A
A
Andrei1penguin12021-02-02 13:53:04
Python
Andrei1penguin1, 2021-02-02 13:53:04

Why does an error occur when compiling the model?

Good day, there is a model:

seq = Sequential()
        seq.add(Conv2D(6, 3, 3, activation="relu", input_shape=input_shape, padding='valid', data_format="channels_first"))
        seq.add(MaxPooling2D(pool_size=(2, 2)))
        seq.add(Dropout(0.25))
        seq.add(Conv2D(12, 3, 3, activation="relu", padding='valid', data_format="channels_first"))
        seq.add(MaxPooling2D(pool_size=(2, 2), data_format='channels_first'))
        seq.add(Dropout(0.25))
        seq.add(Flatten())
        seq.add(Dense(128, activation='relu'))
        seq.add(Dropout(0.1))
        seq.add(Dense(50, activation='relu'))

The model is compiled as follows:
X, Y = self.get_data()
        x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=.25)
        input_dim = x_train.shape[2:]
        img_a = Input(shape=input_dim)
        img_b = Input(shape=input_dim)
        base_network = self.model(input_dim)
        feat_vecs_a = base_network(img_a)
        feat_vecs_b = base_network(img_b)
        distance = Lambda(self.euclidean_distance, output_shape=self.eucl_dist_output_shape)([feat_vecs_a, feat_vecs_b])
        rms = RMSprop()
        model = Model(inputs=[img_a, img_b], outputs=distance)
        model.compile(loss=self.contrastive_loss, optimizer=rms)

Where X.shape = (20000, 2, 1, 56, 46), Y.shape = (20000, 1)
The following error occurs:
Epoch 1/13
2021-02-02 13:48:44.211480: E tensorflow/core/ common_runtime/executor.cc:623] Executor failed to create kernel. Invalid argument: Default MaxPoolingOp only supports NHWC on device type CPU

Traceback (most recent call last):
File "main.py", line 673, in
run.train()
File "main.py", line 667, in train
model.fit([img_1, img_2], y_train, validation_split=.25, batch_size=128, verbose=2, epochs=13)
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\ site-packages\tensorflow\python\keras\engine\training.py", line 1639, in fit
validation_steps=validation_steps)
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages \tensorflow\python\keras\engine\training_arrays.py", line 215, in fit_loop
outs = f(ins_batch)
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\ tensorflow\python\keras\backend.py", line 2983, in __call__
self._make_callable(feed_arrays, feed_symbols, symbol_vals, session)
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\keras\backend.py", line 2928, in _make_callable
callable_fn = session._make_callable_from_options(callable_opts)
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\client\session.py", line 1471, in _make_callable_from_options
return BaseSession._Callable(self, callable_options)
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\client\session.py", line 1425, in __init__
session._session, options_ptr, status)
File " C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 528,in __exit__
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Default MaxPoolingOp only supports NHWC on device type CPU

Exception ignored in:
Traceback (most recent call last):
File "C:\Users \user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\client\session.py", line 1455, in __del__
self._session._session, self._handle, status)
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 528, in __exit__
c_api.TF_GetCode(self.status.status ))
tensorflow.python.framework.errors_impl.InvalidArgumentError: No such callable handle: 2616280080656

And I don't understand whether maxpooling complains on cpu, or the data is incorrect

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Dugin, 2021-02-02
@Andrei1penguin1

Your error says: "Default MaxPoolingOp only supports NHWC on device type CPU", i.e. on the CPU, only channels last is supported for MaxPooling, and you feed channels first. NHWC = (n_samples, height, width, channels).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question