I've been trying to use tensorflow2 and transferlearning to find a certain object. This is the code I've got so far, the first steps work without any problem but when I try to trin the model (the last command), I have some errors (AttributeError)but I don't know how to solve them, I think it has to do with the .tfrecord files providing the images but I'm not completly sure. It's my first time working with something like this. This is the link to my google colab proyect:
The code that is giving me the errors:
num_classes = 1
batch_size = 36
num_steps = 7500
num_eval_steps = 1000
train_record_path = '/content/drive/MyDrive/train.tfrecord'
test_record_path = '/content/drive/MyDrive/test.tfrecord'
model_dir = '/content/training/'
labelmap_path = '/content/drive/MyDrive/labels.txt'
pipeline_config_path = '/content/mobilenet_v2.config'
fine_tune_checkpoint = '/content/mobilenet_v2/mobilenet_v2.ckpt-1'
import re
with open(pipeline_config_path) as f:
config = f.read()
with open(pipeline_config_path, 'w') as f:
# Set labelmap path
config = re.sub('label_map_path: ".*?"',
'label_map_path: "{}"'.format(labelmap_path), config)
# Set fine_tune_checkpoint path
config = re.sub('fine_tune_checkpoint: ".*?"',
'fine_tune_checkpoint: "{}"'.format(fine_tune_checkpoint), config)
# Set train tf-record file path
config = re.sub('(input_path: ".*?)(PATH_TO_BE_CONFIGURED/train)(.*?")',
'input_path: "{}"'.format(train_record_path), config)
# Set test tf-record file path
config = re.sub('(input_path: ".*?)(PATH_TO_BE_CONFIGURED/val)(.*?")',
'input_path: "{}"'.format(test_record_path), config)
# Set number of classes.
config = re.sub('num_classes: [0-9]+',
'num_classes: {}'.format(num_classes), config)
# Set batch size
config = re.sub('batch_size: [0-9]+',
'batch_size: {}'.format(batch_size), config)
# Set training steps
config = re.sub('num_steps: [0-9]+',
'num_steps: {}'.format(num_steps), config)
f.write(config)
!python /content/models/research/object_detection/model_main_tf2.py \
--pipeline_config_path={pipeline_config_path} \
--model_dir={model_dir} \
--alsologtostderr \
--num_train_steps={num_steps} \
--sample_1_of_n_eval_examples=1 \
--num_eval_steps={num_eval_steps}
And the errors:
AttributeError: in user code:
File "/usr/local/lib/python3.10/dist-packages/object_detection/data_decoders/tf_example_decoder.py", line 556, in decode *
tensors = decoder.decode(serialized_example, items=keys)
File "/usr/local/lib/python3.10/dist-packages/tf_slim/data/tfexample_decoder.py", line 722, in decode *
outputs.append(handler.tensors_to_item(keys_to_tensors))
File "/usr/local/lib/python3.10/dist-packages/tf_slim/data/tfexample_decoder.py", line 405, in tensors_to_item *
return self._decode(image_buffer, image_format)
File "/usr/local/lib/python3.10/dist-packages/tf_slim/data/tfexample_decoder.py", line 453, in _decode *
image = control_flow_ops.case(
AttributeError: module 'tensorflow.python.ops.control_flow_ops' has no attribute 'case'