def test_caffe_export(self):
data = L.Input(shape={'dim': [10, 3, 16, 224, 224]})
top = L.Convolution(data, kernel_size=3, pad=1, stride=1, num_output=128, dilation=1,
weight_filler={'type': 'xavier'}, bias_filler={'type': 'constant'})
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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)
response['net']['l0']['params']['caffe'] = True
response['net']['l1']['params']['layer_type'] = '3D'
response['net']['l1']['params']['caffe'] = False
response = self.client.post(reverse('caffe-export'), {'net': json.dumps(response['net']),
'net_name': ''})
response = json.loads(response.content)
self.assertEqual(response['result'], 'error')
# ********** Data Layers Test **********
python类to_proto()的实例源码
def test_caffe_import(self):
data, label = L.WindowData(source='/dummy/source/', batch_size=32, ntop=2,
fg_threshold=0.5, bg_threshold=0.5, fg_fraction=0.25,
context_pad=0, crop_mode='warp', cache_images=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']), 14)
self.assertEqual(response['result'], 'success')
def test_caffe_import(self):
# Test 1
top = L.Pooling(kernel_size=2, pad=0, stride=2, pool=1)
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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']), 4)
self.assertEqual(response['result'], 'success')
# Test 2
top = L.Pooling(kernel_size=2, pad=0, stride=2, pool=2)
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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']), 4)
self.assertEqual(response['result'], 'success')
def test_caffe_import(self):
# Test 1
data = L.Input(shape={'dim': [10, 3, 224, 224]})
top = L.Python(data, module='pyloss', layer='EuclideanLossLayer', loss_weight=1, name='eucLoss')
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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']['l1']['params']), 4)
self.assertEqual(response['result'], 'success')
# Test 2
top = L.Python(module='pascal_multilabel_datalayers', layer='PascalMultilabelDataLayerSync',
param_str="{\'pascal_root\': \'../data/pascal/VOC2007\', \'im_shape\': [227, 227], \
\'split\': \'train\', \'batch_size\': 128}")
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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']), 6)
self.assertEqual(response['result'], 'success')
def densenet(data_file, mode='train', batch_size=64, depth=40, first_output=16, growth_rate=12, dropout=0.2):
data, label = L.Data(source=data_file, backend=P.Data.LMDB, batch_size=batch_size, ntop=2,
transform_param=dict(mean_file="/home/zl499/caffe/examples/cifar10/mean.binaryproto"))
nchannels = first_output
model = L.Convolution(data, kernel_size=3, stride=1, num_output=nchannels,
pad=1, bias_term=False, weight_filler=dict(type='msra'), bias_filler=dict(type='constant'))
N = (depth-4)/3
for i in range(N):
model = add_layer(model, growth_rate, dropout)
nchannels += growth_rate
model = transition(model, nchannels, dropout)
for i in range(N):
model = add_layer(model, growth_rate, dropout)
nchannels += growth_rate
model = transition(model, nchannels, dropout)
for i in range(N):
model = add_layer(model, growth_rate, dropout)
nchannels += growth_rate
model = L.BatchNorm(model, in_place=False, param=[dict(lr_mult=0, decay_mult=0), dict(lr_mult=0, decay_mult=0), dict(lr_mult=0, decay_mult=0)])
model = L.Scale(model, bias_term=True, in_place=True, filler=dict(value=1), bias_filler=dict(value=0))
model = L.ReLU(model, in_place=True)
model = L.Pooling(model, pool=P.Pooling.AVE, global_pooling=True)
model = L.InnerProduct(model, num_output=10, bias_term=True, weight_filler=dict(type='xavier'), bias_filler=dict(type='constant'))
loss = L.SoftmaxWithLoss(model, label)
accuracy = L.Accuracy(model, label)
return to_proto(loss, accuracy)
def caffenet(lmdb, batch_size=256, include_acc=False):
data, label = L.Data(source=lmdb, backend=P.Data.LMDB,
batch_size=batch_size, ntop=2)
# the net itself
conv1, relu1 = conv_relu(data, 11, 96, stride=4)
pool1 = max_pool(relu1, 3, stride=2)
norm1 = L.LRN(pool1, local_size=5, alpha=1e-4, beta=0.75)
conv2, relu2 = conv_relu(norm1, 5, 256, pad=2, group=2)
pool2 = max_pool(relu2, 3, stride=2)
norm2 = L.LRN(pool2, local_size=5, alpha=1e-4, beta=0.75)
conv3, relu3 = conv_relu(norm2, 3, 384, pad=1)
conv4, relu4 = conv_relu(relu3, 3, 384, pad=1, group=2)
conv5, relu5 = conv_relu(relu4, 3, 256, pad=1, group=2)
pool5 = max_pool(relu5, 3, stride=2)
fc6, relu6 = fc_relu(pool5, 4096)
drop6 = L.Dropout(relu6, in_place=True)
fc7, relu7 = fc_relu(drop6, 4096)
drop7 = L.Dropout(relu7, in_place=True)
fc8 = L.InnerProduct(drop7, num_output=1000)
loss = L.SoftmaxWithLoss(fc8, label)
if include_acc:
acc = L.Accuracy(fc8, label)
return to_proto(loss, acc)
else:
return to_proto(loss)
def convert(self, net_string):
net_list = cnn.parse('net', net_string)
net_list = StateStringUtils(self.ssp).convert_model_string_to_states(net_list)[1:]
data, label = self.create_top_layer(caffe.TRAIN, self.hp.TRAIN_FILE, train=True)
data1, label1 = self.create_top_layer(caffe.TEST, self.hp.VAL_FILE, train=False)
loss, acc = self.unpack_list(net_list, data, label)
lls = [data, data1, acc, loss]
cc = to_proto(*lls)
cc = self.replace_top_names(cc)
return cc
# Iterate over token list from parser.
def test_caffe_export(self):
data = L.Input(shape={'dim': [10, 3, 224, 224]})
top = L.Convolution(data, kernel_size=3, pad=1, stride=1, num_output=128, dilation=1,
weight_filler={'type': 'xavier'}, bias_filler={'type': 'constant'})
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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)
response['net']['l0']['params']['caffe'] = True
response['net']['l1']['params']['caffe'] = True
response = self.client.post(reverse('caffe-export'), {'net': json.dumps(response['net']),
'net_name': ''})
response = json.loads(response.content)
self.assertEqual(response['result'], 'success')
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')
def test_caffe_import(self):
# Test 1
data, label = L.Data(source='/dummy/source/', backend=P.Data.LMDB, batch_size=32, ntop=2,
rand_skip=0, prefetch=10,
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']), 10)
self.assertEqual(response['result'], 'success')
# Test 2
data, label = L.Data(source='/dummy/source/', backend=P.Data.LEVELDB, batch_size=32, ntop=2,
rand_skip=0, prefetch=10,
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']), 10)
self.assertEqual(response['result'], 'success')
def test_caffe_import(self):
top = L.HDF5Output(file_name='/dummy/filename')
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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']), 1)
self.assertEqual(response['result'], 'success')
def test_caffe_import(self):
data = L.Input(shape={'dim': [10, 3, 224, 224]})
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(data)))
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']), 1)
self.assertEqual(response['result'], 'success')
def test_caffe_import(self):
data, label = L.MemoryData(batch_size=32, ntop=2, channels=3, height=224, width=224)
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']), 4)
self.assertEqual(response['result'], 'success')
def test_caffe_import(self):
data = L.DummyData(shape={'dim': [10, 3, 224, 224]},
data_filler={'type': 'constant'})
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(data)))
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']), 1)
self.assertEqual(response['result'], 'success')
# ********** Vision Layers Test **********
def test_caffe_import(self):
top = L.SPP(pyramid_height=2, pool=1)
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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']), 2)
self.assertEqual(response['result'], 'success')
def test_caffe_import(self):
top = L.Crop(axis=2, offset=2)
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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']), 2)
self.assertEqual(response['result'], 'success')
def test_caffe_import(self):
# Test 1
top = L.Deconvolution(convolution_param=dict(kernel_size=3, pad=1, stride=1, num_output=128,
weight_filler={'type': 'xavier'}, bias_filler={'type': 'constant'}))
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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']), 6)
self.assertEqual(response['result'], 'success')
# Test 2
top = L.Deconvolution(convolution_param=dict(kernel_w=3, kernel_h=3, pad_w=1, pad_h=1, stride=1,
num_output=128, dilation=1, weight_filler={'type': 'xavier'},
bias_filler={'type': 'constant'}))
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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']), 6)
self.assertEqual(response['result'], 'success')
# ********** Recurrent Layers Test **********
def test_caffe_import(self):
top = L.Recurrent(recurrent_param=dict(num_output=128, debug_info=False,
expose_hidden=False, weight_filler={'type': 'xavier'},
bias_filler={'type': 'constant'}))
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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']), 5)
self.assertEqual(response['result'], 'success')
def test_caffe_import(self):
top = L.LSTM(recurrent_param=dict(num_output=128, debug_info=False,
expose_hidden=False, weight_filler={'type': 'xavier'},
bias_filler={'type': 'constant'}))
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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']), 5)
self.assertEqual(response['result'], 'success')
# ********** Common Layers Test **********
def test_caffe_import(self):
top = L.InnerProduct(num_output=128, weight_filler={'type': 'xavier'},
bias_filler={'type': 'constant'})
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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']), 3)
self.assertEqual(response['result'], 'success')
def test_caffe_import(self):
top = L.Dropout()
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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.assertEqual(response['result'], 'success')
def test_caffe_import(self):
top = L.Embed(num_output=128, input_dim=2, bias_term=False,
weight_filler={'type': 'xavier'})
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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']), 4)
self.assertEqual(response['result'], 'success')
# ********** Normalisation Layers Test **********
def test_caffe_import(self):
top = L.LRN(local_size=5, alpha=1, beta=0.75, k=1, norm_region=1, in_place=True)
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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']), 5)
self.assertEqual(response['result'], 'success')
def test_caffe_import(self):
top = L.BatchNorm(use_global_stats=True, moving_average_fraction=0.999, eps=1e-5, in_place=True)
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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']), 3)
self.assertEqual(response['result'], 'success')
# ********** Activation / Neuron Layers Test **********
def test_caffe_import(self):
top = L.ReLU(negative_slope=0, in_place=True)
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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']), 1)
self.assertEqual(response['result'], 'success')
def test_caffe_import(self):
top = L.PReLU(channel_shared=False, in_place=True)
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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']), 1)
self.assertEqual(response['result'], 'success')
def test_caffe_import(self):
top = L.ELU(alpha=1, in_place=True)
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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']), 1)
self.assertEqual(response['result'], 'success')
def test_caffe_import(self):
top = L.Sigmoid(in_place=True)
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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.assertEqual(response['result'], 'success')
def test_caffe_import(self):
top = L.AbsVal(in_place=True)
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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.assertEqual(response['result'], 'success')
def test_caffe_import(self):
top = L.Power(power=1.0, scale=1.0, shift=0.0, in_place=True)
with open(os.path.join(settings.BASE_DIR, 'media', 'test.prototxt'), 'w') as f:
f.write(str(to_proto(top)))
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']), 3)
self.assertEqual(response['result'], 'success')