titu1994 / keras-non-local-nets

Keras implementation of Non-local Neural Networks
MIT License
290 stars 100 forks source link

Running Error: ValueError: Tried to convert 'shape' to a tensor and failed. #9

Closed bravotty closed 5 years ago

bravotty commented 5 years ago

When i import the non_local_block in my own keras code, it happens ValueError: Tried to convert 'shape' to a tensor and failed. Error: None values not supported.

Here is my code review: def init_model(): im_n = Input(shape=(None, None, 1)) x = Conv2D(64, 3, activation='relu', padding='same')(im_n) x = **non_local_block**(x) resd = Conv2D(1, 3, padding='same')(x) model = Model(inputs=im_n, outputs=resd) model.compile(optimizer=Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-8), loss='mean_squared_error') return model

Here is the ERROR INFO: Traceback (most recent call last): File "/Users/code/train.py", line 49, in <module> model = init_model() File "/Users/code/train.py", line 35, in init_model x = non_local_block(x) File "/Users/code/non_local.py", line 136, in non_local_block y = Reshape((dim1, dim2, intermediate_dim))(y) File "/Users/anaconda3/envs/tf-keras/lib/python3.6/site-packages/keras/engine/base_layer.py", line 457, in __call__ output = self.call(inputs, **kwargs) File "/Users/anaconda3/envs/tf-keras/lib/python3.6/site-packages/keras/layers/core.py", line 401, in call return K.reshape(inputs, (K.shape(inputs)[0],) + self.target_shape) File "/Users/anaconda3/envs/tf-keras/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 1969, in reshape return tf.reshape(x, shape) File "/Users/anaconda3/envs/tf-keras/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py", line 6482, in reshape "Reshape", tensor=tensor, shape=shape, name=name) File "/Users/anaconda3/envs/tf-keras/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 528, in _apply_op_helper (input_name, err)) ValueError: Tried to convert 'shape' to a tensor and failed. Error: None values not supported.

Thx!!!