1
我似乎有更新的keras版本的問題。這個神經網絡結構導致此錯誤:與keras 2.0的UnboundLocalError
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
我閱讀了有關這個問題的一些其他職位,但這個似乎沒有類似於其他的。