nicknochnack / RealTimeObjectDetection

369 stars 582 forks source link

Is 'Creating TF Reacords' part necessary? #17

Open mechaphantom opened 3 years ago

mechaphantom commented 3 years ago

I'm newbie and trying the tutorial I found on youtube. Everything is perfect until I came to the 'Creating TF Records' part. I see many errors, the first one is no module found: pandas, I solved it. Then I encounter with an error which says
File "Tensorflow/scripts/generate_tfrecord.py", line 29, in from object_detection.utils import dataset_util, label_map_util ModuleNotFoundError: No module named 'object_detection'

I search this error and I write 'pip install tensorflow-object-detection-api' in cmd. Then I encounter another error which says,

File "Tensorflow/scripts/generate_tfrecord.py", line 61, in label_map = label_map_util.load_labelmap(args.labels_path) File "C:\Python38\lib\site-packages\object_detection\utils\label_map_util.py", line 132, in load_labelmap with tf.gfile.GFile(path, 'r') as fid: AttributeError: module 'tensorflow' has no attribute 'gfile'

Do you have any ide how to fix? Or should I pass this part?

StarvedHawk commented 3 years ago

In order for it to work the following changes need to be implemented :
in generate_tfrecord.py:
label_map = label_map_util.load_labelmap(args.labels_path) label_map_dict = label_map_util.get_label_map_dict(label_map)
as
label_map_dict = label_map_util.get_label_map_dict(args.labels_path) in label_map_util.py :
tf.gfile.GFile(name,mode_code) to
tf.io.gfile.GFile(name,mode=mode_code)

ahmedghadani commented 3 years ago

The solution mentioned by @StarvedHawk works and the TF records are generated successfully, however, it does not work for the configuration when executing: config = config_util.get_configs_from_pipeline_file(CONFIG_PATH)

This is the output, (notice tf.io.gfile.GFile is there but somehow it is not being recognized):

AttributeError: module 'tensorflow' has no attribute 'gfile'
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_12928/2792951555.py in <module>
----> 1 config = config_util.get_configs_from_pipeline_file(CONFIG_PATH)

