Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support new version numpy #163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1.support new version numpy
AbelDengGang committed Dec 4, 2020
commit 8d5fe1f7f4b2b97d6f4ded2b287461a52b1e8d99
Empty file added data/facebank/.gitignore
Empty file.
41 changes: 41 additions & 0 deletions mtcnn_pytorch/src/get_nets.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,11 @@
from collections import OrderedDict
import numpy as np

def get_np_version_number():
ver_str = np.__version__
ver_list = ver_str.split('.')
ver_num = int(ver_list[0]) * 10000 + int(ver_list[1])*100 + int(ver_list[2])
return ver_num

class Flatten(nn.Module):

@@ -51,8 +56,19 @@ def __init__(self):

self.conv4_1 = nn.Conv2d(32, 2, 1, 1)
self.conv4_2 = nn.Conv2d(32, 4, 1, 1)
np_ver = get_np_version_number()
if np_ver >= 11602: # from np 1.16.2, allow_pickle default set to False
# save np.load
np_load_old = np.load
# modify the default parameters of np.load
np.load = lambda *a,**k: np_load_old(*a, allow_pickle=True, **k)

weights = np.load('mtcnn_pytorch/src/weights/pnet.npy')[()]

if np_ver >= 11602: # from np 1.16.2, allow_pickle default set to False
# restore np.load for future normal usage
np.load = np_load_old

for n, p in self.named_parameters():
p.data = torch.FloatTensor(weights[n])

@@ -96,8 +112,19 @@ def __init__(self):

self.conv5_1 = nn.Linear(128, 2)
self.conv5_2 = nn.Linear(128, 4)
np_ver = get_np_version_number()
if np_ver >= 11602: # from np 1.16.2, allow_pickle default set to False
# save np.load
np_load_old = np.load
# modify the default parameters of np.load
np.load = lambda *a,**k: np_load_old(*a, allow_pickle=True, **k)

weights = np.load('mtcnn_pytorch/src/weights/rnet.npy')[()]

if np_ver >= 11602: # from np 1.16.2, allow_pickle default set to False
# restore np.load for future normal usage
np.load = np_load_old

for n, p in self.named_parameters():
p.data = torch.FloatTensor(weights[n])

@@ -148,7 +175,21 @@ def __init__(self):
self.conv6_2 = nn.Linear(256, 4)
self.conv6_3 = nn.Linear(256, 10)

np_ver = get_np_version_number()
if np_ver >= 11602: # from np 1.16.2, allow_pickle default set to False
# save np.load
np_load_old = np.load
# modify the default parameters of np.load
np.load = lambda *a,**k: np_load_old(*a, allow_pickle=True, **k)

weights = np.load('mtcnn_pytorch/src/weights/onet.npy')[()]


if np_ver >= 11602: # from np 1.16.2, allow_pickle default set to False
# restore np.load for future normal usage
np.load = np_load_old


for n, p in self.named_parameters():
p.data = torch.FloatTensor(weights[n])