Image-Super-Resolution icon indicating copy to clipboard operation
Image-Super-Resolution copied to clipboard

Error due to layer incompatibility, reshaping the data.

Open paulprasanth536 opened this issue 3 years ago • 0 comments

The given below is the error I've got.

Epoch 1/25 WARNING:tensorflow:Model was constructed with shape (None, 18729, 2, 1) for input KerasTensor(type_spec=TensorSpec(shape=(None, 18729, 2, 1), dtype=tf.float32, name='conv2d_16_input'), name='conv2d_16_input', description="created by layer 'conv2d_16_input'"), but it was called on an input with incompatible shape (None, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1).

ValueError Traceback (most recent call last) in () 5 from keras.utils import to_categorical 6 ----> 7 history=model.fit(X_train_scaled,Y_train_scaled,epochs=25,validation_data=(X_train_scaled,Y_train_scaled)) 8 #history=model.fit(X_train_scaled,Y_train_scaled,batch_size=32,epochs=100,verbose=2,validation_split=0.8) 9 print(model.summary())

9 frames /usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py in wrapper(*args, **kwargs) 975 except Exception as e: # pylint:disable=broad-except 976 if hasattr(e, "ag_error_metadata"): --> 977 raise e.ag_error_metadata.to_exception(e) 978 else: 979 raise

ValueError: in user code:

/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:805 train_function  *
    return step_function(self, iterator)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:795 step_function  **
    outputs = model.distribute_strategy.run(run_step, args=(data,))
/usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/distribute_lib.py:1259 run
    return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/distribute_lib.py:2730 call_for_each_replica
    return self._call_for_each_replica(fn, args, kwargs)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/distribute_lib.py:3417 _call_for_each_replica
    return fn(*args, **kwargs)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:788 run_step  **
    outputs = model.train_step(data)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:754 train_step
    y_pred = self(x, training=True)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/base_layer.py:1012 __call__
    outputs = call_fn(inputs, *args, **kwargs)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/sequential.py:375 call
    return super(Sequential, self).call(inputs, training=training, mask=mask)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/functional.py:425 call
    inputs, training=training, mask=mask)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/functional.py:560 _run_internal_graph
    outputs = node.layer(*args, **kwargs)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/base_layer.py:1012 __call__
    outputs = call_fn(inputs, *args, **kwargs)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/layers/convolutional.py:248 call
    outputs = self._convolution_op(inputs, self.kernel)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py:201 wrapper
    return target(*args, **kwargs)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/nn_ops.py:1020 convolution_v2
    name=name)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/nn_ops.py:1150 convolution_internal
    name=name)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/nn_ops.py:2615 _conv2d_expanded_batch
    name=name)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/nn_ops.py:313 squeeze_batch_dims
    out_reshaped = op(inp_reshaped)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/gen_nn_ops.py:973 conv2d
    data_format=data_format, dilations=dilations, name=name)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/op_def_library.py:750 _apply_op_helper
    attrs=attr_protos, op_def=op_def)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py:592 _create_op_internal
    compute_device)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/ops.py:3536 _create_op_internal
    op_def=op_def)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/ops.py:2016 __init__
    control_input_ops, op_def)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/ops.py:1856 _create_c_op
    raise ValueError(str(e))

ValueError: Negative dimension size caused by subtracting 18729 from 1 for '{{node sequential_20/conv2d_16/Conv2D/Conv2D}} = Conv2D[T=DT_FLOAT, data_format="NHWC", dilations=[1, 1, 1, 1], explicit_paddings=[], padding="VALID", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true](sequential_20/conv2d_16/Conv2D/Reshape, sequential_20/conv2d_16/Conv2D/Conv2D/ReadVariableOp)' with input shapes: [?,1,1,1], [18729,2,1,1].

The code is this:

%tensorflow_version 2.3

import tensorflow as tf X_Train = X_train_scaled.reshape(X_train.shape + (-1,)) print(X_Train.shape) # (8000,20,32,1) Y_Train = Y_train_scaled.reshape( Y_train.shape+ (-1,)) print(Y_Train.shape) # (8000,20,32,1)

model = tf.keras.models.Sequential([ tf.keras.layers.Conv2D(1, (18729,2), input_shape=(18729,2,1))])

model.compile(loss='mse', optimizer='rmsprop',metrics=['accuracy']) print ('compilation time : ', time.time() - start)

paulprasanth536 avatar May 21 '21 05:05 paulprasanth536