~\anaconda3\envs\ssd-net\lib\site-packages\object_detection\utils\config_util.py in get_configs_from_pipeline_file(pipeline_config_path, config_override)
     94   """
     95   pipeline_config = pipeline_pb2.TrainEvalPipelineConfig()
---> 96   with tf.io.gfile.GFile(pipeline_config_path, "r") as f:
     97     proto_str = f.read()
     98     text_format.Merge(proto_str, pipeline_config)

AttributeError: module 'tensorflow' has no attribute 'gfile'

After updating Jupiter to the latest version, I got another error which exactly as the one mentioned here Training SSD-MobilenetV2 fails with Message type "object_detection.protos.TrainConfig" has no field named "fine_tune_checkpoint_version" #9297

Applying the solution mentioned here solved it deleting the "fine-tuning checkpoint version" line from the configuration file

nipunwalia commented 2 years ago

@ahmedghadani can you help me with the exact line that's supposed to be deleted. I can't find it in the config_util.py file.

ahmedghadani commented 2 years ago

@nipunwalia Hi, I don't remember exactly, but I don't think it was in config_util.py, rather it was in the pipeline.config file. You will find this file in a path similar to this YOUR_USERNAME\RealTimeObjectDetection\Tensorflow\workspace\models\my_ssd_mobnet\pipeline.config

It should be somewhere around line 172 if nothing has been changed since last time I tried this. Friendly warning though, I remember facing more problems going forward after fixing this xD.

Please let me know if you find that line there. I will have to dig a little bit deeper to verify it from my side

nipunwalia commented 2 years ago

@ahmedghadani thanks man for the help and yes now I get what you meant by "more problems" xD.

harshitha-8 commented 2 years ago

I'm newbie and trying the tutorial I found on youtube. Everything is perfect until I came to the 'Creating TF Records' part. I see many errors, the first one is no module found: pandas, I solved it. Then I encounter with an error which says File "Tensorflow/scripts/generate_tfrecord.py", line 29, in from object_detection.utils import dataset_util, label_map_util ModuleNotFoundError: No module named 'object_detection'

I search this error and I write 'pip install tensorflow-object-detection-api' in cmd. Then I encounter another error which says,

File "Tensorflow/scripts/generate_tfrecord.py", line 61, in label_map = label_map_util.load_labelmap(args.labels_path) File "C:\Python38\lib\site-packages\object_detection\utils\label_map_util.py", line 132, in load_labelmap with tf.gfile.GFile(path, 'r') as fid: AttributeError: module 'tensorflow' has no attribute 'gfile'

Do you have any ide how to fix? Or should I pass this part?

In order for it to work the following changes need to be implemented : in generate_tfrecord.py:

label_map = label_map_util.load_labelmap(args.labels_path)
label_map_dict = label_map_util.get_label_map_dict(label_map)

as

label_map_dict = label_map_util.get_label_map_dict(args.labels_path)

in label_map_util.py :

tf.gfile.GFile(name,mode_code)

to

tf.io.gfile.GFile(name,mode=mode_code)

I was rectifying the error and trying to edit in label_map_util.py but here already tf.io.gfile.GFile is there , but still getting an error

the line of code which is giving error is : with tf.io.gfile.GFile(path,mode='r') as fid:

Any leads about this? if you could help me it would be a great.

Syedfaizan3192 commented 2 years ago

Traceback (most recent call last): File "Tensorflow/scripts/generate_tfrecord.py", line 29, in from object_detection.utils import dataset_util, label_map_util ModuleNotFoundError: No module named 'object_detection' Traceback (most recent call last): File "Tensorflow/scripts/generate_tfrecord.py", line 29, in from object_detection.utils import dataset_util, label_map_util ModuleNotFoundError: No module named 'object_detection

Kindly guide me anyone?

SureshbabuAkash1999 commented 2 years ago

@harshitha-8 Go to this address: C:\Users---\AppData\Local\Programs\Python\Python39\Lib\site-packages\object_detection\utils\label_map_util.py in your pc and do the same changes there.

satwik834 commented 2 years ago

hello while generating tf records im getting an error Traceback (most recent call last): File "G:\hand\RealTimeObjectDetection\Tensorflow\scripts\generate_tfrecord.py", line 168, in tf.app.run() File "C:\Users\new\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow\python\platform\app.py", line 36, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "C:\Users\new\AppData\Local\Programs\Python\Python310\lib\site-packages\absl\app.py", line 312, in run _run_main(main, args) File "C:\Users\new\AppData\Local\Programs\Python\Python310\lib\site-packages\absl\app.py", line 258, in _run_main sys.exit(main(argv)) File "G:\hand\RealTimeObjectDetection\Tensorflow\scripts\generate_tfrecord.py", line 158, in main tf_example = create_tf_example(group, path) File "G:\hand\RealTimeObjectDetection\Tensorflow\scripts\generate_tfrecord.py", line 132, in create_tf_example classes.append(class_text_to_int(row['class'])) File "G:\hand\RealTimeObjectDetection\Tensorflow\scripts\generate_tfrecord.py", line 101, in class_text_to_int return label_map_dict[row_label] KeyError: 'hello' Traceback (most recent call last): File "G:\hand\RealTimeObjectDetection\Tensorflow\scripts\generate_tfrecord.py", line 168, in tf.app.run() File "C:\Users\new\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow\python\platform\app.py", line 36, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "C:\Users\new\AppData\Local\Programs\Python\Python310\lib\site-packages\absl\app.py", line 312, in run _run_main(main, args) File "C:\Users\new\AppData\Local\Programs\Python\Python310\lib\site-packages\absl\app.py", line 258, in _run_main sys.exit(main(argv)) File "G:\hand\RealTimeObjectDetection\Tensorflow\scripts\generate_tfrecord.py", line 158, in main tf_example = create_tf_example(group, path) File "G:\hand\RealTimeObjectDetection\Tensorflow\scripts\generate_tfrecord.py", line 132, in create_tf_example classes.append(class_text_to_int(row['class'])) File "G:\hand\RealTimeObjectDetection\Tensorflow\scripts\generate_tfrecord.py", line 101, in class_text_to_int return label_map_dict[row_label] KeyError: 'hello'

please help

sravaniy123 commented 1 year ago

hello while generating tf records im getting an error Traceback (most recent call last): File "G:\hand\RealTimeObjectDetection\Tensorflow\scripts\generate_tfrecord.py", line 168, in tf.app.run() File "C:\Users\new\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow\python\platform\app.py", line 36, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "C:\Users\new\AppData\Local\Programs\Python\Python310\lib\site-packages\absl\app.py", line 312, in run _run_main(main, args) File "C:\Users\new\AppData\Local\Programs\Python\Python310\lib\site-packages\absl\app.py", line 258, in _run_main sys.exit(main(argv)) File "G:\hand\RealTimeObjectDetection\Tensorflow\scripts\generate_tfrecord.py", line 158, in main tf_example = create_tf_example(group, path) File "G:\hand\RealTimeObjectDetection\Tensorflow\scripts\generate_tfrecord.py", line 132, in create_tf_example classes.append(class_text_to_int(row['class'])) File "G:\hand\RealTimeObjectDetection\Tensorflow\scripts\generate_tfrecord.py", line 101, in class_text_to_int return label_map_dict[row_label] KeyError: 'hello' Traceback (most recent call last): File "G:\hand\RealTimeObjectDetection\Tensorflow\scripts\generate_tfrecord.py", line 168, in tf.app.run() File "C:\Users\new\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow\python\platform\app.py", line 36, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "C:\Users\new\AppData\Local\Programs\Python\Python310\lib\site-packages\absl\app.py", line 312, in run _run_main(main, args) File "C:\Users\new\AppData\Local\Programs\Python\Python310\lib\site-packages\absl\app.py", line 258, in _run_main sys.exit(main(argv)) File "G:\hand\RealTimeObjectDetection\Tensorflow\scripts\generate_tfrecord.py", line 158, in main tf_example = create_tf_example(group, path) File "G:\hand\RealTimeObjectDetection\Tensorflow\scripts\generate_tfrecord.py", line 132, in create_tf_example classes.append(class_text_to_int(row['class'])) File "G:\hand\RealTimeObjectDetection\Tensorflow\scripts\generate_tfrecord.py", line 101, in class_text_to_int return label_map_dict[row_label] KeyError: 'hello'

please help

MEE TOO PLEASE HELP