tensorflow.python.framework.errors_impl.InvalidArgumentError: Default MaxPoolingOp only supports NHWC on device type CPU

Viewed 937

when i use keras VGG16 pre-trained model to get bottleneck feature in tf.dataset.map function, i got this problem

vgg16 = VGG16(include_top=False, input_shape=input_shape)
vgg16.trainable = False


def _parse_function(example_proto):
  features = {'img': tf.FixedLenFeature((), tf.string, default_value=""),
              'label': tf.FixedLenFeature((), tf.int64, default_value=0)}
  parsed_features = tf.parse_single_example(example_proto, features)
  img = tf.decode_raw(parsed_features['img'], tf.uint8)
  img = tf.reshape(img, (224, 224, 3))
  img = tf.cast(img, tf.float32) / 255.0
  img = tf.expand_dims(img, 0)
  img = vgg16(img)
  img = tf.squeeze(img, [0])
  label = parsed_features['label']
  return img, label

ds.map(_parse_function)

the error print is

2019-06-19 13:47:19.378807: E tensorflow/core/common_runtime/executor.cc:624] Executor failed to create kernel. Invalid argument: Default MaxPoolingOp only supports NHWC on device type CPU [[{{node vgg16/block1_pool/MaxPool}}]] 2019-06-19 13:47:19.379204: W tensorflow/core/framework/op_kernel.cc:1401] OP_REQUIRES failed at iterator_ops.cc:660 : Invalid argument: Default MaxPoolingOp only supports NHWC on device type CPU [[{{node vgg16/block1_pool/MaxPool}}]] Traceback (most recent call last): File "/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1334, in _do_call return fn(*args) File "/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1319, in _run_fn options, feed_dict, fetch_list, target_list, run_metadata) File "/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1407, in _call_tf_sessionrun run_metadata) tensorflow.python.framework.errors_impl.InvalidArgumentError: Default MaxPoolingOp only supports NHWC on device type CPU [[{{node vgg16/block1_pool/MaxPool}}]] [[{{node MakeIterator}}]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/tf/image_cls/train.py", line 103, in steps_per_epoch=steps_per_epoch, File "/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py", line 776, in fit shuffle=shuffle) File "/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py", line 2200, in _standardize_user_data K.get_session().run(x.initializer) File "/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 929, in run run_metadata_ptr) File "/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1152, in _run feed_dict_tensor, options, run_metadata) File "/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1328, in _do_run run_metadata) File "/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1348, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.InvalidArgumentError: Default MaxPoolingOp only supports NHWC on device type CPU [[{{node vgg16/block1_pool/MaxPool}}]] [[node MakeIterator (defined at /home/tf/image_cls/train.py:103) ]]

0 Answers
Related