onnx / tutorials

Tutorials for creating and using ONNX models
Apache License 2.0
3.34k stars 626 forks source link

tutorials/tutorials/assets/tf-train-mnist.py not working #45

Open yichuan1118 opened 6 years ago

yichuan1118 commented 6 years ago

getting the following error when running this script

⟩ python tf-train-mnist.py
WARNING:tensorflow:From tf-train-mnist.py:125: read_data_sets (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use alternatives such as official/mnist/dataset.py from tensorflow/models.
WARNING:tensorflow:From /usr/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:260: maybe_download (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version.
Instructions for updating:
Please write your own downloading logic.
WARNING:tensorflow:From /usr/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/datasets/base.py:252: wrapped_fn (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version.
Instructions for updating:
Please use urllib or similar directly.
Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
WARNING:tensorflow:From /usr/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:262: extract_images (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use tf.data to implement this functionality.
Extracting /tmp/tensorflow/mnist/input_data/train-images-idx3-ubyte.gz
Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.
WARNING:tensorflow:From /usr/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:267: extract_labels (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use tf.data to implement this functionality.
Extracting /tmp/tensorflow/mnist/input_data/train-labels-idx1-ubyte.gz
Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.
Extracting /tmp/tensorflow/mnist/input_data/t10k-images-idx3-ubyte.gz
Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.
Extracting /tmp/tensorflow/mnist/input_data/t10k-labels-idx1-ubyte.gz
WARNING:tensorflow:From /usr/local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:290: __init__ (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.
Instructions for updating:
Please use alternatives such as official/mnist/dataset.py from tensorflow/models.
Saving graph to: /var/folders/xg/lb58443132sb9khl0f8k7m700000gn/T/tmpaitUPD
2018-06-27 11:53:51.868247: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2018-06-27 11:53:52.129638: E tensorflow/core/common_runtime/executor.cc:660] Executor failed to create kernel. Invalid argument: Default MaxPoolingOp only supports NHWC on device type CPU
     [[Node: pool1/MaxPool = MaxPool[T=DT_FLOAT, data_format="NCHW", ksize=[1, 1, 2, 2], padding="SAME", strides=[1, 1, 2, 2], _device="/job:localhost/replica:0/task:0/device:CPU:0"](conv1/Relu)]]
Traceback (most recent call last):
  File "tf-train-mnist.py", line 183, in <module>
    tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 126, in run
    _sys.exit(main(argv))
  File "tf-train-mnist.py", line 167, in main
    x: batch[0], y_: batch[1]})
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 710, in eval
    return _eval_using_default_session(self, feed_dict, self.graph, session)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 5180, in _eval_using_default_session
    return session.run(tensors, feed_dict)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 900, in run
    run_metadata_ptr)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1135, in _run
    feed_dict_tensor, options, run_metadata)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1316, in _do_run
    run_metadata)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1335, 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: pool1/MaxPool = MaxPool[T=DT_FLOAT, data_format="NCHW", ksize=[1, 1, 2, 2], padding="SAME", strides=[1, 1, 2, 2], _device="/job:localhost/replica:0/task:0/device:CPU:0"](conv1/Relu)]]

Caused by op u'pool1/MaxPool', defined at:
  File "tf-train-mnist.py", line 183, in <module>
    tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 126, in run
    _sys.exit(main(argv))
  File "tf-train-mnist.py", line 131, in main
    y_conv = deepnn(x)
  File "tf-train-mnist.py", line 69, in deepnn
    h_pool1 = max_pool_2x2(h_conv1)
  File "tf-train-mnist.py", line 108, in max_pool_2x2
    strides=[1, 1, 2, 2], padding='SAME', data_format="NCHW")
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/nn_ops.py", line 2142, in max_pool
    name=name)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_nn_ops.py", line 4604, in max_pool
    data_format=data_format, name=name)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op
    op_def=op_def)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1718, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Default MaxPoolingOp only supports NHWC on device type CPU
     [[Node: pool1/MaxPool = MaxPool[T=DT_FLOAT, data_format="NCHW", ksize=[1, 1, 2, 2], padding="SAME", strides=[1, 1, 2, 2], _device="/job:localhost/replica:0/task:0/device:CPU:0"](conv1/Relu)]]
OwenLiuzZ commented 6 years ago

Yes, I have meet with the same problem

OwenLiuzZ commented 6 years ago

