我似乎对更新的keras版本有问题。这种神经网络结构导致了这个错误:
print "Data-train-in: " + str(data_train_input[0].shape)
print "Data-train-out: " + str(data_train_output[0].shape)
print "Data-test-in: " + str(data_test_input[0].shape)
#sys.exit()
model.add(Conv2D(filters = 32, kernel_size = (3,3) , padding = "same" , activation = "LeakyRelu" , input_shape = (3,6,3)))
model.add(Conv2D(filters = 64, kernel_size = (3,3) , padding = "same" , activation = "LeakyRelu", ))
model.add(Conv2D(filters = 64, kernel_size = (3,3) , padding = "same" , activation = "LeakyRelu", ))
model.add(Conv2D(filters = 32, kernel_size = (1,1) , padding = "same" , activation = "LeakyRelu", ))
print model.output_shape
# model.add(MaxPooling2D(pool_size=(3,1)))
print model.output_shape
model.add(Flatten())
print model.output_shape
# model.add(Dense(output_dim=300, input_dim=200, init="normal",activation='tanh'))
# model.add(Dense(output_dim=32, input_dim=200, init="normal",activation='relu'))
# model.add(Dense(output_dim=1, input_dim=32, init="normal",activation='tanh'))
model.add(Dense(output_dim=13, input_dim=32, init="normal",activation='LeakyReLU'))
model.add(Dense(output_dim=1, init="normal", activation='linear'))
print model.summary()
model.compile(loss='mean_squared_error', optimizer="adam")
给出这个输出:
Data-train-in: (3, 6, 3)
Data-train-out: (1,)
Data-test-in: (3, 6, 3)
Traceback (most recent call last):
File "keras_convolutional_feature_extraction.py", line 602, in <module>
model(i,train_input_data_interweawed_normalized,output_data_train,test_input_data_interweawed_normalized,output_data_test)
File "keras_convolutional_feature_extraction.py", line 535, in model
model.add(Conv2D(filters = 32, kernel_size = (3,3) , padding = "same" , activation = "LeakyRelu" , input_shape = (3,6,3)))
File "/usr/local/lib/python2.7/dist-packages/keras/legacy/interfaces.py", line 87, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/keras/layers/convolutional.py", line 455, in __init__
**kwargs)
File "/usr/local/lib/python2.7/dist-packages/keras/layers/convolutional.py", line 108, in __init__
self.activation = activations.get(activation)
File "/usr/local/lib/python2.7/dist-packages/keras/activations.py", line 69, in get
return deserialize(identifier)
File "/usr/local/lib/python2.7/dist-packages/keras/activations.py", line 61, in deserialize
printable_module_name='activation function')
File "/usr/local/lib/python2.7/dist-packages/keras/utils/generic_utils.py", line 157, in deserialize_keras_object
':' + class_name)
UnboundLocalError: local variable 'class_name' referenced before assignment
我读了一些关于这个问题的其他帖子,但这似乎与其他帖子类似。
答案 0 :(得分:0)
必须以可分离的方式添加高级图层,而不是在定义卷积图层的同一行中。