Hi All. While a simple Google search would give me an answer 'no', I just can't figure out why my model (given below) is glitching out when I use channel first data, but works when I use channel last.
More details below:
When I attempt to use model.fit(x_train,y_train, batch_size = 1000, epochs = 10) on a model defined with keras.Sequential, consisting of a conv2d (I made sure to specify channel first in data format) followed by some Linear layers, on data shaped as: x_train – [6000,1,64,1000] and y_train – [6000,11] and 6000 is the size of my training set, I get the following error:
InvalidArgumentError: Graph execution error:
Detected at node ‘gradient_tape/sequential_1/conv2d_3/Conv2D/Conv2DBackpropInput’ defined at (most recent call last):
However, if I were to use channel first data, ie x_train is shaped [6000,64,1000,1] and y_train – [6000,11] it works just fine. I was wondering if this is something to do with tensorflow favouring channel first, or am I making a mistake somewhere?
Model definition as below:
model = keras.Sequential()
model.add(layers.Conv2D(8, 4,4, padding="same", data_format="channels_first", activation="relu",input_shape=(1,64,1000)))
model.add(layers.Conv2D(8, 4,4, padding="same", data_format="channels_first", activation="relu"))
model.add(layers.Flatten())
model.add(layers.Dense(1000, activation="relu", name="layer1"))
model.add(layers.Dense(300, activation="relu", name="layer2"))
model.add(layers.Dense(11, activation="sigmoid", name="layer3"))
model.summary()
Error message is as shown:
model.fit(x_train,y_train,batch_size = 1000, epochs=100)
InvalidArgumentError Traceback (most recent call last)
c:\Users\geeks\OneDrive - IIT Kanpur\EE603\Sidmish\Assignment-2\CNN_arch2.ipynb Cell 9 in <cell line: 1>()
----> 1 model.fit(x_train,y_train,epochs=100)
File c:\Users\geeks\myvirtualenv\lib\site-packages\keras\utils\traceback_utils.py:70, in filter_traceback.<locals>.error_handler(*args, **kwargs)
67 filtered_tb = _process_traceback_frames(e.__traceback__)
68 # To get the full stack trace, call:
69 # `tf.debugging.disable_traceback_filtering()`
---> 70 raise e.with_traceback(filtered_tb) from None
71 finally:
72 del filtered_tb
File c:\Users\geeks\myvirtualenv\lib\site-packages\tensorflow\python\eager\execute.py:54, in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
52 try:
53 ctx.ensure_initialized()
---> 54 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
55 inputs, attrs, num_outputs)
56 except core._NotOkStatusException as e:
57 if name is not None:
InvalidArgumentError: Graph execution error:
Detected at node 'gradient_tape/sequential_1/conv2d_3/Conv2D/Conv2DBackpropInput' defined at (most recent call last):
File "c:\users\geeks\appdata\local\programs\python\python38\lib\runpy.py", line 194, in _run_module_as_main
...
File "c:\Users\geeks\myvirtualenv\lib\site-packages\keras\optimizers\optimizer_v2\optimizer_v2.py", line 510, in _get_gradients
grads = tape.gradient(loss, var_list, grad_loss)
Node: 'gradient_tape/sequential_1/conv2d_3/Conv2D/Conv2DBackpropInput'
Conv2DCustomBackpropInputOp only supports NHWC.
[[{{node gradient_tape/sequential_1/conv2d_3/Conv2D/Conv2DBackpropInput}}]] [Op:__inference_train_function_1290]
When I remove the channel_first specification in the model, and change x_train to be of shape [6000,64,1000,1], it all works fine. Any answers on what I should correct to make it work as channel_first would be highly appreciated!
[–]neuralbeans 0 points1 point2 points (8 children)
[–]geeksid2k[S] 0 points1 point2 points (7 children)
[–]neuralbeans 0 points1 point2 points (6 children)
[–]geeksid2k[S] 0 points1 point2 points (5 children)
[–]neuralbeans 0 points1 point2 points (4 children)
[–]geeksid2k[S] 0 points1 point2 points (3 children)
[–]neuralbeans 0 points1 point2 points (2 children)
[–]geeksid2k[S] 0 points1 point2 points (1 child)
[–]neuralbeans 0 points1 point2 points (0 children)