python test1.py --device=cpu --data_format=NHWC WARNING:tensorflow:From test1.py:122: read_data_sets (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version. Instructions for updating: Please use alternatives such as official/mnist/dataset.py from tensorflow/models. WARNING:tensorflow:From /Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:260: maybe_download (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version. Instructions for updating: Please write your own downloading logic. WARNING:tensorflow:From /Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:262: extract_images (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version. Instructions for updating: Please use tf.data to implement this functionality. Extracting /tmp/tensorflow/mnist/input_data/train-images-idx3-ubyte.gz WARNING:tensorflow:From /Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:267: extract_labels (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version. Instructions for updating: Please use tf.data to implement this functionality. Extracting /tmp/tensorflow/mnist/input_data/train-labels-idx1-ubyte.gz Extracting /tmp/tensorflow/mnist/input_data/t10k-images-idx3-ubyte.gz Extracting /tmp/tensorflow/mnist/input_data/t10k-labels-idx1-ubyte.gz WARNING:tensorflow:From /Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:290: DataSet.init (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version. Instructions for updating: Please use alternatives such as official/mnist/dataset.py from tensorflow/models. Saving graph to: /var/folders/5x/prh0yx817bz_gky7k98hnvnc0000gn/T/tmpsbp0zfjd 2018-07-10 14:17:05.739052: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA 2018-07-10 14:17:05.988595: E tensorflow/core/common_runtime/executor.cc:660] Executor failed to create kernel. Invalid argument: Default MaxPoolingOp only supports NHWC on device type CPU [[Node: pool1/MaxPool = MaxPoolT=DT_FLOAT, data_format="NCHW", ksize=[1, 1, 2, 2], padding="SAME", strides=[1, 1, 2, 2], _device="/job:localhost/replica:0/task:0/device:CPU:0"]] Traceback (most recent call last): File "/Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1322, in _do_call return fn(*args) File "/Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1307, in _run_fn options, feed_dict, fetch_list, target_list, run_metadata) File "/Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1409, in _call_tf_sessionrun run_metadata) tensorflow.python.framework.errors_impl.InvalidArgumentError: Default MaxPoolingOp only supports NHWC on device type CPU [[Node: pool1/MaxPool = MaxPoolT=DT_FLOAT, data_format="NCHW", ksize=[1, 1, 2, 2], padding="SAME", strides=[1, 1, 2, 2], _device="/job:localhost/replica:0/task:0/device:CPU:0"]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "test1.py", line 180, in tf.app.run(main=main, argv=[sys.argv[0]] + unparsed) File "/Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 126, in run sys.exit(main(argv)) File "test1.py", line 164, in main x: batch[0], y: batch[1]}) File "/Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 710, in eval return _eval_using_default_session(self, feed_dict, self.graph, session) File "/Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 5180, in _eval_using_default_session return session.run(tensors, feed_dict) File "/Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 900, in run run_metadata_ptr) File "/Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1135, in _run feed_dict_tensor, options, run_metadata) File "/Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1316, in _do_run run_metadata) File "/Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1335, 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: pool1/MaxPool = MaxPoolT=DT_FLOAT, data_format="NCHW", ksize=[1, 1, 2, 2], padding="SAME", strides=[1, 1, 2, 2], _device="/job:localhost/replica:0/task:0/device:CPU:0"]]

Caused by op 'pool1/MaxPool', defined at: File "test1.py", line 180, in tf.app.run(main=main, argv=[sys.argv[0]] + unparsed) File "/Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 126, in run _sys.exit(main(argv)) File "test1.py", line 128, in main y_conv = deepnn(x) File "test1.py", line 66, in deepnn h_pool1 = max_pool_2x2(h_conv1) File "test1.py", line 105, in max_pool_2x2 strides=[1, 1, 2, 2], padding='SAME', data_format="NCHW") File "/Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/ops/nn_ops.py", line 2142, in max_pool name=name) File "/Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/ops/gen_nn_ops.py", line 4604, in max_pool data_format=data_format, name=name) File "/Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "/Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op op_def=op_def) File "/Users/liusichao/anaconda3/envs/py3.6/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1718, in init self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Default MaxPoolingOp only supports NHWC on device type CPU [[Node: pool1/MaxPool = MaxPoolT=DT_FLOAT, data_format="NCHW", ksize=[1, 1, 2, 2], padding="SAME", strides=[1, 1, 2, 2], _device="/job:localhost/replica:0/task:0/device:CPU:0"]]

OwenLiuzZ commented 6 years ago

I use a likely solution but it does not work for me: Default MaxPoolingOp only supports NHWC #82

OwenLiuzZ commented 6 years ago

I have deal with this problem. data_format="NCHW". This data format is for GPU training. So you need to train it in GPU machine

sosam29 commented 6 years ago

Not sure when you mentioned that this data format is for GPU training. does it work on CPU?

mukul74 commented 5 years ago

I have made the changes in the .py file to run it Like: Previous W_conv1 = weight_variable([5, 5, 1, 32]) b_conv1 = bias_variable([32]) h_conv1 = tf.nn.relu(add(conv2d(x_image, W_conv1), b_conv1))

Changed by this New

W_conv1 = weight_variable([5, 5, 1, 32])

b_conv1 = bias_variable([32])

h_conv1 = tf.layers.conv2d(x_image, 32, 5, activation=tf.nn.relu)