Skip to content

Commit 994199e

Browse files
committed
Test running MTCNN with different data types.
The fp16 portion only runs on GPUs, as is it not supported on CPUs. Also test with the pre-release automatic multi-precision package. This portion of the test only runs on pre-release (1.6+) versions of torch.
1 parent c304896 commit 994199e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/travis_test.py

+40
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,46 @@ def get_image(path, trans):
146146
mtcnn(img, save_path='data/tmp.png')
147147

148148

149+
#### MTCNN TYPES TEST ####
150+
151+
img = Image.open('data/multiface.jpg')
152+
153+
mtcnn = MTCNN(keep_all=True)
154+
boxes_ref, _ = mtcnn.detect(img)
155+
_ = mtcnn(img)
156+
157+
mtcnn = MTCNN(keep_all=True).double()
158+
boxes_test, _ = mtcnn.detect(img)
159+
_ = mtcnn(img)
160+
161+
box_diff = boxes_ref[np.argsort(boxes_ref[:,1])] - boxes_test[np.argsort(boxes_test[:,1])]
162+
total_error = np.sum(np.abs(box_diff))
163+
print('\nfp64 Total box error: {}'.format(total_error))
164+
165+
assert total_error < 1e-2
166+
167+
168+
# half is not supported on CPUs, only GPUs
169+
if torch.cuda.is_available():
170+
171+
mtcnn = MTCNN(keep_all=True, device='cuda').half()
172+
boxes_test, _ = mtcnn.detect(img)
173+
_ = mtcnn(img)
174+
175+
box_diff = boxes_ref[np.argsort(boxes_ref[:,1])] - boxes_test[np.argsort(boxes_test[:,1])]
176+
print('fp16 Total box error: {}'.format(np.sum(np.abs(box_diff))))
177+
178+
# test new automatic multi precision to compare
179+
if hasattr(torch.cuda, 'amp'):
180+
with torch.cuda.amp.autocast():
181+
mtcnn = MTCNN(keep_all=True, device='cuda')
182+
boxes_test, _ = mtcnn.detect(img)
183+
_ = mtcnn(img)
184+
185+
box_diff = boxes_ref[np.argsort(boxes_ref[:,1])] - boxes_test[np.argsort(boxes_test[:,1])]
186+
print('AMP total box error: {}'.format(np.sum(np.abs(box_diff))))
187+
188+
149189
#### MULTI-IMAGE TEST ####
150190

151191
mtcnn = MTCNN(keep_all=True)

0 commit comments

Comments
 (0)