def test_caffe_import(self):
# Test 1
data, label = L.ImageData(source='/dummy/source/', batch_size=32, ntop=2, rand_skip=0,
shuffle=False, new_height=256, new_width=256, is_color=False,
root_folder='/dummy/folder/',
transform_param=dict(crop_size=227, mean_value=[104, 117, 123],
mirror=True, force_color=False,
force_gray=False))
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(data, label)))
sample_file = open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'r')
response = self.client.post(reverse('caffe-import'), {'file': sample_file})
response = json.loads(response.content)
os.remove(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'))
self.assertGreaterEqual(len(response['net']['l0']['params']), 13)
self.assertEqual(response['result'], 'success')
# Test 2
data, label = L.ImageData(source='/dummy/source/', batch_size=32, ntop=2, rand_skip=0,
shuffle=False, new_height=256, new_width=256, is_color=False,
root_folder='/dummy/folder/', include=dict(phase=caffe.TRAIN),
transform_param=dict(crop_size=227, mean_file='/path/to/file',
mirror=True, force_color=False,
force_gray=False))
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(data, label)))
sample_file = open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'r')
response = self.client.post(reverse('caffe-import'), {'file': sample_file})
response = json.loads(response.content)
os.remove(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'))
self.assertGreaterEqual(len(response['net']['l0']['params']), 13)
self.assertEqual(response['result'], 'success')
评论列表
文章目录