LSTM Object Detection Model Does Not Run
System information
- What is the top-level directory of the model you are using: lstm_object_detection
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Trying to
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
- TensorFlow installed from (source or binary): source
- TensorFlow version (use command below): 1.12.0
- Bazel version (if compiling from source):
- CUDA/cuDNN version: 9.0
- GPU model and memory: GTX 1070 ti
- Exact command to reproduce: python train.py --train_dir=training --pipeline_config_path=configs/lstm_ssd_mobilenet_v1_imagenet.config
Describe the problem
Training the LSTM object detection model does not work. After making a tfrecord, modifying the config as necessary, creating a training dir, and running the command, I get this error:
tensorflow.python.framework.errors_impl.InvalidArgumentError: Tried to explicitly squeeze dimension 0 but dimension was not 1: 0
[[Node: Squeeze_1 = Squeeze[T=DT_INT64, squeeze_dims=[0], _device="/job:localhost/replica:0/task:0/device:CPU:0"](split_2)]]
More documentation, including a simple example file of how to make a tfrecord and train, would be very helpful. I have tried two ways to create a tfrecord, both of which are shown below. I thought maybe the record structure is wrong, but if I put a typo in the record keys, I get a different error complaining about that, so perhaps I structured the records correctly. I tried looking at the model in tensorboard and modifying the training code in slim/learning.py to fetch values from individual nodes near Squeeze_1. I print the node, the output, and the shape of the output. Here are results from these attempts:
try run: split_1:0
Tensor("split_1:0", shape=(?, ?, 4), dtype=float32, device=/device:CPU:0)
value: []
size: (0, 0, 4)
try run: ParseSingleSequenceExample/ParseSingleSequenceExample:0
Tensor("ParseSingleSequenceExample/ParseSingleSequenceExample:0", shape=(), dtype=string, device=/device:CPU:0)
value: b''
size: ()
try run: ResizeImage/resize_images/ResizeBilinear:0
Tensor("ResizeImage/resize_images/ResizeBilinear:0", shape=(4, 256, 256, 3), dtype=float32, device=/device:CPU:0)
value: (big numpy array)
size: (4, 256, 256, 3)
It seems that split_1 and ParseSingleSequenceExample are not actually receiving any data, and thus cause this squeeze error since there is nothing to squeeze. But resize image still gets data. Additionally, if I ONLY fetch ResizeImage/resize_images/ResizeBilinear:0, I can fetch it a couple of times (repeatedly fetching in a loop), and then it fails. Perhaps the model fails after one batch?
I'm not sure if this counts a duplicate, but here are some related threads: https://github.com/tensorflow/models/issues/6027 https://github.com/tensorflow/models/issues/5869 https://stackoverflow.com/questions/54093931/lstm-object-detection-tensorflow
I've also emailed the authors and heard nothing back.
EDIT:
I should mention, I removed ssd_random_crop from data augmentation options in the config because it was giving me an error "the function ssd_random_crop requires argument groundtruth_weights" Not sure if this would matter at all
Source code / logs
I tried two ways of creating tfrecords. The first was taken from tf_sequence_example_decoder_test.py, in this repo. The only change was swapping to sequences of length 4 to match the config file.
writer = tf.python_io.TFRecordWriter(path)
with tf.Session() as sess:
for _ in range(2000):
image_tensor = np.random.randint(255, size=(16, 16, 3)).astype(np.uint8)
print(image_tensor)
encoded_jpeg = tf.image.encode_jpeg(tf.constant(image_tensor)).eval()
sequence_example = example_pb2.SequenceExample(
context=feature_pb2.Features(
feature={
'image/format':
feature_pb2.Feature(
bytes_list=feature_pb2.BytesList(
value=['jpeg'.encode('utf-8')])),
'image/height':
feature_pb2.Feature(
int64_list=feature_pb2.Int64List(value=[16])),
'image/width':
feature_pb2.Feature(
int64_list=feature_pb2.Int64List(value=[16])),
}),
feature_lists=feature_pb2.FeatureLists(
feature_list={
'image/encoded':
feature_pb2.FeatureList(feature=[
feature_pb2.Feature(
bytes_list=feature_pb2.BytesList(
value=[encoded_jpeg])), feature_pb2.Feature(
bytes_list=feature_pb2.BytesList(
value=[encoded_jpeg])), feature_pb2.Feature(
bytes_list=feature_pb2.BytesList(
value=[encoded_jpeg])), feature_pb2.Feature(
bytes_list=feature_pb2.BytesList(
value=[encoded_jpeg]))
]),
'image/object/bbox/xmin':
feature_pb2.FeatureList(feature=[
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[0.0])),
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[0.0])),
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[0.0])),
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[0.0]))
]),
'image/object/bbox/xmax':
feature_pb2.FeatureList(feature=[
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[1.0])),
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[1.0])),
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[1.0])),
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[1.0]))
]),
'image/object/bbox/ymin':
feature_pb2.FeatureList(feature=[
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[0.0])),
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[0.0])),
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[0.0])),
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[0.0]))
]),
'image/object/bbox/ymax':
feature_pb2.FeatureList(feature=[
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[1.0])),
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[1.0])),
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[1.0])),
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[1.0]))
]),
'image/object/class/label':
feature_pb2.FeatureList(feature=[
feature_pb2.Feature(
int64_list=feature_pb2.Int64List(value=[1])),
feature_pb2.Feature(
int64_list=feature_pb2.Int64List(value=[1])),
feature_pb2.Feature(
int64_list=feature_pb2.Int64List(value=[1])),
feature_pb2.Feature(
int64_list=feature_pb2.Int64List(value=[1]))
]),
}))
writer.write(sequence_example.SerializeToString())
writer.close()
I also tried adapting a method I found here: https://github.com/wakanda-ai/tf-detectors For this I used a couple sample xml files in PASCAL VOC format from a training set I have for one of the normal object_detection models.
# Iterate frames
for data, img_path in zip(dicts, imgs_path):
## open single frame
with tf.gfile.FastGFile(img_path, 'rb') as fid:
encoded_jpg = fid.read()
encoded_jpg_io = io.BytesIO(encoded_jpg)
image = Image.open(encoded_jpg_io)
if image.format != 'JPEG':
raise ValueError('Image format not JPEG')
key = hashlib.sha256(encoded_jpg).hexdigest()
## validation
assert int(data['size']['height']) == height
assert int(data['size']['width']) == width
## iterate objects
xmin, ymin = [], []
xmax, ymax = [], []
name = []
classval = []
occluded = []
generated = []
if 'object' in data:
for obj in data['object']:
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)
name.append(obj['name'].encode('utf8'))
classval.append(1)
occluded.append(0)
generated.append(0)
else:
xmin.append(float(-1))
ymin.append(float(-1))
xmax.append(float(-1))
ymax.append(float(-1))
name.append('NoObject'.encode('utf8'))
classval.append(1)
occluded.append(0)
generated.append(0)
## append tf_feature to list
filenames.append(dataset_util.bytes_feature(data['filename'].encode('utf8')))
encodeds.append(dataset_util.bytes_feature(encoded_jpg))
sources.append(dataset_util.bytes_feature(data['source']['database'].encode('utf8')))
keys.append(dataset_util.bytes_feature(key.encode('utf8')))
formats.append(dataset_util.bytes_feature('jpeg'.encode('utf8')))
xmins.append(dataset_util.float_list_feature(xmin))
ymins.append(dataset_util.float_list_feature(ymin))
xmaxs.append(dataset_util.float_list_feature(xmax))
ymaxs.append(dataset_util.float_list_feature(ymax))
names.append(dataset_util.bytes_list_feature(name))
occludeds.append(dataset_util.int64_list_feature(occluded))
generateds.append(dataset_util.int64_list_feature(generated))
class_labels.append(dataset_util.int64_list_feature(classval))
# Non sequential features
context = tf.train.Features(feature={
'video/folder': dataset_util.bytes_feature(folder.encode('utf8')),
'video/frame_number': dataset_util.int64_feature(len(imgs_path)),
'video/height': dataset_util.int64_feature(height),
'video/width': dataset_util.int64_feature(width),
})
# Sequential features
tf_feature_lists = {
'image/filename': tf.train.FeatureList(feature=filenames),
'image/encoded': tf.train.FeatureList(feature=encodeds),
'image/sources': tf.train.FeatureList(feature=sources),
'image/key/sha256': tf.train.FeatureList(feature=keys),
'image/format': tf.train.FeatureList(feature=formats),
'image/object/bbox/xmin': tf.train.FeatureList(feature=xmins),
'image/object/bbox/xmax': tf.train.FeatureList(feature=xmaxs),
'image/object/bbox/ymin': tf.train.FeatureList(feature=ymins),
'image/object/bbox/ymax': tf.train.FeatureList(feature=ymaxs),
'image/object/class/text': tf.train.FeatureList(feature=names),
'image/object/class/label': tf.train.FeatureList(feature=class_labels),
'image/object/occluded': tf.train.FeatureList(feature=occludeds),
'image/object/generated': tf.train.FeatureList(feature=generateds),
}
feature_lists = tf.train.FeatureLists(feature_list=tf_feature_lists)
# Make single sequence example
tf_example = tf.train.SequenceExample(context=context, feature_lists=feature_lists)
return tf_example
Tfrecords created with both of these approaches yielded identical errors.
I‘ve met the same "squeeze" issue with @wrkgm .
I tried to comment the data augmentation options in config:
# data_augmentation_options {
# random_horizontal_flip {
# }
# }
# data_augmentation_options {
# ssd_random_crop {
# groundtruth_weights: 1.0
# }
# }
then meet the error:
root@747-Super-Server:~/tensorflow/models/research# python lstm_object_detection/train.py --train_dir=/home1/lstmDetection/model --pipeline_config_path=lstm_object_detection/configs/lstm_ssd_mobilenet_v1_imagenet.config
.....
tensorflow.python.framework.errors_impl.InvalidArgumentError: assertion failed: [All sequence lengths must match, but received lengths: 0 All sequence lengths must match, but received lengths: 0 All sequence lengths must match, but received lengths: 1]
[[Node: batch_sequences_with_states/Assert_2/Assert = Assert[T=[DT_STRING], summarize=3, _device="/job:localhost/replica:0/task:0/device:CPU:0"](batch_sequences_with_states/Equal_2, batch_sequences_with_states/StringJoin)]]
System information
- What is the top-level directory of the model you are using: lstm_object_detection
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Trying to
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
- TensorFlow installed from (source or binary): source
- TensorFlow version (use command below): 1.12.0
- Bazel version (if compiling from source):
- CUDA/cuDNN version: 9.0
- GPU model and memory: GTX 1070 ti
- Exact command to reproduce: python train.py --train_dir=training --pipeline_config_path=configs/lstm_ssd_mobilenet_v1_imagenet.config
Describe the problem
Training the LSTM object detection model does not work. After making a tfrecord, modifying the config as necessary, creating a training dir, and running the command, I get this error:
tensorflow.python.framework.errors_impl.InvalidArgumentError: Tried to explicitly squeeze dimension 0 but dimension was not 1: 0 [[Node: Squeeze_1 = Squeeze[T=DT_INT64, squeeze_dims=[0], _device="/job:localhost/replica:0/task:0/device:CPU:0"](split_2)]]More documentation, including a simple example file of how to make a tfrecord and train, would be very helpful. I have tried two ways to create a tfrecord, both of which are shown below. I thought maybe the record structure is wrong, but if I put a typo in the record keys, I get a different error complaining about that, so perhaps I structured the records correctly. I tried looking at the model in tensorboard and modifying the training code in slim/learning.py to fetch values from individual nodes near Squeeze_1. I print the node, the output, and the shape of the output. Here are results from these attempts:
try run: split_1:0 Tensor("split_1:0", shape=(?, ?, 4), dtype=float32, device=/device:CPU:0) value: [] size: (0, 0, 4) try run: ParseSingleSequenceExample/ParseSingleSequenceExample:0 Tensor("ParseSingleSequenceExample/ParseSingleSequenceExample:0", shape=(), dtype=string, device=/device:CPU:0) value: b'' size: () try run: ResizeImage/resize_images/ResizeBilinear:0 Tensor("ResizeImage/resize_images/ResizeBilinear:0", shape=(4, 256, 256, 3), dtype=float32, device=/device:CPU:0) value: (big numpy array) size: (4, 256, 256, 3)It seems that split_1 and ParseSingleSequenceExample are not actually receiving any data, and thus cause this squeeze error since there is nothing to squeeze. But resize image still gets data. Additionally, if I ONLY fetch ResizeImage/resize_images/ResizeBilinear:0, I can fetch it a couple of times (repeatedly fetching in a loop), and then it fails. Perhaps the model fails after one batch?
I'm not sure if this counts a duplicate, but here are some related threads: #6027 #5869 https://stackoverflow.com/questions/54093931/lstm-object-detection-tensorflow
I've also emailed the authors and heard nothing back.
Source code / logs
I tried two ways of creating tfrecords. The first was taken from tf_sequence_example_decoder_test.py, in this repo. The only change was swapping to sequences of length 4 to match the config file.
writer = tf.python_io.TFRecordWriter(path) with tf.Session() as sess: for _ in range(2000): image_tensor = np.random.randint(255, size=(16, 16, 3)).astype(np.uint8) print(image_tensor) encoded_jpeg = tf.image.encode_jpeg(tf.constant(image_tensor)).eval() sequence_example = example_pb2.SequenceExample( context=feature_pb2.Features( feature={ 'image/format': feature_pb2.Feature( bytes_list=feature_pb2.BytesList( value=['jpeg'.encode('utf-8')])), 'image/height': feature_pb2.Feature( int64_list=feature_pb2.Int64List(value=[16])), 'image/width': feature_pb2.Feature( int64_list=feature_pb2.Int64List(value=[16])), }), feature_lists=feature_pb2.FeatureLists( feature_list={ 'image/encoded': feature_pb2.FeatureList(feature=[ feature_pb2.Feature( bytes_list=feature_pb2.BytesList( value=[encoded_jpeg])), feature_pb2.Feature( bytes_list=feature_pb2.BytesList( value=[encoded_jpeg])), feature_pb2.Feature( bytes_list=feature_pb2.BytesList( value=[encoded_jpeg])), feature_pb2.Feature( bytes_list=feature_pb2.BytesList( value=[encoded_jpeg])) ]), 'image/object/bbox/xmin': feature_pb2.FeatureList(feature=[ feature_pb2.Feature( float_list=feature_pb2.FloatList(value=[0.0])), feature_pb2.Feature( float_list=feature_pb2.FloatList(value=[0.0])), feature_pb2.Feature( float_list=feature_pb2.FloatList(value=[0.0])), feature_pb2.Feature( float_list=feature_pb2.FloatList(value=[0.0])) ]), 'image/object/bbox/xmax': feature_pb2.FeatureList(feature=[ feature_pb2.Feature( float_list=feature_pb2.FloatList(value=[1.0])), feature_pb2.Feature( float_list=feature_pb2.FloatList(value=[1.0])), feature_pb2.Feature( float_list=feature_pb2.FloatList(value=[1.0])), feature_pb2.Feature( float_list=feature_pb2.FloatList(value=[1.0])) ]), 'image/object/bbox/ymin': feature_pb2.FeatureList(feature=[ feature_pb2.Feature( float_list=feature_pb2.FloatList(value=[0.0])), feature_pb2.Feature( float_list=feature_pb2.FloatList(value=[0.0])), feature_pb2.Feature( float_list=feature_pb2.FloatList(value=[0.0])), feature_pb2.Feature( float_list=feature_pb2.FloatList(value=[0.0])) ]), 'image/object/bbox/ymax': feature_pb2.FeatureList(feature=[ feature_pb2.Feature( float_list=feature_pb2.FloatList(value=[1.0])), feature_pb2.Feature( float_list=feature_pb2.FloatList(value=[1.0])), feature_pb2.Feature( float_list=feature_pb2.FloatList(value=[1.0])), feature_pb2.Feature( float_list=feature_pb2.FloatList(value=[1.0])) ]), 'image/object/class/label': feature_pb2.FeatureList(feature=[ feature_pb2.Feature( int64_list=feature_pb2.Int64List(value=[1])), feature_pb2.Feature( int64_list=feature_pb2.Int64List(value=[1])), feature_pb2.Feature( int64_list=feature_pb2.Int64List(value=[1])), feature_pb2.Feature( int64_list=feature_pb2.Int64List(value=[1])) ]), })) writer.write(sequence_example.SerializeToString()) writer.close()I also tried adapting a method I found here: https://github.com/wakanda-ai/tf-detectors For this I used a couple sample xml files in PASCAL VOC format from a training set I have for one of the normal object_detection models.
# Iterate frames for data, img_path in zip(dicts, imgs_path): ## open single frame with tf.gfile.FastGFile(img_path, 'rb') as fid: encoded_jpg = fid.read() encoded_jpg_io = io.BytesIO(encoded_jpg) image = Image.open(encoded_jpg_io) if image.format != 'JPEG': raise ValueError('Image format not JPEG') key = hashlib.sha256(encoded_jpg).hexdigest() ## validation assert int(data['size']['height']) == height assert int(data['size']['width']) == width ## iterate objects xmin, ymin = [], [] xmax, ymax = [], [] name = [] classval = [] occluded = [] generated = [] if 'object' in data: for obj in data['object']: 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) name.append(obj['name'].encode('utf8')) classval.append(1) occluded.append(0) generated.append(0) else: xmin.append(float(-1)) ymin.append(float(-1)) xmax.append(float(-1)) ymax.append(float(-1)) name.append('NoObject'.encode('utf8')) classval.append(1) occluded.append(0) generated.append(0) ## append tf_feature to list filenames.append(dataset_util.bytes_feature(data['filename'].encode('utf8'))) encodeds.append(dataset_util.bytes_feature(encoded_jpg)) sources.append(dataset_util.bytes_feature(data['source']['database'].encode('utf8'))) keys.append(dataset_util.bytes_feature(key.encode('utf8'))) formats.append(dataset_util.bytes_feature('jpeg'.encode('utf8'))) xmins.append(dataset_util.float_list_feature(xmin)) ymins.append(dataset_util.float_list_feature(ymin)) xmaxs.append(dataset_util.float_list_feature(xmax)) ymaxs.append(dataset_util.float_list_feature(ymax)) names.append(dataset_util.bytes_list_feature(name)) occludeds.append(dataset_util.int64_list_feature(occluded)) generateds.append(dataset_util.int64_list_feature(generated)) class_labels.append(dataset_util.int64_list_feature(classval)) # Non sequential features context = tf.train.Features(feature={ 'video/folder': dataset_util.bytes_feature(folder.encode('utf8')), 'video/frame_number': dataset_util.int64_feature(len(imgs_path)), 'video/height': dataset_util.int64_feature(height), 'video/width': dataset_util.int64_feature(width), }) # Sequential features tf_feature_lists = { 'image/filename': tf.train.FeatureList(feature=filenames), 'image/encoded': tf.train.FeatureList(feature=encodeds), 'image/sources': tf.train.FeatureList(feature=sources), 'image/key/sha256': tf.train.FeatureList(feature=keys), 'image/format': tf.train.FeatureList(feature=formats), 'image/object/bbox/xmin': tf.train.FeatureList(feature=xmins), 'image/object/bbox/xmax': tf.train.FeatureList(feature=xmaxs), 'image/object/bbox/ymin': tf.train.FeatureList(feature=ymins), 'image/object/bbox/ymax': tf.train.FeatureList(feature=ymaxs), 'image/object/class/text': tf.train.FeatureList(feature=names), 'image/object/class/label': tf.train.FeatureList(feature=class_labels), 'image/object/occluded': tf.train.FeatureList(feature=occludeds), 'image/object/generated': tf.train.FeatureList(feature=generateds), } feature_lists = tf.train.FeatureLists(feature_list=tf_feature_lists) # Make single sequence example tf_example = tf.train.SequenceExample(context=context, feature_lists=feature_lists) return tf_exampleTfrecords created with both of these approaches yielded identical errors.
@wrkgm I used this code to convert ImageNet VID 2015 to tfrecord, but get a different error:
tensorflow.python.framework.errors_impl.InvalidArgumentError: Can not squeeze dim[0], expected a dimension of 1, got 0
[[{{node Squeeze_1}} = Squeeze[T=DT_INT64, squeeze_dims=[0], _device="/job:localhost/replica:0/task:0/device:CPU:0"](split_2)]]
One important point, I also faced an error saying:
"the function ssd_random_crop requires argument groundtruth_weights"
I fixed it by adding the "groundtruth_weights" and putting it equal to "None".
Did you face the similar error? I thought that the current error might relate to it.
@ashkanee Good point! I forgot I did face this error as well. I simply removed ssd_random_crop entirely from data augmentation options. Will edit main post to mention this, thanks
@ashkanee Good point! I forgot I did face this error as well. I simply removed ssd_random_crop entirely from data augmentation options. Will edit main post to mention this, thanks
I added the groundtruth_weights for ssd_random_crop and fixed the bug, but got the same error as you. Based on this, I guess that may not be the source of the problem.
@dreamdragon Also, one more observation:
1- If I use the check point, I get the following error:
tensorflow.python.framework.errors_impl.InvalidArgumentError: Number of ways to split should evenly divide the split dimension, but got split_dim 0 (size = 10) and num_split 4
[[{{node split}} = Split[T=DT_UINT8, num_split=4, _device="/job:localhost/replica:0/task:0/device:CPU:0"](batch_sequences_with_states/InputQueueingStateSaver/ExpandDims_1/dim, map/TensorArrayStack/TensorArrayGatherV3)]]
which seems that relates to GPU issues.
2- If I do not use the check point, I get the similar error as @wrkgm :
tensorflow.python.framework.errors_impl.InvalidArgumentError: Can not squeeze dim[0], expected a dimension of 1, got 0
[[{{node Squeeze_1}} = Squeeze[T=DT_INT64, squeeze_dims=[0], _device="/job:localhost/replica:0/task:0/device:CPU:0"](split_2)]]
Based on the above, it seems your issue relates to the missing check point.
Important point: Do you get warning on deprecated functions? I get them. May be the error is caused by deprecated functions in TensorFlow. This is probably worth working on.
@wrkgm Can I ask you the following:
1- Can you please check what happens if you add the check point? I use the check point weights here
2- Is it possible for you to explain how you used "tf_sequence_example_decoder_test.py" to generate tfrecord files? Does it give separate training and validation files? Using this mixes the training and validation files.
Thanks!
Edit: I am trying to train on one GPU: Tesla V100-SXM2-16GB, it seems that this issue relates when training using more than one GPU. There are more infomration here: #266
update: the error s most probably do not related to GPU
Edit: Last observation: The errors are not related to check point and based on my experiments are based on the preprocessing part on data augmentation since empty tensors are passed on. This may caused by the way that data are converted to tfrecord.
@wrkgm Do you get the warning:
WARNING:tensorflow:From /home/ashkan/models/research/object_detection/core/preprocessor.py:1218: calling squeeze (from tensorflow.python.ops.array_ops) with squeeze_dims is deprecated and will be removed in a future version.
Instructions for updating:
Use the axis argument instead
I guess it may help.
Edit: Fixing this still results in the error.
I looked into the tensors in the file seq_dataset_builder.py and noticed that the following tensors are empty:
tensor_dict['groundtruth_boxes']
tensor_dict['groundtruth_classes']
In addition, I get one of the following errors each time (they appear in random order which seems to be related in the randomness of data augmentation part since they go away if you comment the data augmentation in the config file)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Can not squeeze dim[0], expected a dimension of 1, got 0
[[{{node Squeeze_10}} = Squeeze[T=DT_INT64, squeeze_dims=[0], _device="/job:localhost/replica:0/task:0/device:CPU:0"](strided_slice_7)]]
tensorflow.python.framework.errors_impl.InvalidArgumentError: Number of ways to split should evenly divide the split dimension, but got split_dim 0 (size = 10) and num_split 4
[[{{node split}} = Split[T=DT_UINT8, num_split=4, _device="/job:localhost/replica:0/task:0/device:CPU:0"](batch_sequences_with_states/InputQueueingStateSaver/ExpandDims_1/dim, Print)]]
There are commands afterwards as tf.split and tf.squeeze and my understanding is that the errors are caused since empty tensors are being spitted or squeezed.
@ashkanee I just modified the code from that file to generate a tfrecord full of randomly generated numpy arrays. I pointed the train path config at this. Haven't worried about splitting train and test yet, I'm just trying to get the code to run for anything at all. I tried with and without checkpoint and got similar error.
It's almost certainly not related to the GPU. I've got a GTX 1070ti. And I get that same warning. I agree it likely has something to do with the input pipeline or preprocessing steps.
While running train.py file from lstm_object_detection, I get the following error-
Traceback (most recent call last): File "lstm_object_detection/train.py", line 185, in
tf.app.run() File "/home/kt-ml1/.local/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 125, in run _sys.exit(main(argv)) File "lstm_object_detection/train.py", line 94, in main FLAGS.pipeline_config_path) File "/home/kt-ml1/models-master/models-master/research/lstm_object_detection/utils/config_util.py", line 46, in get_configs_from_pipeline_file text_format.Merge(proto_str, pipeline_config) File "/home/kt-ml1/.local/lib/python3.6/site-packages/google/protobuf/text_format.py", line 574, in Merge descriptor_pool=descriptor_pool) File "/home/kt-ml1/.local/lib/python3.6/site-packages/google/protobuf/text_format.py", line 631, in MergeLines return parser.MergeLines(lines, message) File "/home/kt-ml1/.local/lib/python3.6/site-packages/google/protobuf/text_format.py", line 654, in MergeLines self._ParseOrMerge(lines, message) File "/home/kt-ml1/.local/lib/python3.6/site-packages/google/protobuf/text_format.py", line 676, in _ParseOrMerge self._MergeField(tokenizer, message) File "/home/kt-ml1/.local/lib/python3.6/site-packages/google/protobuf/text_format.py", line 735, in _MergeField 'that message's _pb2 module must be imported as well' % name) google.protobuf.text_format.ParseError: 18:26 : Extension "object_detection.protos.lstm_model" not registered. Did you import the _pb2 module which defines it? If you are trying to place the extension in the MessageSet field of another message that is in an Any or MessageSet field, that message's _pb2 module must be imported as well
I figured out that there is something wrong with the config file in the lstm_object_detection. Can someone please help me understand what changes do we need to do in the config file to run it successfully.
Replace object_detection.protos.lstm_model with lstm_object_detection.protos.lstm_model in the config.
We will fix this issue in the codebase shortly.
Replace object_detection.protos.lstm_model with lstm_object_detection.protos.lstm_model in the config.
We will fix this issue in the codebase shortly.
Done. Thanks. But, this got me another error as follows:-
TypeError: Expected binary or unicode string, got <object_detection.core.matcher.Match object at 0x7f5b089379b0>
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "lstm_object_detection/train.py", line 185, in
tf.app.run() File "/home/kt-ml1/.local/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 125, in run _sys.exit(main(argv)) File "lstm_object_detection/train.py", line 181, in main worker_job_name, is_chief, FLAGS.train_dir) File "/home/kt-ml1/models-master/models-master/research/lstm_object_detection/trainer.py", line 293, in train clones = model_deploy.create_clones(deploy_config, model_fn, [input_queue]) File "/home/kt-ml1/models-master/models-master/research/slim/deployment/model_deploy.py", line 193, in create_clones outputs = model_fn(*args, **kwargs) File "/home/kt-ml1/models-master/models-master/research/lstm_object_detection/trainer.py", line 174, in _create_losses losses_dict = detection_model.loss(prediction_dict, true_image_shapes) File "/home/kt-ml1/models-master/models-master/research/lstm_object_detection/meta_architectures/lstm_ssd_meta_arch.py", line 165, in loss match_list = [matcher.Match(match) for match in tf.unstack(batch_match)] File "/home/kt-ml1/.local/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py", line 1149, in unstack value = ops.convert_to_tensor(value) File "/home/kt-ml1/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1039, in convert_to_tensor return convert_to_tensor_v2(value, dtype, preferred_dtype, name) File "/home/kt-ml1/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1097, in convert_to_tensor_v2 as_ref=False) File "/home/kt-ml1/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1175, in internal_convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File "/home/kt-ml1/.local/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 304, in _constant_tensor_conversion_function return constant(v, dtype=dtype, name=name) File "/home/kt-ml1/.local/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 245, in constant allow_broadcast=True) File "/home/kt-ml1/.local/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 283, in _constant_impl allow_broadcast=allow_broadcast)) File "/home/kt-ml1/.local/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 562, in make_tensor_proto "supported type." % (type(values), values)) TypeError: Failed to convert object of type <class 'list'> to Tensor. Contents: [<object_detection.core.matcher.Match object at 0x7f5b089379b0>, <object_detection.core.matcher.Match object at 0x7f5b087b75c0>, <object_detection.core.matcher.Match object at 0x7f5b08626fd0>, <object_detection.core.matcher.Match object at 0x7f5b084a9b00>, <object_detection.core.matcher.Match object at 0x7f5b083302b0>, <object_detection.core.matcher.Match object at 0x7f5b0819a6a0>, <object_detection.core.matcher.Match object at 0x7f5b03fe2710>, <object_detection.core.matcher.Match object at 0x7f5b03e672b0>, <object_detection.core.matcher.Match object at 0x7f5b03cd36a0>, <object_detection.core.matcher.Match object at 0x7f5b03b53710>, <object_detection.core.matcher.Match object at 0x7f5b039d92b0>, <object_detection.core.matcher.Match object at 0x7f5b038456a0>, <object_detection.core.matcher.Match object at 0x7f5b036ca710>, <object_detection.core.matcher.Match object at 0x7f5b0354e2b0>, <object_detection.core.matcher.Match object at 0x7f5b034396a0>, <object_detection.core.matcher.Match object at 0x7f5b032bb710>, <object_detection.core.matcher.Match object at 0x7f5b0313f2b0>, <object_detection.core.matcher.Match object at 0x7f5b02faf6a0>, <object_detection.core.matcher.Match object at 0x7f5b02e315f8>, <object_detection.core.matcher.Match object at 0x7f5b02cb32b0>, <object_detection.core.matcher.Match object at 0x7f5b02b226a0>, <object_detection.core.matcher.Match object at 0x7f5b029a5710>, <object_detection.core.matcher.Match object at 0x7f5b028282b0>, <object_detection.core.matcher.Match object at 0x7f5b026936a0>, <object_detection.core.matcher.Match object at 0x7f5b02518710>, <object_detection.core.matcher.Match object at 0x7f5b0239c2b0>, <object_detection.core.matcher.Match object at 0x7f5b022096a0>, <object_detection.core.matcher.Match object at 0x7f5b0208f710>, <object_detection.core.matcher.Match object at 0x7f5b01f0f2b0>, <object_detection.core.matcher.Match object at 0x7f5b01dfc6a0>, <object_detection.core.matcher.Match object at 0x7f5b01c03710>, <object_detection.core.matcher.Match object at 0x7f5b01a842b0>]. Consider casting elements to a supported type.
PS- I have commented data augmentation option in the config file because it was giving me groundtruth_error
As @ashkanee said, the problem seems to be coming from tensors in the file seq_dataset_builder.py, as the tensors are empty.
Any help would be appreciated.
I think I've found a solution. When trying to understand the scripts, I noticed that keys to features were specified in TFSequenceExampleDecoder and they were different from those in DatasetBuilderTest (seq_dataset_builder_test.py). So, I used a script for creating tf records similar to @wrkgm's first version, but replaced image/object/bbox/... with bbox/... and image/object/class/label with bbox/label/index.
I think I've found a solution. When trying to understand the scripts, I noticed that keys to features were specified in TFSequenceExampleDecoder and they were different from those in DatasetBuilderTest (seq_dataset_builder_test.py). So, I used a script for creating tf records similar to @wrkgm's first version, but replaced
image/object/bbox/...withbbox/...andimage/object/class/labelwithbbox/label/index.
Did you successfully train the model?
Well, not yet. I've just solved this tensorflow.python.framework.errors_impl.InvalidArgumentError and verified that it started to train (iterations shown in tensorboard)
I do plan to train a model on my dataset - shall inform you here of the results
I do plan to train a model on my dataset - shall inform you here of the results
On what dataset did you make the tfrecords?
It's a specific dataset I use for my project. I can't tell the details, but in general, it is a set of annotated (boxes + labels) images organised in folders - one folder for one sequence. I just take each sequence, split it into snippets of length 4 (as specified in lstm_ssd_mobilenet_v1_imagenet.config) and convert each snippet into TF SequenceExample.
It's a specific dataset I use for my project. I can't tell the details, but in general, it is a set of annotated (boxes + labels) images organised in folders - one folder for one sequence. I just take each sequence, split it into snippets of length 4 (as specified in lstm_ssd_mobilenet_v1_imagenet.config) and convert each snippet into TF SequenceExample.
Can we use the same tfrecords we used for objectdetection? Because on using those tfrecords im getting the following issue
tensorflow.python.framework.errors_impl.InvalidArgumentError: Name: , Feature list 'image/encoded' is required but could not be found. Did you mean to include it in feature_list_dense_missing_assumed_empty or feature_list_dense_defaults? [[{{node ParseSingleSequenceExample/ParseSingleSequenceExample}}]]
I haven't worked with object detection tfrecords, but I assume they are not SequenceExamples, but just Examples, and they don't have the required feature lists like image/encoded, bbox/xmin, etc.