Skip to content

Commit 1918be5

Browse files
moving to test data from OSF and setting weights_only=False
1 parent 97ea2aa commit 1918be5

File tree

4 files changed

+14
-34
lines changed

4 files changed

+14
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ For any issues or questions about Facemap, please [open an issue](https://github
105105
The models will be downloaded automatically from our website when you first run Facemap for processing keypoints. If download of pretrained models fails, please try the following:
106106
107107
- to resolve certificate error try: ```pip install –upgrade certifi```, or
108-
- download the pretrained model files: [model state](https://www.facemappy.org/models/facemap_model_state.pt) and [model parameters](https://www.facemappy.org/models/facemap_model_params.pth) and place them in the `models` subfolder of the hidden `facemap` folder located in home directory. Path to the hidden folder is: `C:\Users\your_username\.facemap\models` on Windows and `/home/your_username/.facemap/models` on Linux and Mac.
108+
- download the pretrained model files: [model_params](https://osf.io/download/67f00beaba4331d9888b7f36/), [model_state](https://osf.io/download/67f00be8959068ade6cf70f1/) and place them in the `models` subfolder of the hidden `facemap` folder located in home directory. Path to the hidden folder is: `C:\Users\your_username\.facemap\models` on Windows and `/home/your_username/.facemap/models` on Linux and Mac.
109109
110110
# Running Facemap
111111

facemap/pose/model_loader.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
from pathlib import Path
1212
from urllib.request import urlretrieve
1313

14-
MODEL_PARAMS_URL = "https://www.facemappy.org/models/facemap_model_params.pth"
15-
MODEL_STATE_URL = "https://www.facemappy.org/models/facemap_model_state.pt"
14+
MODEL_PARAMS_URL = "https://osf.io/download/67f00beaba4331d9888b7f36/"
15+
MODEL_STATE_URL = "https://osf.io/download/67f00be8959068ade6cf70f1/"
1616

1717

1818
def get_data_dir():
@@ -158,3 +158,6 @@ def get_model_files():
158158
# Read the file
159159
filenames = file_readobject.read().splitlines()
160160
return filenames
161+
162+
get_model_params_path()
163+
get_basemodel_state_path()

facemap/pose/pose.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def set_model(self, model_selected=None):
153153
self.model_name = model_paths[model_names.index(model)]
154154
break
155155
print("Loading model state from:", self.model_name)
156-
self.net.load_state_dict(torch.load(self.model_name, map_location=self.device))
156+
self.net.load_state_dict(torch.load(self.model_name, map_location=self.device, weights_only=False))
157157
self.net.to(self.device)
158158

159159
def load_model(self):
@@ -168,7 +168,7 @@ def load_model(self):
168168
GUIobject=self.GUIobject,
169169
prompt="Loading model... {}".format(model_params_file),
170170
)
171-
model_params = torch.load(model_params_file, map_location=self.device)
171+
model_params = torch.load(model_params_file, map_location=self.device, weights_only=False)
172172
# self.bodyparts = model_params["params"]["bodyparts"]
173173
channels = model_params["params"]["channels"]
174174
kernel_size = 3

tests/conftest.py

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from glob import glob
99
from pathlib import Path
1010
from urllib.request import urlopen
11+
import zipfile
1112

1213
import pytest
1314
from tqdm import tqdm
@@ -41,47 +42,23 @@ def bodyparts():
4142
]
4243
return BODYPARTS
4344

45+
def extract_zip(cached_file, url, data_path):
46+
download_url_to_file(url, cached_file)
47+
with zipfile.ZipFile(cached_file,"r") as zip_ref:
48+
zip_ref.extractall(data_path)
4449

4550
@pytest.fixture(scope="session")
4651
def data_dir(video_names):
4752
fm_dir = Path.home().joinpath(".facemap")
4853
fm_dir.mkdir(exist_ok=True)
54+
extract_zip(fm_dir.joinpath("data.zip"), "https://osf.io/download/67f025b541d31bf67eb256dd/", fm_dir)
4955
data_dir = fm_dir.joinpath("data")
50-
data_dir.mkdir(exist_ok=True)
51-
data_dir_cam1 = data_dir.joinpath("cam1")
52-
data_dir_cam1.mkdir(exist_ok=True)
53-
data_dir_cam2 = data_dir.joinpath("cam2")
54-
data_dir_cam2.mkdir(exist_ok=True)
55-
56-
for i, video_name in enumerate(video_names):
57-
url = "https://www.facemappy.org/test_data/" + video_name
58-
if "1" in video_name:
59-
cached_file = str(data_dir_cam1.joinpath(video_name))
60-
else:
61-
cached_file = str(data_dir_cam2.joinpath(video_name))
62-
if not os.path.exists(cached_file):
63-
download_url_to_file(url, cached_file)
64-
6556
return data_dir
6657

6758

6859
@pytest.fixture(scope="session")
6960
def expected_output_dir(data_dir):
7061
expected_output_dir = data_dir.joinpath("expected_output")
71-
expected_output_dir.mkdir(exist_ok=True)
72-
# Download expected output files
73-
download_url_to_file(
74-
"https://www.facemappy.org/test_data/single_video_proc.npy",
75-
expected_output_dir.joinpath("single_video_proc.npy"),
76-
)
77-
download_url_to_file(
78-
"https://www.facemappy.org/test_data/multi_video_proc.npy",
79-
expected_output_dir.joinpath("multi_video_proc.npy"),
80-
)
81-
download_url_to_file(
82-
"https://www.facemappy.org/test_data/cam1_test_FacemapPose.h5",
83-
expected_output_dir.joinpath("cam1_test_FacemapPose.h5"),
84-
)
8562
return expected_output_dir
8663

8764

0 commit comments

Comments
 (0)