Spaces:
Sleeping
Sleeping
mrneuralnet
commited on
Commit
•
eecef1d
1
Parent(s):
4c216d2
Change to gpu inference
Browse files- app.py +2 -2
- extract_video.py +2 -2
- inference.py +2 -2
app.py
CHANGED
@@ -68,10 +68,10 @@ def main():
|
|
68 |
|
69 |
|
70 |
with st.spinner(f'Processing {file_type}...'):
|
71 |
-
processing_stdout = subprocess.run(shlex.split(f"""python extract_video.py --device
|
72 |
st.text(f'1. Processing {file_type} ✅')
|
73 |
with st.spinner(f'Analyzing {file_type}...'):
|
74 |
-
analyze_stdout = subprocess.run(shlex.split(f"""python inference.py --weight weights/model_params_ffpp_c23.pickle --device
|
75 |
st.text(f'2. Analyzing {file_type} ✅')
|
76 |
|
77 |
if len(os.listdir("{}/images/{}".format(base_folder, filename.split(".")[0]))) < 1:
|
|
|
68 |
|
69 |
|
70 |
with st.spinner(f'Processing {file_type}...'):
|
71 |
+
processing_stdout = subprocess.run(shlex.split(f"""python extract_video.py --device cuda --max_frames 50 --bs 2 --frame_interval 60 --confidence_threshold 0.997 --data_path "{filepath}" """), capture_output=True)
|
72 |
st.text(f'1. Processing {file_type} ✅')
|
73 |
with st.spinner(f'Analyzing {file_type}...'):
|
74 |
+
analyze_stdout = subprocess.run(shlex.split(f"""python inference.py --weight weights/model_params_ffpp_c23.pickle --device cuda --image_folder "{base_folder}/images/{filename}" """), capture_output=True)
|
75 |
st.text(f'2. Analyzing {file_type} ✅')
|
76 |
|
77 |
if len(os.listdir("{}/images/{}".format(base_folder, filename.split(".")[0]))) < 1:
|
extract_video.py
CHANGED
@@ -37,7 +37,7 @@ def remove_prefix(state_dict, prefix):
|
|
37 |
return {f(key): value for key, value in state_dict.items()}
|
38 |
|
39 |
|
40 |
-
def load_model(model, pretrained_path, load_to_cpu):
|
41 |
print('Loading pretrained model from {}'.format(pretrained_path))
|
42 |
if load_to_cpu:
|
43 |
pretrained_dict = torch.load(
|
@@ -226,7 +226,7 @@ if __name__ == '__main__':
|
|
226 |
|
227 |
# net and model
|
228 |
net = RetinaFace(cfg=cfg, phase='test')
|
229 |
-
net = load_model(net, pretrained_weights,
|
230 |
net.eval()
|
231 |
print('Finished loading model!')
|
232 |
|
|
|
37 |
return {f(key): value for key, value in state_dict.items()}
|
38 |
|
39 |
|
40 |
+
def load_model(model, pretrained_path, load_to_cpu=False):
|
41 |
print('Loading pretrained model from {}'.format(pretrained_path))
|
42 |
if load_to_cpu:
|
43 |
pretrained_dict = torch.load(
|
|
|
226 |
|
227 |
# net and model
|
228 |
net = RetinaFace(cfg=cfg, phase='test')
|
229 |
+
net = load_model(net, pretrained_weights, load_to_cpu=False)
|
230 |
net.eval()
|
231 |
print('Finished loading model!')
|
232 |
|
inference.py
CHANGED
@@ -120,9 +120,9 @@ def main():
|
|
120 |
if args.weight and args.bin:
|
121 |
raise ValueError("Only one of '--weight' or '--bin' can be set.")
|
122 |
elif args.weight:
|
123 |
-
weights = torch.load(args.weight, map_location=
|
124 |
elif args.bin:
|
125 |
-
weights = torch.load(args.bin, map_location=
|
126 |
else:
|
127 |
raise ValueError("Neither of '--weight' nor '--bin' is set. Please specify either "
|
128 |
"one of these two arguments to load model's weight properly.")
|
|
|
120 |
if args.weight and args.bin:
|
121 |
raise ValueError("Only one of '--weight' or '--bin' can be set.")
|
122 |
elif args.weight:
|
123 |
+
weights = torch.load(args.weight, map_location=device)
|
124 |
elif args.bin:
|
125 |
+
weights = torch.load(args.bin, map_location=device)["model"]
|
126 |
else:
|
127 |
raise ValueError("Neither of '--weight' nor '--bin' is set. Please specify either "
|
128 |
"one of these two arguments to load model's weight properly.")
|