def test_keras_export(self):
tests = open(os.path.join(settings.BASE_DIR, 'tests', 'unit', 'keras_app',
'keras_export_test.json'), 'r')
response = json.load(tests)
tests.close()
net = yaml.safe_load(json.dumps(response['net']))
net = {'l0': net['Input'], 'l1': net['Input2'], 'l2': net['Input4'], 'l3': net['Convolution']}
# Conv 1D
net['l1']['connection']['output'].append('l3')
net['l3']['connection']['input'] = ['l1']
net['l3']['params']['layer_type'] = '1D'
net['l3']['shape']['input'] = net['l1']['shape']['output']
net['l3']['shape']['output'] = [128, 12]
inp = data(net['l1'], '', 'l1')['l1']
temp = convolution(net['l3'], [inp], 'l3')
model = Model(inp, temp['l3'])
self.assertEqual(model.layers[2].__class__.__name__, 'Conv1D')
# Conv 2D
net['l0']['connection']['output'].append('l0')
net['l3']['connection']['input'] = ['l0']
net['l3']['params']['layer_type'] = '2D'
net['l3']['shape']['input'] = net['l0']['shape']['output']
net['l3']['shape']['output'] = [128, 226, 226]
inp = data(net['l0'], '', 'l0')['l0']
temp = convolution(net['l3'], [inp], 'l3')
model = Model(inp, temp['l3'])
self.assertEqual(model.layers[2].__class__.__name__, 'Conv2D')
# Conv 3D
net['l2']['connection']['output'].append('l3')
net['l3']['connection']['input'] = ['l2']
net['l3']['params']['layer_type'] = '3D'
net['l3']['shape']['input'] = net['l2']['shape']['output']
net['l3']['shape']['output'] = [128, 226, 226, 18]
inp = data(net['l2'], '', 'l2')['l2']
temp = convolution(net['l3'], [inp], 'l3')
model = Model(inp, temp['l3'])
self.assertEqual(model.layers[2].__class__.__name__, 'Conv3D')
评论列表
文章目录