tensorflow slim giving error while training train_image_classifier.py
Hi, I am trying to train my own model using inception_v3 architecture with using small sample data taken as flowers data
when I am trying to run the following command, its giving the error python train_image_classifier.py --train_dir=${TRAIN_DIR} --dataset_name=flowers --dataset_split_name=train --dataset_dir=${DATASET_DIR} --model_name=inception_v3
the error is like this
(/home/mcis-lap-49/work/anaconda2) mcis-lap-49@MCIS-LAP-49:~/slim$ python train_image_classifier.py --train_dir=${TRAIN_DIR} --dataset_name=flowers --dataset_split_name=train --dataset_dir=${DATASET_DIR} --model_name=inception_v3 INFO:tensorflow:Summary name /clone_loss is illegal; using clone_loss instead. 2017-08-14 15:14:01.398254: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. 2017-08-14 15:14:01.398303: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. 2017-08-14 15:14:01.398317: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. 2017-08-14 15:14:01.398328: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations. 2017-08-14 15:14:01.398338: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations. INFO:tensorflow:Error reported to Coordinator: <class 'tensorflow.python.framework.errors_impl.InvalidArgumentError'>, Cannot assign a device for operation 'gradients/InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/moments/Sub_grad/BroadcastGradientArgs': Operation was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/cpu:0 ]. Make sure the device specification refers to a valid device. [[Node: gradients/InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/moments/Sub_grad/BroadcastGradientArgs = BroadcastGradientArgs[T=DT_INT32, _device="/device:GPU:0"](gradients/InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/moments/Sub_grad/Shape, gradients/InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/moments/Sub_grad/Shape_1)]]
Caused by op u'gradients/InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/moments/Sub_grad/BroadcastGradientArgs', defined at:
File "train_image_classifier.py", line 573, in
...which was originally created as op u'InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/moments/Sub', defined at:
File "train_image_classifier.py", line 573, in
InvalidArgumentError (see above for traceback): Cannot assign a device for operation 'gradients/InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/moments/Sub_grad/BroadcastGradientArgs': Operation was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/cpu:0 ]. Make sure the device specification refers to a valid device. [[Node: gradients/InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/moments/Sub_grad/BroadcastGradientArgs = BroadcastGradientArgs[T=DT_INT32, _device="/device:GPU:0"](gradients/InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/moments/Sub_grad/Shape, gradients/InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/moments/Sub_grad/Shape_1)]]
Traceback (most recent call last):
File "train_image_classifier.py", line 573, in
Caused by op u'gradients/InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/moments/Sub_grad/BroadcastGradientArgs', defined at:
File "train_image_classifier.py", line 573, in
...which was originally created as op u'InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/moments/Sub', defined at:
File "train_image_classifier.py", line 573, in
InvalidArgumentError (see above for traceback): Cannot assign a device for operation 'gradients/InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/moments/Sub_grad/BroadcastGradientArgs': Operation was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/cpu:0 ]. Make sure the device specification refers to a valid device. [[Node: gradients/InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/moments/Sub_grad/BroadcastGradientArgs = BroadcastGradientArgs[T=DT_INT32, _device="/device:GPU:0"](gradients/InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/moments/Sub_grad/Shape, gradients/InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/moments/Sub_grad/Shape_1)]]
ERROR:tensorflow:==================================
Object was never used (type <class 'tensorflow.python.framework.ops.Tensor'>):
<tf.Tensor 'init_ops/report_uninitialized_variables/boolean_mask/Gather:0' shape=(?,) dtype=string>
If you want to mark it as used call its "mark_used()" method.
It was originally created here:
['File "train_image_classifier.py", line 573, in \n tf.app.run()', 'File "/home/mcis-lap-49/work/anaconda2/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 48, in run\n _sys.exit(main(_sys.argv[:1] + flags_passthrough))', 'File "train_image_classifier.py", line 569, in main\n sync_optimizer=optimizer if FLAGS.sync_replicas else None)', 'File "/home/mcis-lap-49/work/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/slim/python/slim/learning.py", line 655, in train\n ready_op = tf_variables.report_uninitialized_variables()', 'File "/home/mcis-lap-49/work/anaconda2/lib/python2.7/site-packages/tensorflow/python/util/tf_should_use.py", line 170, in wrapped\n return _add_should_use_warning(fn(*args, **kwargs))', 'File "/home/mcis-lap-49/work/anaconda2/lib/python2.7/site-packages/tensorflow/python/util/tf_should_use.py", line 139, in _add_should_use_warning\n wrapped = TFShouldUseWarningWrapper(x)', 'File "/home/mcis-lap-49/work/anaconda2/lib/python2.7/site-packages/tensorflow/python/util/tf_should_use.py", line 96, in init\n stack = [s.strip() for s in traceback.format_stack()]']
I didn't understand what is this error.... please help me
There's a lot of output but I think this is the important part of the stack traces:
Cannot assign a device for operation 'gradients/InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/moments/Sub_grad/BroadcastGradientArgs': Operation was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/cpu:0 ]. Make sure the device specification refers to a valid device.
Looks like you're trying to assign to a GPU but you don't have one.
@skye i have one 1080ti installed on my computer and i still got the error ?? do you know how to fix it ? when i run normal inception it runs fine.
Hi @vaibhav0195 , I'm guessing you haven't installed a TF version with GPU configuration, but it's hard to say for certain. Please post on StackOverflow for more help.
@skye I have fixed the issue it is due the kernel problem.
Can you specify how to fix the issue? @vaibhav0195 I got exactly the same problem
I solved this issue by providing an extra arg '--clone_on_cpu=True' while running ( which is False by default) i.e.
python train_image_classifier.py --clone_on_cpu=True --train_dir=${TRAIN_DIR} --dataset_name=flowers --dataset_split_name=train --dataset_dir=${DATASET_DIR} --model_name=inception_v3
I also encountered the same problem . Could you please talk about how you fix it ?And the kernel problem means? Thanks @vaibhav0195
@SragAR thats is a flag to use cpu not gpu. cloning on cpu will take forever to train especially if you have large dataset. I solved the same issue by reinstalling tenserflow as gpu as per @skye comment. thanks. pip install tensorflow-gpu==1.2.1 (maybe it is wont work with 1.3.0 version of tensorflow)
I encounter a similar problem, and I try too pass a parameter "session_config = tf.ConfigProto(allow_soft_placement=True)" to slim.learning.train().
@robindume Do you succeed? I am looking for this too and but have no idea about it.
@robindume I found the answer:
slim.learning.train( train_tensor, session_config=tf.ConfigProto(allow_soft_placement=True), logdir=FLAGS.train_dir, master=FLAGS.master, is_chief=(FLAGS.task == 0), init_fn=_get_init_fn(), summary_op=summary_op, number_of_steps=FLAGS.max_number_of_steps, log_every_n_steps=FLAGS.log_every_n_steps, save_summaries_secs=FLAGS.save_summaries_secs, save_interval_secs=FLAGS.save_interval_secs, sync_optimizer=optimizer if FLAGS.sync_replicas else None)
@robindume @GraceDSeven This would make your code run but only on CPU. It takes forever if you have a large dataset!
Two ways to solve it,
- Go to the code find the flag clone-on-cpu by default, it is set as false, make it true
- In the script set the flag clone-on-cpu=True
I solved the error by uninstalling tensorflow and installing tensorflow-gpu, Note: it works so far with the version 1.4, idk with newer versions
pip uninstall tensorflow pip install --upgrade tensorflow-gpu==1.4