Spaces:
Runtime error
Runtime error
Commit ·
2fe3d36
1
Parent(s): 9f1ce44
new model
Browse files
app.py
CHANGED
|
@@ -23,17 +23,31 @@ import torchvision.transforms.functional as F
|
|
| 23 |
from huggingface_hub import hf_hub_download
|
| 24 |
from huggingface_hub import HfApi
|
| 25 |
|
|
|
|
|
|
|
| 26 |
plt.style.use('dark_background')
|
| 27 |
|
| 28 |
-
hf_hub_download(repo_id="dylanplummer/ropenet", filename="
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
| 31 |
#model_xml = "model_ir/model.xml"
|
| 32 |
|
| 33 |
-
ie = Core()
|
| 34 |
-
model_ir = ie.read_model(model=model_xml)
|
| 35 |
-
config = {"PERFORMANCE_HINT": "LATENCY"}
|
| 36 |
-
compiled_model_ir = ie.compile_model(model=model_ir, device_name="CPU", config=config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
|
| 39 |
class SquarePad:
|
|
@@ -80,11 +94,6 @@ def inference(x, count_only_api, api_key, img_size=192, seq_len=64, stride_lengt
|
|
| 80 |
frame_i += 1
|
| 81 |
cap.release()
|
| 82 |
|
| 83 |
-
# Get output layer
|
| 84 |
-
output_layer_period_length = compiled_model_ir.output(0)
|
| 85 |
-
output_layer_periodicity = compiled_model_ir.output(1)
|
| 86 |
-
output_layer_marks = compiled_model_ir.output(2)
|
| 87 |
-
output_layer_event_type = compiled_model_ir.output(3)
|
| 88 |
length = len(all_frames)
|
| 89 |
period_lengths = np.zeros(len(all_frames) + seq_len + stride_length)
|
| 90 |
periodicities = np.zeros(len(all_frames) + seq_len + stride_length)
|
|
@@ -129,11 +138,11 @@ def inference(x, count_only_api, api_key, img_size=192, seq_len=64, stride_lengt
|
|
| 129 |
idx_list.append(i)
|
| 130 |
if len(batch_list) == batch_size:
|
| 131 |
batch_X = torch.cat(batch_list)
|
| 132 |
-
result =
|
| 133 |
-
y1pred = result[
|
| 134 |
-
y2pred = result[
|
| 135 |
-
y3pred = result[
|
| 136 |
-
y4pred = result[
|
| 137 |
for y1, y2, y3, y4, idx in zip(y1pred, y2pred, y3pred, y4pred, idx_list):
|
| 138 |
periodLength = y1.squeeze()
|
| 139 |
periodicity = y2.squeeze()
|
|
@@ -152,11 +161,11 @@ def inference(x, count_only_api, api_key, img_size=192, seq_len=64, stride_lengt
|
|
| 152 |
batch_list.append(batch_list[-1])
|
| 153 |
idx_list.append(idx_list[-1])
|
| 154 |
batch_X = torch.cat(batch_list)
|
| 155 |
-
result =
|
| 156 |
-
y1pred = result[
|
| 157 |
-
y2pred = result[
|
| 158 |
-
y3pred = result[
|
| 159 |
-
y4pred = result[
|
| 160 |
for y1, y2, y3, y4, idx in zip(y1pred, y2pred, y3pred, y4pred, idx_list):
|
| 161 |
periodLength = y1.squeeze()
|
| 162 |
periodicity = y2.squeeze()
|
|
@@ -310,10 +319,7 @@ DESCRIPTION += '\nDemo created by [Dylan Plummer](https://dylan-plummer.github.i
|
|
| 310 |
|
| 311 |
with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
|
| 312 |
gr.Markdown(DESCRIPTION)
|
| 313 |
-
|
| 314 |
-
#with gr.Row():
|
| 315 |
-
in_video = gr.PlayableVideo(label="Input Video", elem_id='input-video', format='mp4', width='50%', min_width=400, interactive=True, container=True)
|
| 316 |
-
placeholder = gr.Markdown(label="", elem_id='placeholder-text')
|
| 317 |
|
| 318 |
with gr.Row():
|
| 319 |
run_button = gr.Button(value="Run", elem_id='run-button', scale=1)
|
|
|
|
| 23 |
from huggingface_hub import hf_hub_download
|
| 24 |
from huggingface_hub import HfApi
|
| 25 |
|
| 26 |
+
|
| 27 |
+
|
| 28 |
plt.style.use('dark_background')
|
| 29 |
|
| 30 |
+
checkpoint = hf_hub_download(repo_id="dylanplummer/ropenet", filename="ropenet_keypoint_0.pt", repo_type="model", token=os.environ['DATASET_SECRET'])
|
| 31 |
+
model_file = checkpoint = hf_hub_download(repo_id="dylanplummer/ropenet", filename="model.py", repo_type="model", token=os.environ['DATASET_SECRET'])
|
| 32 |
+
os.move(model_file, "model.py")
|
| 33 |
+
from model import RepNet
|
| 34 |
+
# model_xml = hf_hub_download(repo_id="dylanplummer/ropenet", filename="model.xml", repo_type="model", token=os.environ['DATASET_SECRET'])
|
| 35 |
+
# hf_hub_download(repo_id="dylanplummer/ropenet", filename="model.mapping", repo_type="model", token=os.environ['DATASET_SECRET'])
|
| 36 |
#model_xml = "model_ir/model.xml"
|
| 37 |
|
| 38 |
+
# ie = Core()
|
| 39 |
+
# model_ir = ie.read_model(model=model_xml)
|
| 40 |
+
# config = {"PERFORMANCE_HINT": "LATENCY"}
|
| 41 |
+
# compiled_model_ir = ie.compile_model(model=model_ir, device_name="CPU", config=config)
|
| 42 |
+
|
| 43 |
+
img_size = 224
|
| 44 |
+
backbone = 'mobilenetv3'
|
| 45 |
+
embedding_size = 196
|
| 46 |
+
n_layers_lstm = 1
|
| 47 |
+
separate_rope = False
|
| 48 |
+
save_realtime = False
|
| 49 |
+
model = RepNet(64, backbone=backbone, backbone_scale='0', trainable_backbone=False, distill_frame_model=save_realtime, img_size=img_size, embedding_size=embedding_size, separate_rope=separate_rope)
|
| 50 |
+
|
| 51 |
|
| 52 |
|
| 53 |
class SquarePad:
|
|
|
|
| 94 |
frame_i += 1
|
| 95 |
cap.release()
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
length = len(all_frames)
|
| 98 |
period_lengths = np.zeros(len(all_frames) + seq_len + stride_length)
|
| 99 |
periodicities = np.zeros(len(all_frames) + seq_len + stride_length)
|
|
|
|
| 138 |
idx_list.append(i)
|
| 139 |
if len(batch_list) == batch_size:
|
| 140 |
batch_X = torch.cat(batch_list)
|
| 141 |
+
result = model(batch_X)
|
| 142 |
+
y1pred = result[0]
|
| 143 |
+
y2pred = result[1]
|
| 144 |
+
y3pred = result[2]
|
| 145 |
+
y4pred = result[3]
|
| 146 |
for y1, y2, y3, y4, idx in zip(y1pred, y2pred, y3pred, y4pred, idx_list):
|
| 147 |
periodLength = y1.squeeze()
|
| 148 |
periodicity = y2.squeeze()
|
|
|
|
| 161 |
batch_list.append(batch_list[-1])
|
| 162 |
idx_list.append(idx_list[-1])
|
| 163 |
batch_X = torch.cat(batch_list)
|
| 164 |
+
result = model(batch_X)
|
| 165 |
+
y1pred = result[0]
|
| 166 |
+
y2pred = result[1]
|
| 167 |
+
y3pred = result[2]
|
| 168 |
+
y4pred = result[3]
|
| 169 |
for y1, y2, y3, y4, idx in zip(y1pred, y2pred, y3pred, y4pred, idx_list):
|
| 170 |
periodLength = y1.squeeze()
|
| 171 |
periodicity = y2.squeeze()
|
|
|
|
| 319 |
|
| 320 |
with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
|
| 321 |
gr.Markdown(DESCRIPTION)
|
| 322 |
+
in_video = gr.PlayableVideo(label="Input Video", elem_id='input-video', format='mp4', width=400, height=400, interactive=True, container=True)
|
|
|
|
|
|
|
|
|
|
| 323 |
|
| 324 |
with gr.Row():
|
| 325 |
run_button = gr.Button(value="Run", elem_id='run-button', scale=1)
|