Problem in retraining ssd_mobilenet on my own dataset
Hi, I am trying to retrain 'ssd_mobilenet' on my own dataset. I am using 5 classes. I converted my dataset with annotated bounding boxes to the desired TFRecord format without errors and changed the .config file as well. I then followed 'Running Locally' section and executed: python object_detection/train.py --logtostderr --pipeline_confi g_path=${PATH_TO_YOUR_PIPELINE_CONFIG} --train_dir=${PATH_TO_TRAIN_DIR}
What I observe is that the loss stays constant and it gets killed after 5 steps.
INFO:tensorflow:Recording summary at step 0. INFO:tensorflow:global step 1: loss = 0.3352 (11.099 sec/step) INFO:tensorflow:global step 2: loss = 0.3352 (4.418 sec/step) INFO:tensorflow:global step 3: loss = 0.3352 (5.504 sec/step) INFO:tensorflow:global step 4: loss = 0.3352 (7.470 sec/step) INFO:tensorflow:global step 5: loss = 0.3352 (5.705 sec/step) Killed
Could you please give me some pointers on what I could do in solving this? Thanks, Amit
Hi @agshift - perhaps you could describe your dataset a bit as well as the labelmap that you used?
Hi @jch1,
My dataset looks like this.
My images are high resolution images of one particular type of fruit.
<size>
<width>4032</width>
<height>3024</height>
</size>
I am trying to identify the various defects seen on these fruit images - for example defect1, defect2... etc. I am using bounding boxes to annotate each of these defects inside each of the images. I am showing the annotation for defect1 below in my xml file (two occurences of defect1 in one image as shown below)
<object>
<name>defect1</name>
<bndbox>
<xmin>2554</xmin>
<ymin>496</ymin>
<xmax>2730</xmax>
<ymax>672</ymax>
</bndbox>
</object>
<object>
<name>defect1</name>
<bndbox>
<xmin>1388</xmin>
<ymin>483</ymin>
<xmax>1549</xmax>
<ymax>644</ymax>
</bndbox>
</object>
I created the dataset based on pascal voc 2007 format and am able to generate the TFRecord file. I created equal train/val datasets from all my annotated images
My labelmap looks like this (my_label_map.pbtxt):
item { id: 0 name: 'none_of_the_above' }
item { id: 1 name: 'defect1' }
item { id: 2 name: 'defect2' }
item { id: 3 name: 'defect3' }
item { id: 4 name: 'defect4' }
item { id: 5 name: 'defect5' }
I also changed the config file like this (just highlighting the important ones below): model { ssd { num_classes: 5
train_config: { batch_size: 1
exponential_decay_learning_rate { initial_learning_rate: 0.001 # changed it from 0.004
fine_tune_checkpoint: "/<path_to_my>/ssd_mobilenet_v1_coco_11_06_2017/model.ckpt" from_detection_checkpoint: true
train_input_reader: { tf_record_input_reader { input_path: "/<path_to_my>/my_train.record" } label_map_path: "/<path_to_my>/my_label_map.pbtxt" }
eval_config: { num_examples: 2000 }
eval_input_reader: { tf_record_input_reader { input_path: "/<path_to_my>/my_val.record" } label_map_path: "/<path_to_my>/my_label_map.pbtxt" }
Please let me know what I could do to make this work. Thanks, Amit
Okay the label map looks fine - but the high resolution images are probably killing the memory. You should scale the images down significantly. The SSD model will automatically scale it down to 300x300 anyway --- and ordinarily you wouldn't have to worry about this --- the problem is that we preload a queue of images for speed, but your images are large enough that this isn't working out well.
Hi @jch1, I was thinking that SSD will forcefully downscale the images for me (as you also wrote). But based on your input, it looks like that I need to downscale the images myself for the preloading of the queue to work.
Do you want me to add something like:
def preprocess(self, inputs):
return tf.image.resize_images(inputs, [300, 300])
and call this function from trainer.py from this function: def _create_input_queue(...)
Thanks, Amit
Well there are many ways to do it, but my inclination would be to just resize during the create dataset script that you run. This way your resulting tf record file will be much smaller and it'll also cut down on communication costs if you are training over a network.
Thanks for the suggestion. Will try and let you know how it goes. Thanks, Amit
Resizing before creating a datasset is NOT a good idea in most cases, as most times you want to have different random crops covering different parts of the image at every step. Resizing when creating the dataset defeats the purpose of the random crop (and makes the accuracy for small objects drop significantly).
@jch1 I tried the following modification to do the resizing and then encode back in 'create_pascal_tf_record.py'.
with tf.gfile.GFile(full_path) as fid:
encoded_jpg = fid.read()
encoded_jpg_io = io.BytesIO(encoded_jpg)
# resizing the image here
decoded_image = tf.image.decode_jpeg(encoded_jpg)
decoded_image_resized = tf.image.resize_images(decoded_image, [300, 300]) # this returns float32
decoded_image_resized = tf.cast(decoded_image_resized, tf.uint8)
encoded_jpg = tf.image.encode_jpeg(decoded_image_resized) # expects uint8
encoded_jpg = bytes(encoded_jpg) # I think this may not be the right way of doing this
I was able to generate a highly optimized TFRecord file, but when I ran 'train.py' I get the following assertion failure:
tensorflow.python.framework.errors_impl.InvalidArgumentError: assertion failed: [Unable to decode bytes as JPEG, PNG, or GIF]
I think I am unable to do the encoding properly. Could you please help me on how I can resolve this? I think somehow my bytes() conversion is broken. Thanks, Amit
@jch1 Finally, figured it out... This one helped:
#encoded_jpg = bytes(encoded_jpg) # Commented out this
encoded_jpg = tf.Session().run(encoded_jpg)
The loss also decreased during training. Currently running just 500 steps to do a quick step. Will observe how well it did on the validation dataset. Will update the thread. Thanks, Amit
Hi @jch1, I am trying to run for 4000 steps. The loses went down, but I run into severe problem when I run it using my own dataset.
- The training crashes after 953 steps with NaN in summary histogram as shown below. How do I debug this?
INFO:tensorflow:global step 949: loss = 0.5480 (0.102 sec/step)
INFO:tensorflow:global step 950: loss = 0.4973 (0.102 sec/step)
INFO:tensorflow:global step 951: loss = 1.2043 (0.103 sec/step)
INFO:tensorflow:global step 952: loss = 0.5934 (0.105 sec/step)
INFO:tensorflow:global step 953: loss = 0.7066 (0.100 sec/step)
2017-07-22 09:53:32.871184: W tensorflow/core/framework/op_kernel.cc:1158] Invalid argument: Nan in summary histogram for: FeatureEx
tractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1 = HistogramSumma
ry[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_1
28/BatchNorm/moving_variance_1/tag, FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance
/read)]]
- The loss decreased over the 953 steps (as seen on stdout, though tensorboard tells me a different story), but when I run 'eval.py' it gets stuck for quite some time and then gives me this warning
INFO:tensorflow:Restoring parameters from /tensorflow_models/models/object_detection/models/model/train/model.ckpt-0
INFO:tensorflow:Restoring parameters from /tensorflow_models/models/object_detection/models/model/train/model.ckpt-0
WARNING:root:The following classes have no ground truth examples: 0
/tensorflow_models/models/object_detection/utils/metrics.py:144: RuntimeWarning: invalid value encountered in true_divide
num_images_correctly_detected_per_class / num_gt_imgs_per_class)
- When I run tensorboard, my total_loss graph just shows me only one dot. Theres isn't any graph actually
Any idea on how I can resolve these issues? Thanks, Amit
Thanks to @jch1, When I changed my batch_size from 1 to 24, I was able to get past all those errors mentioned in my earlier comment. Just wanted to record this over here, for the benefit of everyone following this thread.
@jch1 How about the bbox of the labels inside the images? Are they resized accordingly?
Hi all,
I tried retraining ssd_Mobilenet using the python script in tensorflow at tensorflow/examples/image_retrain/retrain.py with architecture as Mobinet as specified in the script. The script ran successfully and the logs showed around 88% accuracy on my custom dataset. But for inferencing using the script at tensorflow/examples/label_image/label_image.py with arguments as the specfied in retraining sample example. But i am getting an error as could not import output final_result:0. But the script is meant for retraining Mobilenet as well. what could be the issue?
thanks and regards
@agshift @jch1 Do you finally know the reason of the error that cause the training stops if the batch_size is 1?
Invalid argument: Nan in summary histogram for: FeatureEx
tractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1 = HistogramSumma
ry[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_1
28/BatchNorm/moving_variance_1/tag, FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance
/read)]]
.
.
**INFO:tensorflow:global step 205: loss = 7.8596 (0.604 sec/step)
INFO:tensorflow:Finished training! Saving model to disk.**
My training stops within the first 300 steps and my total_loss graph just shows one dot in the Tensorboard. Windows 7, 8GB ram, intel i5, Nvidia Quadro K2000, python 3.5, tensorflow 1.3
My cmd shows all this:
2017-09-12 15:15:06.387551: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu
\PY\35\tensorflow\core\framework\op_kernel.cc:1192] Invalid argument: Nan in sum
mary histogram for: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_
3x3_s2_128/BatchNorm/moving_variance_1
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3
_s2_128/BatchNorm/moving_variance_1 = HistogramSummary[T=DT_FLOAT, _device="/job
:localhost/replica:0/task:0/cpu:0"](FeatureExtractor/MobilenetV1/Conv2d_13_point
wise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1/tag, FeatureExtractor/Mob
ilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance/rea
d)]]
2017-09-12 15:15:06.388801: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu
\PY\35\tensorflow\core\framework\op_kernel.cc:1192] Invalid argument: Nan in sum
mary histogram for: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_
3x3_s2_128/BatchNorm/moving_variance_1
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3
_s2_128/BatchNorm/moving_variance_1 = HistogramSummary[T=DT_FLOAT, _device="/job
:localhost/replica:0/task:0/cpu:0"](FeatureExtractor/MobilenetV1/Conv2d_13_point
wise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1/tag, FeatureExtractor/Mob
ilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance/rea
d)]]
2017-09-12 15:15:06.390051: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu
\PY\35\tensorflow\core\framework\op_kernel.cc:1192] Invalid argument: Nan in sum
mary histogram for: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_
3x3_s2_128/BatchNorm/moving_variance_1
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3
_s2_128/BatchNorm/moving_variance_1 = HistogramSummary[T=DT_FLOAT, _device="/job
:localhost/replica:0/task:0/cpu:0"](FeatureExtractor/MobilenetV1/Conv2d_13_point
wise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1/tag, FeatureExtractor/Mob
ilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance/rea
d)]]
2017-09-12 15:15:06.391301: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu
\PY\35\tensorflow\core\framework\op_kernel.cc:1192] Invalid argument: Nan in sum
mary histogram for: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_
3x3_s2_128/BatchNorm/moving_variance_1
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3
_s2_128/BatchNorm/moving_variance_1 = HistogramSummary[T=DT_FLOAT, _device="/job
:localhost/replica:0/task:0/cpu:0"](FeatureExtractor/MobilenetV1/Conv2d_13_point
wise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1/tag, FeatureExtractor/Mob
ilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance/rea
d)]]
2017-09-12 15:15:06.391301: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu
\PY\35\tensorflow\core\framework\op_kernel.cc:1192] Invalid argument: Nan in sum
mary histogram for: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_
3x3_s2_128/BatchNorm/moving_variance_1
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3
_s2_128/BatchNorm/moving_variance_1 = HistogramSummary[T=DT_FLOAT, _device="/job
:localhost/replica:0/task:0/cpu:0"](FeatureExtractor/MobilenetV1/Conv2d_13_point
wise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1/tag, FeatureExtractor/Mob
ilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance/rea
d)]]
2017-09-12 15:15:06.392551: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu
\PY\35\tensorflow\core\framework\op_kernel.cc:1192] Invalid argument: Nan in sum
mary histogram for: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_
3x3_s2_128/BatchNorm/moving_variance_1
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3
_s2_128/BatchNorm/moving_variance_1 = HistogramSummary[T=DT_FLOAT, _device="/job
:localhost/replica:0/task:0/cpu:0"](FeatureExtractor/MobilenetV1/Conv2d_13_point
wise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1/tag, FeatureExtractor/Mob
ilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance/rea
d)]]
2017-09-12 15:15:06.393801: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu
\PY\35\tensorflow\core\framework\op_kernel.cc:1192] Invalid argument: Nan in sum
mary histogram for: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_
3x3_s2_128/BatchNorm/moving_variance_1
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3
_s2_128/BatchNorm/moving_variance_1 = HistogramSummary[T=DT_FLOAT, _device="/job
:localhost/replica:0/task:0/cpu:0"](FeatureExtractor/MobilenetV1/Conv2d_13_point
wise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1/tag, FeatureExtractor/Mob
ilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance/rea
d)]]
2017-09-12 15:15:06.395051: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu
\PY\35\tensorflow\core\framework\op_kernel.cc:1192] Invalid argument: Nan in sum
mary histogram for: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_
3x3_s2_128/BatchNorm/moving_variance_1
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3
_s2_128/BatchNorm/moving_variance_1 = HistogramSummary[T=DT_FLOAT, _device="/job
:localhost/replica:0/task:0/cpu:0"](FeatureExtractor/MobilenetV1/Conv2d_13_point
wise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1/tag, FeatureExtractor/Mob
ilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance/rea
d)]]
2017-09-12 15:15:06.396301: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu
\PY\35\tensorflow\core\framework\op_kernel.cc:1192] Invalid argument: Nan in sum
mary histogram for: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_
3x3_s2_128/BatchNorm/moving_variance_1
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3
_s2_128/BatchNorm/moving_variance_1 = HistogramSummary[T=DT_FLOAT, _device="/job
:localhost/replica:0/task:0/cpu:0"](FeatureExtractor/MobilenetV1/Conv2d_13_point
wise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1/tag, FeatureExtractor/Mob
ilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance/rea
d)]]
INFO:tensorflow:Error reported to Coordinator: <class 'tensorflow.python.framewo
rk.errors_impl.InvalidArgumentError'>, Nan in summary histogram for: FeatureExtr
actor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_var
iance_1
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3
_s2_128/BatchNorm/moving_variance_1 = HistogramSummary[T=DT_FLOAT, _device="/job
:localhost/replica:0/task:0/cpu:0"](FeatureExtractor/MobilenetV1/Conv2d_13_point
wise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1/tag, FeatureExtractor/Mob
ilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance/rea
d)]]
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_3_3x3
_s2_256/weights/read/_557 = _Recv[client_terminated=false, recv_device="/job:loc
alhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/cpu
:0", send_device_incarnation=1, tensor_name="edge_3133_FeatureExtractor/Mobilene
tV1/Conv2d_13_pointwise_2_Conv2d_3_3x3_s2_256/weights/read", tensor_type=DT_FLOA
T, _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
**Caused by op 'FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2
_128/BatchNorm/moving_variance_1', defined at:**
File "train.py", line 198, in <module>
tf.app.run()
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
platform\app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "train.py", line 194, in main
worker_job_name, is_chief, FLAGS.train_dir)
File "C:\Program Files (x86)\Python 3.5.2\Lib\site-packages\tensorflow\models\
object_detection\trainer.py", line 253, in train
global_summaries.add(tf.summary.histogram(model_var.op.name, model_var))
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
summary\summary.py", line 192, in histogram
tag=tag, values=values, name=scope)
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
ops\gen_logging_ops.py", line 129, in _histogram_summary
name=name)
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
framework\op_def_library.py", line 767, in apply_op
op_def=op_def)
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
framework\ops.py", line 2630, in create_op
original_op=self._default_original_op, op_def=op_def)
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
framework\ops.py", line 1204, in __init__
self._traceback = self._graph._extract_stack() # pylint: disable=protected-
access
InvalidArgumentError (see above for traceback): Nan in summary histogram for: Fe
atureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/m
oving_variance_1
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3
_s2_128/BatchNorm/moving_variance_1 = HistogramSummary[T=DT_FLOAT, _device="/job
:localhost/replica:0/task:0/cpu:0"](FeatureExtractor/MobilenetV1/Conv2d_13_point
wise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1/tag, FeatureExtractor/Mob
ilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance/rea
d)]]
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_3_3x3
_s2_256/weights/read/_557 = _Recv[client_terminated=false, recv_device="/job:loc
alhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/cpu
:0", send_device_incarnation=1, tensor_name="edge_3133_FeatureExtractor/Mobilene
tV1/Conv2d_13_pointwise_2_Conv2d_3_3x3_s2_256/weights/read", tensor_type=DT_FLOA
T, _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
**INFO:tensorflow:global step 205: loss = 7.8596 (0.604 sec/step)
INFO:tensorflow:Finished training! Saving model to disk.**
Traceback (most recent call last):
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
client\session.py", line 1327, in _do_call
return fn(*args)
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
client\session.py", line 1306, in _run_fn
status, run_metadata)
File "C:\Program Files (x86)\Python 3.5.2\lib\contextlib.py", line 66, in __ex
it__
next(self.gen)
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
framework\errors_impl.py", line 466, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Nan in summary his
togram for: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_1
28/BatchNorm/moving_variance_1
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3
_s2_128/BatchNorm/moving_variance_1 = HistogramSummary[T=DT_FLOAT, _device="/job
:localhost/replica:0/task:0/cpu:0"](FeatureExtractor/MobilenetV1/Conv2d_13_point
wise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1/tag, FeatureExtractor/Mob
ilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance/rea
d)]]
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_3_3x3
_s2_256/weights/read/_557 = _Recv[client_terminated=false, recv_device="/job:loc
alhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/cpu
:0", send_device_incarnation=1, tensor_name="edge_3133_FeatureExtractor/Mobilene
tV1/Conv2d_13_pointwise_2_Conv2d_3_3x3_s2_256/weights/read", tensor_type=DT_FLOA
T, _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "train.py", line 198, in <module>
tf.app.run()
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
platform\app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "train.py", line 194, in main
worker_job_name, is_chief, FLAGS.train_dir)
File "C:\Program Files (x86)\Python 3.5.2\Lib\site-packages\tensorflow\models\
object_detection\trainer.py", line 290, in train
saver=saver)
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\contrib
\slim\python\slim\learning.py", line 767, in train
sv.stop(threads, close_summary_writer=True)
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
training\supervisor.py", line 792, in stop
stop_grace_period_secs=self._stop_grace_secs)
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
training\coordinator.py", line 389, in join
six.reraise(*self._exc_info_to_raise)
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\six.py", line 686,
in reraise
raise value
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
training\coordinator.py", line 296, in stop_on_exception
yield
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
training\coordinator.py", line 494, in run
self.run_loop()
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
training\supervisor.py", line 994, in run_loop
self._sv.global_step])
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
client\session.py", line 895, in run
run_metadata_ptr)
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
client\session.py", line 1124, in _run
feed_dict_tensor, options, run_metadata)
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
client\session.py", line 1321, in _do_run
options, run_metadata)
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
client\session.py", line 1340, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Nan in summary his
togram for: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_1
28/BatchNorm/moving_variance_1
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3
_s2_128/BatchNorm/moving_variance_1 = HistogramSummary[T=DT_FLOAT, _device="/job
:localhost/replica:0/task:0/cpu:0"](FeatureExtractor/MobilenetV1/Conv2d_13_point
wise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1/tag, FeatureExtractor/Mob
ilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance/rea
d)]]
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_3_3x3
_s2_256/weights/read/_557 = _Recv[client_terminated=false, recv_device="/job:loc
alhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/cpu
:0", send_device_incarnation=1, tensor_name="edge_3133_FeatureExtractor/Mobilene
tV1/Conv2d_13_pointwise_2_Conv2d_3_3x3_s2_256/weights/read", tensor_type=DT_FLOA
T, _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
Caused by op 'FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2
_128/BatchNorm/moving_variance_1', defined at:
File "train.py", line 198, in <module>
tf.app.run()
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
platform\app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "train.py", line 194, in main
worker_job_name, is_chief, FLAGS.train_dir)
File "C:\Program Files (x86)\Python 3.5.2\Lib\site-packages\tensorflow\models\
object_detection\trainer.py", line 253, in train
global_summaries.add(tf.summary.histogram(model_var.op.name, model_var))
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
summary\summary.py", line 192, in histogram
tag=tag, values=values, name=scope)
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
ops\gen_logging_ops.py", line 129, in _histogram_summary
name=name)
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
framework\op_def_library.py", line 767, in apply_op
op_def=op_def)
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
framework\ops.py", line 2630, in create_op
original_op=self._default_original_op, op_def=op_def)
File "C:\Program Files (x86)\Python 3.5.2\lib\site-packages\tensorflow\python\
framework\ops.py", line 1204, in __init__
self._traceback = self._graph._extract_stack() # pylint: disable=protected-
access
InvalidArgumentError (see above for traceback): Nan in summary histogram for: Fe
atureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/m
oving_variance_1
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3
_s2_128/BatchNorm/moving_variance_1 = HistogramSummary[T=DT_FLOAT, _device="/job
:localhost/replica:0/task:0/cpu:0"](FeatureExtractor/MobilenetV1/Conv2d_13_point
wise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance_1/tag, FeatureExtractor/Mob
ilenetV1/Conv2d_13_pointwise_2_Conv2d_5_3x3_s2_128/BatchNorm/moving_variance/rea
d)]]
[[Node: FeatureExtractor/MobilenetV1/Conv2d_13_pointwise_2_Conv2d_3_3x3
_s2_256/weights/read/_557 = _Recv[client_terminated=false, recv_device="/job:loc
alhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/cpu
:0", send_device_incarnation=1, tensor_name="edge_3133_FeatureExtractor/Mobilene
tV1/Conv2d_13_pointwise_2_Conv2d_3_3x3_s2_256/weights/read", tensor_type=DT_FLOA
T, _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
@agshift @jch1 I am very new to tensorflow, would appreciate your help..
System Specs: Ubuntu 16.04 (Python 2.7), using tf-nightly 1.5.0 for py2.7 (#2653 suggests the use of tf-nightly), performing on cpu since I do not have a good gpu.
I have my own dataset with 2 classes (628 images in total) and high res images (1920,1080) I have xml annotations similar to that of yours, where there are two or more instances a.k.a <object> in a single image.. But when I train (using train.py in /models/research/object_detection), I get an error saying
InvalidArgumentError (see above for traceback): assertion failed: [Groundtruth boxes and labels have incompatible shapes!] [Condition x == y did not hold element-wise:] [x (Loss/BoxClassifierLoss/strided_slice_1:0) = ]'
I managed to generate the tfrecord files using tf_convert_data.py present here https://github.com/balancap/SSD-Tensorflow/tree/master/ since create_pet_tf_records.py throws these errors below:
Traceback (most recent call last):
File "object_detection/create_pet_tf_record.py", line 215, in <module>
tf.app.run()
File "/home/srinath/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "object_detection/create_pet_tf_record.py", line 210, in main
image_dir, train_examples)
File "object_detection/create_pet_tf_record.py", line 179, in create_tf_record
tf_example = dict_to_tf_example(data, label_map_dict, image_dir)
File "object_detection/create_pet_tf_record.py", line 122, in dict_to_tf_example
class_name = get_class_name_from_filename(data['filename'])
File "object_detection/create_pet_tf_record.py", line 63, in get_class_name_from_filename
return match.groups()[0]
AttributeError: 'NoneType' object has no attribute 'groups'
What am I doing wrong? I tried looking up but I couldn't find a useful resource related to the above issue :(
I would be glad if you guys can help me with a workaround. Thanks in Advance.
(tensorflow) C:\Users\Lenovo\tensorflow\model>python object_detection/dataset_tools/create_pet_tf_record.py
C:\Users\Lenovo\tensorflow\model\object_detection\utils\dataset_util.py:75: FutureWarning: The behavior of this method will change in future versions. Use specific 'len(elem)' or 'elem is not None' test instead.
if not xml:
Traceback (most recent call last):
File "object_detection/dataset_tools/create_pet_tf_record.py", line 208, in
can any one help me for this problem code:
Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================
r"""Convert the Oxford pet dataset to TFRecord for object_detection.
See: O. M. Parkhi, A. Vedaldi, A. Zisserman, C. V. Jawahar
Cats and Dogs
IEEE Conference on Computer Vision and Pattern Recognition, 2012
http://www.robots.ox.ac.uk/~vgg/data/pets/
Example usage:
./create_pet_tf_record --data_dir=/home/user/pet
--output_dir=/home/user/pet/output
"""
import sys sys.path.append('C:/Users/Lenovo/tensorflow/model') # point to your tensorflow dir sys.path.append('C:/Users/Lenovo/tensorflow/model/slim') # point ot your slim dir
import hashlib import io import logging import os import random import re
from lxml import etree import PIL.Image import tensorflow as tf
from object_detection.utils import dataset_util from object_detection.utils import label_map_util
flags = tf.app.flags flags.DEFINE_string('data_dir', '', 'Root directory to raw pet dataset.') flags.DEFINE_string('output_dir', '', 'Path to directory to output TFRecords.') flags.DEFINE_string('label_map_path', 'tf_files/label_map.pbtxt', 'Path to label map proto') FLAGS = flags.FLAGS
def get_class_name_from_filename(file_name): """Gets the class name from a file. Args: file_name: The file name to get the class name from. ie. "american_pit_bull_terrier_105.jpg" Returns: A string of the class name. """ match = re.match(r'([A-Za-z_]+)(_[0-9]+.jpg)', file_name, re.I) return match.groups()[0]
def dict_to_tf_example(data, label_map_dict, image_subdirectory, ignore_difficult_instances=False): """Convert XML derived dict to tf.Example proto. Notice that this function normalizes the bounding box coordinates provided by the raw data. Args: data: dict holding PASCAL XML fields for a single image (obtained by running dataset_util.recursive_parse_xml_to_dict) label_map_dict: A map from string label names to integers ids. image_subdirectory: String specifying subdirectory within the Pascal dataset directory holding the actual image data. ignore_difficult_instances: Whether to skip difficult instances in the dataset (default: False). Returns: example: The converted tf.Example. Raises: ValueError: if the image pointed to by data['filename'] is not a valid JPEG """ img_path = os.path.join(image_subdirectory, data['filename']) with tf.gfile.GFile(img_path, 'rb') as fid: encoded_jpg = fid.read() encoded_jpg_io = io.BytesIO(encoded_jpg) image = PIL.Image.open(encoded_jpg_io) if image.format != 'JPEG': raise ValueError('Image format not JPEG') key = hashlib.sha256(encoded_jpg).hexdigest()
width = int(data['size']['width']) height = int(data['size']['height'])
xmin = [] ymin = [] xmax = [] ymax = [] classes = [] classes_text = [] truncated = [] poses = [] difficult_obj = [] for obj in data['object']: difficult = bool(int(obj['difficult'])) if ignore_difficult_instances and difficult: continue
difficult_obj.append(int(difficult))
xmin.append(float(obj['bndbox']['xmin']) / width)
ymin.append(float(obj['bndbox']['ymin']) / height)
xmax.append(float(obj['bndbox']['xmax']) / width)
ymax.append(float(obj['bndbox']['ymax']) / height)
class_name = get_class_name_from_filename(data['filename'])
classes_text.append(class_name.encode('utf8'))
classes.append(label_map_dict[class_name])
truncated.append(int(obj['truncated']))
poses.append(obj['pose'].encode('utf8'))
example = tf.train.Example(features=tf.train.Features(feature={ 'image/height': dataset_util.int64_feature(height), 'image/width': dataset_util.int64_feature(width), 'image/filename': dataset_util.bytes_feature( data['filename'].encode('utf8')), 'image/source_id': dataset_util.bytes_feature( data['filename'].encode('utf8')), 'image/key/sha256': dataset_util.bytes_feature(key.encode('utf8')), 'image/encoded': dataset_util.bytes_feature(encoded_jpg), 'image/format': dataset_util.bytes_feature('jpeg'.encode('utf8')), 'image/object/bbox/xmin': dataset_util.float_list_feature(xmin), 'image/object/bbox/xmax': dataset_util.float_list_feature(xmax), 'image/object/bbox/ymin': dataset_util.float_list_feature(ymin), 'image/object/bbox/ymax': dataset_util.float_list_feature(ymax), 'image/object/class/text': dataset_util.bytes_list_feature(classes_text), 'image/object/class/label': dataset_util.int64_list_feature(classes), 'image/object/difficult': dataset_util.int64_list_feature(difficult_obj), 'image/object/truncated': dataset_util.int64_list_feature(truncated), 'image/object/view': dataset_util.bytes_list_feature(poses), })) return example
def create_tf_record(output_filename, label_map_dict, annotations_dir, image_dir, examples): """Creates a TFRecord file from examples. Args: output_filename: Path to where output file is saved. label_map_dict: The label map dictionary. annotations_dir: Directory where annotation files are stored. image_dir: Directory where image files are stored. examples: Examples to parse and save to tf record. """ writer = tf.python_io.TFRecordWriter(output_filename) for idx, example in enumerate(examples): if idx % 100 == 0: logging.info('On image %d of %d', idx, len(examples)) path = os.path.join(annotations_dir, 'xmls', example + '.xml')
if not os.path.exists(path):
logging.warning('Could not find %s, ignoring example.', path)
continue
with tf.gfile.GFile(path, 'r') as fid:
xml_str = fid.read()
xml = etree.fromstring(xml_str)
data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation']
tf_example = dict_to_tf_example(data, label_map_dict, image_dir)
writer.write(tf_example.SerializeToString())
writer.close()
TODO: Add test for pet/PASCAL main files.
def main(_): data_dir = FLAGS.data_dir label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path)
logging.info('Reading from Pet dataset.') image_dir = os.path.join(data_dir, 'images') annotations_dir = os.path.join(data_dir, 'annotations') examples_path = os.path.join(annotations_dir, 'trainval.txt') examples_list = dataset_util.read_examples_list(examples_path)
Test images are not included in the downloaded data set, so we shall perform
our own split.
random.seed(42) random.shuffle(examples_list) num_examples = len(examples_list) num_train = int(0.7 * num_examples) train_examples = examples_list[:num_train] val_examples = examples_list[num_train:] logging.info('%d training and %d validation examples.', len(train_examples), len(val_examples))
train_output_path = os.path.join(FLAGS.output_dir, 'pet_train.record') val_output_path = os.path.join(FLAGS.output_dir, 'pet_val.record') create_tf_record(train_output_path, label_map_dict, annotations_dir, image_dir, train_examples) create_tf_record(val_output_path, label_map_dict, annotations_dir, image_dir, val_examples)
if name == 'main': tf.app.run()
@sxr3455 I encontered same problem, and have resolve it by processing my data. The reason may be you have two objects but you record it as one.
Hi There, We are checking to see if you still need help on this, as this seems to be considerably old issue. Please update this issue with the latest information, code snippet to reproduce your issue and error you are seeing. If we don't hear from you in the next 7 days, this issue will be closed automatically. If you don't need help on this issue any more, please consider closing this.