title: What does Default MaxPoolingOp only supports NHWC on device type CPU [[{{node maxpool4/MaxPool}}]] mean?
body: <p>I'm attempting to write the squeezenet CNN found in matlab inside python. In my attempt of doing so I got an error. I found the inspiration for this code on github and will link the person as well to make sure they get the credit they deserve.
  <a href="https://github.com/chasingbob/squeezenet-keras" rel="nofollow noreferrer">https://github.com/chasingbob/squeezenet-keras</a></p>
  <pre><code>```
  InvalidArgumentError                      Traceback (most recent call last)
  &lt;ipython-input-21-faad1ec2e17b&gt; in &lt;module&gt;
   23             validation_data=val_data_gen,
   24             #nb_val_samples=21,
   ---&gt; 25             callbacks=[checkpoint])
   
   in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, 
   validation_data, validation_steps, validation_freq, class_weight, 
   max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
   1294         shuffle=shuffle,
   1295         initial_epoch=initial_epoch,
   -&gt;1296         steps_name='steps_per_epoch')
   1297 
   1298   def evaluate_generator(self,
  
   in model_iteration(model, data, steps_per_epoch, epochs, verbose, callbacks, 
   validation_data, validation_steps, validation_freq, class_weight, 
   max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch, mode, 
   batch_size, steps_name, **kwargs)
   263 
   264       is_deferred = not model._is_compiled
   --&gt;  265       batch_outs = batch_function(*batch_data)
   266       if not isinstance(batch_outs, list):
   267         batch_outs = [batch_outs]
  
   in train_on_batch(self, x, y, sample_weight, class_weight, reset_metrics)
   1015       self._update_sample_weight_modes(sample_weights=sample_weights)
   1016       self._make_train_function()
   -&gt; 1017       outputs = self.train_function(ins)  # pylint: disable=not- 
   callable
   1018 
   1019     if reset_metrics:
  
   in __call__(self, inputs)
   3471         feed_symbols != self._feed_symbols or self.fetches != 
   self._fetches or
   3472         session != self._session):
   -&gt; 3473       self._make_callable(feed_arrays, feed_symbols, symbol_vals, session)
   3474 
   3475     fetched = self._callable_fn(*array_vals,
  
   in _make_callable(self, feed_arrays, feed_symbols, symbol_vals, session)
   3408       callable_opts.run_options.CopyFrom(self.run_options)
   3409     # Create callable.
   -&gt; 3410     callable_fn = session._make_callable_from_options(callable_opts)
   3411     # Cache parameters corresponding to the generated callable, so that
   3412     # we can detect future mismatches and refresh the callable.
  
   in _make_callable_from_options(self, callable_options)
   1503     &quot;&quot;&quot;
   1504     self._extend_graph()
   -&gt; 1505     return BaseSession._Callable(self, callable_options)
   1506 
   1507 
  
   in __init__(self, session, callable_options)
   1458       try:
   1459         self._handle = tf_session.TF_SessionMakeCallable(
   -&gt; 1460             session._session, options_ptr)
   1461       finally:
   1462         tf_session.TF_DeleteBuffer(options_ptr)
  
   InvalidArgumentError: Default MaxPoolingOp only supports NHWC on device type 
   CPU
   [[{{node maxpool4/MaxPool}}]]
  
   
  </code></pre>
  <p>Here is the code</p>
  <pre><code>batch_size = 10
  epochs = 18
  IMG_HEIGHT = 227
  IMG_WIDTH = 227
  
  train_image_generator = ImageDataGenerator(rescale=1./255) # Generator for our 
  training data
  validation_image_generator = ImageDataGenerator(rescale=1./255) # Generator for 
  our validation data
  
  train_data_gen = train_image_generator.flow_from_directory(batch_size=batch_size,
                                                             directory=train_dir,
                                                             shuffle=False,
                                                             target_size=(IMG_HEIGHT, IMG_WIDTH),
                                                             class_mode='categorical')
  
  
  
  val_data_gen = validation_image_generator.flow_from_directory(batch_size=batch_size,
                                                            directory=validation_dir,
                                                            target_size=(IMG_HEIGHT, IMG_WIDTH),
                                                            class_mode='categorical')
  
  
  def SqueezeNet(nb_classes, inputs=(227,227,3)):
      # Keras Implementation of SqueezeNet(arXiv 1602.07360)
      #Arguments:
          #nb_classes: total number of final categories
          
          #inputs -- shape of the input images (channel, cols, rows)
      
      input_img = Input(shape=(227,227,3))
      conv1 = Convolution2D(
          96, 7, 7, activation='relu', kernel_initializer='glorot_uniform',#strides=(2,2),
           padding='same', name='conv1')(input_img)
      
      maxpool1 = MaxPooling2D(
          pool_size=(1, 1), strides=(2, 2), name='maxpool1')(conv1)
  
      fire2_squeeze = Convolution2D(
          16, 1, 1, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire2_squeeze')(maxpool1)
      fire2_expand1 = Convolution2D(
          64, 3, 3, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire2_expand1')(fire2_squeeze)
      fire2_expand2 = Convolution2D(
          64, 3, 3, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire2_expand2')(fire2_squeeze)
      merge2 = concatenate(
          [fire2_expand1, fire2_expand2], axis=1)
  
      fire3_squeeze = Convolution2D(
          16, 1, 1, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire3_squeeze')(merge2)
      fire3_expand1 = Convolution2D(
          64, 3, 3, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire3_expand1')(fire3_squeeze)
      fire3_expand2 = Convolution2D(
          64, 3, 3, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire3_expand2')(fire3_squeeze)
      merge3 = concatenate(
          [fire3_expand1, fire3_expand2], axis=1)
  
      fire4_squeeze = Convolution2D(
          32, 1, 1, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire4_squeeze')(merge3)
      fire4_expand1 = Convolution2D(
          128, 3, 3, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire4_expand1')(fire4_squeeze)
      fire4_expand2 = Convolution2D(
          128, 3, 3, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire4_expand2')(fire4_squeeze)
      merge4 = concatenate(
          [fire4_expand1, fire4_expand2], axis=1)
      maxpool4 = MaxPooling2D(
          pool_size=(1, 1), strides=(2, 2), name='maxpool4',data_format = 'channels_first')(merge4) 
  
      fire5_squeeze = Convolution2D(
          32, 1, 1, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire5_squeeze')(maxpool4)
      fire5_expand1 = Convolution2D(
          128, 3, 3, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire5_expand1')(fire5_squeeze)
      fire5_expand2 = Convolution2D(
          128, 3, 3, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire5_expand2')(fire5_squeeze)
      merge5 = concatenate(
          [fire5_expand1, fire5_expand2], axis=1)
  
      fire6_squeeze = Convolution2D(
          48, 1, 1, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire6_squeeze')(merge5)
      fire6_expand1 = Convolution2D(
          192, 3, 3, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire6_expand1')(fire6_squeeze)
      fire6_expand2 = Convolution2D(
          192, 3, 3, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire6_expand2')(fire6_squeeze)
      merge6 = concatenate(
          [fire6_expand1, fire6_expand2], axis=1)
  
      fire7_squeeze = Convolution2D(
          48, 1, 1, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire7_squeeze')(merge6)
      fire7_expand1 = Convolution2D(
          192, 3, 3, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire7_expand1')(fire7_squeeze)
      fire7_expand2 = Convolution2D(
          192, 3, 3, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire7_expand2')(fire7_squeeze)
      merge7 = concatenate(
          [fire7_expand1, fire7_expand2], axis=1)
  
      fire8_squeeze = Convolution2D(
          64, 1, 1, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire8_squeeze')(merge7)
      fire8_expand1 = Convolution2D(
          256, 3, 3, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire8_expand1')(fire8_squeeze)
      fire8_expand2 = Convolution2D(
          256, 3, 3, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire8_expand2')(fire8_squeeze)
      merge8 = concatenate(
          [fire8_expand1, fire8_expand2], axis=1)
  
      maxpool8 = MaxPooling2D(
          pool_size=(1, 1), strides=(2, 2), name='maxpool8',data_format = 'channels_first')(merge8)
  
      fire9_squeeze = Convolution2D(
          64, 1, 1, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire9_squeeze')(maxpool8)
      fire9_expand1 = Convolution2D(
          256, 3, 3, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire9_expand1')(fire9_squeeze)
      fire9_expand2 = Convolution2D(
          256, 3, 3, activation='relu', kernel_initializer='glorot_uniform',
          padding='same', name='fire9_expand2')(fire9_squeeze)
      merge9 = concatenate(
          [fire9_expand1, fire9_expand2], axis=1)
  
      fire9_dropout = Dropout(0.6, name='fire9_dropout')(merge9)
      conv10 = Convolution2D(
          nb_classes, 1, 1, kernel_initializer='glorot_uniform',
          padding='valid', name='conv10')(fire9_dropout)
      # The size should match the output of conv10
      avgpool10 = AveragePooling2D((1, 1), name='avgpool10')(conv10)
  
      flatten = Flatten(name='flatten')(avgpool10)
      softmax = Activation(&quot;softmax&quot;, name='softmax')(flatten)
  
      return Model(inputs=input_img, outputs=softmax)
  
  
  from tensorflow.keras.optimizers import SGD
  from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint
  from tensorflow.keras.preprocessing.image import ImageDataGenerator
  model = SqueezeNet(2,inputs=(227,227,3))
  
  sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
  model.compile(optimizer=sgd,
                #loss=&quot;mse&quot;,
                loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
                metrics=['accuracy'])
  
  batch_size = 32
  nb_classes = 10
  nb_epoch = 200
  
  early_stopping = EarlyStopping(monitor='val_loss', patience=3, verbose=0)
  checkpoint = ModelCheckpoint(                                         
                  'weights.{epoch:02d}-{val_loss:.2f}.h5',
                  monitor='val_loss',                               
                  verbose=0,                                        
                  save_best_only=True,                              
                  save_weights_only=True,                           
                  mode='min',                                       
                  period=1)                                         
  
  
  #model = CustomModel(inputs, outputs)
  tf.config.threading.set_intra_op_parallelism_threads(2)
  tf.config.threading.set_inter_op_parallelism_threads(2)
  model.fit_generator(
              train_data_gen,
              #samples_per_epoch=10,
              #epoch=18,
              validation_data=val_data_gen,
              #nb_val_samples=21, 
              callbacks=[checkpoint])
  </code></pre>