models icon indicating copy to clipboard operation
models copied to clipboard

TypeError: Expected binary or unicode string, got None`

Open hammadullah125 opened this issue 8 years ago • 26 comments

Whenever I want to train the model with "model_main.py"

python3 model_main.py --logtostderr --train_dir=training/ --pipelie_config_path=training/ssd_mobilenet_v1_pets.config

it's throwing this error.

`/Users/screamer/models/research/object_detection/utils/visualization_utils.py:25: UserWarning: This call to matplotlib.use() has no effect because the backend has already been chosen; matplotlib.use() must be called before pylab, matplotlib.pyplot, or matplotlib.backends is imported for the first time.

The backend was originally set to 'MacOSX' by the following code: File "model_main.py", line 26, in from object_detection import model_lib File "/Users/screamer/models/research/object_detection/model_lib.py", line 26, in from object_detection import eval_util File "/Users/screamer/models/research/object_detection/eval_util.py", line 28, in from object_detection.metrics import coco_evaluation File "/Users/screamer/models/research/object_detection/metrics/coco_evaluation.py", line 20, in from object_detection.metrics import coco_tools File "/Users/screamer/models/research/object_detection/metrics/coco_tools.py", line 47, in from pycocotools import coco File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pycocotools/coco.py", line 49, in import matplotlib.pyplot as plt File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/pyplot.py", line 71, in from matplotlib.backends import pylab_setup File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/backends/init.py", line 16, in line for line in traceback.format_stack()

import matplotlib; matplotlib.use('Agg') # pylint: disable=multiple-statements Traceback (most recent call last): File "model_main.py", line 101, in tf.app.run() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 125, in run _sys.exit(main(argv)) File "model_main.py", line 62, in main eval_steps=FLAGS.num_eval_steps) File "/Users/screamer/models/research/object_detection/model_lib.py", line 497, in create_estimator_and_inputs configs = get_configs_from_pipeline_file(pipeline_config_path) File "/Users/screamer/models/research/object_detection/utils/config_util.py", line 93, in get_configs_from_pipeline_file proto_str = f.read() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/lib/io/file_io.py", line 125, in read self._preread_check() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/lib/io/file_io.py", line 85, in _preread_check compat.as_bytes(self.__name), 1024 * 512, status) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/util/compat.py", line 61, in as_bytes (bytes_or_text,)) TypeError: Expected binary or unicode string, got None`

Any guesses what is wrong? PS: I have also tried with the absolute paths but error remains the same.

hammadullah125 avatar Sep 10 '18 10:09 hammadullah125

Thank you for your post. We noticed you have not filled out the following field in the issue template. Could you update them if they are relevant in your case, or leave them as N/A? Thanks. What is the top-level directory of the model you are using Have I written custom code OS Platform and Distribution TensorFlow installed from TensorFlow version Bazel version CUDA/cuDNN version GPU model and memory Exact command to reproduce

tensorflowbutler avatar Sep 10 '18 19:09 tensorflowbutler

Thanks. I solved this problem

hammadullah125 avatar Sep 11 '18 09:09 hammadullah125

I am also facing the same issue. Could you help me out to resolve this.

sumeetssaurav avatar Sep 12 '18 18:09 sumeetssaurav

Please check your command carefully. In my case, i wrote "pipelie" where alphabet "n" was missing. After correcting this, my problem was solved.

hammadullah125 avatar Sep 13 '18 08:09 hammadullah125

Thanks for the quick reply. However with model_main.py it has become really difficult to train a model on custom dataset. I am not getting any detection after evaluation. My model is not getting trained at all. I don't know where I m making mistakes. Just curious whether you got success..? If yes then plz guide me too.

On Thursday, September 13, 2018, Hammad Ullah [email protected] wrote:

Please check your command carefully. In my case, i wrote "pipelie" where alphabet "n" was missing. After correcting this, my problem was solved.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tensorflow/models/issues/5276#issuecomment-420928794, or mute the thread https://github.com/notifications/unsubscribe-auth/ANCgkwqCtVUokE_AcPMdPyBwYXXxTsOCks5uahlagaJpZM4WhHvR .

-- With Best Wishes Sumeet Saurav

sumeetssaurav avatar Sep 13 '18 20:09 sumeetssaurav

My model is still on training. I’m using CPU training.

hammadullah125 avatar Sep 13 '18 20:09 hammadullah125

Okay...how about your losses...? How you set the value of num_train_steps and num_eval_steps? My evaluation is showing average precision and recall as -1.00 which is wrong. Don't know where I am making mistakes. How you passed the arguments..?

On Friday, September 14, 2018, Hammad Ullah [email protected] wrote:

My model is still on training. I’m using CPU training.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tensorflow/models/issues/5276#issuecomment-421151057, or mute the thread https://github.com/notifications/unsubscribe-auth/ANCgk9GZV8Ue800PXkC6k93mvwW4DJVCks5uaseXgaJpZM4WhHvR .

-- With Best Wishes Sumeet Saurav

sumeetssaurav avatar Sep 13 '18 21:09 sumeetssaurav

I had the same problem with the the following command python object_detection/export_tflite_ssd_graph.py \ --pipeline_config_path=$CONFIG_FILE \ --trained_checkpoint_prefix=$CHECKPOINT_PATH \ --output_directory=$OUTPUT_DIR \ --add_postprocessing_op=true

I changed it to the following python object_detection/export_tflite_ssd_graph.py --pipeline_config_path=$CONFIG_FILE --trained_checkpoint_prefix=$CHECKPOINT_PATH --output_directory=$OUTPUT_DIR --add_postprocessing_op=true

I just removed the '' between the arguments and on the same line not multiline.

The first command gave that error "TypeError: Expected binary or unicode string, got None"

SteveIb avatar Nov 18 '18 10:11 SteveIb

The same error

dibet avatar Mar 12 '19 18:03 dibet

@hammadullah125 HI! I want to know how did you deploy the model_main.py? I've set the model_dir,pipeline_config_path and the num_train_steps. and still get the error TypeError: Expected binary or unicode string, got None.

here is my set of the code(in object_detection/model_main.py): `flags.DEFINE_string( 'model_dir', None, r'F:/mask_rcnn-myself/detection/result/' 'where event and checkpoint files will be written.') flags.DEFINE_string('pipeline_config_path', None, r'F:/mask_rcnn-myself/detection/training/coco.config' 'file.') flags.DEFINE_integer('num_train_steps', None, '50000 ')

and here is my error: Traceback (most recent call last): File "F:/mask_rcnn-myself/detection/model_main.py", line 110, in tf.app.run() File "D:\Anacoda\anacoda\lib\site-packages\tensorflow\python\platform\app.py", line 125, in run _sys.exit(main(argv)) File "F:/mask_rcnn-myself/detection/model_main.py", line 72, in main FLAGS.sample_1_of_n_eval_on_train_examples)) File "D:\Anacoda\anacoda\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\model_lib.py", line 589, in create_estimator_and_inputs pipeline_config_path, config_override=config_override) File "D:\Anacoda\anacoda\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\utils\config_util.py", line 97, in get_configs_from_pipeline_file proto_str = f.read() File "D:\Anacoda\anacoda\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 125, in read self._preread_check() File "D:\Anacoda\anacoda\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 85, in _preread_check compat.as_bytes(self.__name), 1024 * 512, status) File "D:\Anacoda\anacoda\lib\site-packages\tensorflow\python\util\compat.py", line 61, in as_bytes (bytes_or_text,)) TypeError: Expected binary or unicode string, got None

Look4-you avatar Mar 21 '19 03:03 Look4-you

I had the same problem with the the following command python object_detection/export_tflite_ssd_graph.py \ --pipeline_config_path=$CONFIG_FILE \ --trained_checkpoint_prefix=$CHECKPOINT_PATH \ --output_directory=$OUTPUT_DIR \ --add_postprocessing_op=true

I changed it to the following python object_detection/export_tflite_ssd_graph.py --pipeline_config_path=$CONFIG_FILE --trained_checkpoint_prefix=$CHECKPOINT_PATH --output_directory=$OUTPUT_DIR --add_postprocessing_op=true

I just removed the '' between the arguments and on the same line not multiline.

The first command gave that error "TypeError: Expected binary or unicode string, got None"

I had the same problem with the the following command python object_detection/export_tflite_ssd_graph.py \ --pipeline_config_path=$CONFIG_FILE \ --trained_checkpoint_prefix=$CHECKPOINT_PATH \ --output_directory=$OUTPUT_DIR \ --add_postprocessing_op=true

I changed it to the following python object_detection/export_tflite_ssd_graph.py --pipeline_config_path=$CONFIG_FILE --trained_checkpoint_prefix=$CHECKPOINT_PATH --output_directory=$OUTPUT_DIR --add_postprocessing_op=true

I just removed the '' between the arguments and on the same line not multiline.

The first command gave that error "TypeError: Expected binary or unicode string, got None"

Hey, I am getting the same error. Did you give path to any directory in that command ?

devimonica avatar May 14 '19 22:05 devimonica

Hey! im getting the same error. Any solution???

ghost avatar Aug 16 '19 08:08 ghost

@Stevelb's solution worked for me.

I noticed that model_main.py loads up parameters on line 64 and following for an estimator. On changing the order of the parameters, the gripe "TypeError: Expected binary or unicode string, got None" is always on the last parameter. Look for "sys.exit(main(argv))" in the traceback.

jrasor avatar Aug 18 '19 19:08 jrasor

@hammadullah125 HI! I want to know how did you deploy the model_main.py? I've set the model_dir,pipeline_config_path and the num_train_steps. and still get the error TypeError: Expected binary or unicode string, got None.

here is my set of the code(in object_detection/model_main.py): `flags.DEFINE_string( 'model_dir', None, r'F:/mask_rcnn-myself/detection/result/' 'where event and checkpoint files will be written.') flags.DEFINE_string('pipeline_config_path', None, r'F:/mask_rcnn-myself/detection/training/coco.config' 'file.') flags.DEFINE_integer('num_train_steps', None, '50000 ')

and here is my error: Traceback (most recent call last): File "F:/mask_rcnn-myself/detection/model_main.py", line 110, in tf.app.run() File "D:\Anacoda\anacoda\lib\site-packages\tensorflow\python\platform\app.py", line 125, in run _sys.exit(main(argv)) File "F:/mask_rcnn-myself/detection/model_main.py", line 72, in main FLAGS.sample_1_of_n_eval_on_train_examples)) File "D:\Anacoda\anacoda\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\model_lib.py", line 589, in create_estimator_and_inputs pipeline_config_path, config_override=config_override) File "D:\Anacoda\anacoda\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\utils\config_util.py", line 97, in get_configs_from_pipeline_file proto_str = f.read() File "D:\Anacoda\anacoda\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 125, in read self._preread_check() File "D:\Anacoda\anacoda\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 85, in _preread_check compat.as_bytes(self.__name), 1024 * 512, status) File "D:\Anacoda\anacoda\lib\site-packages\tensorflow\python\util\compat.py", line 61, in as_bytes (bytes_or_text,)) TypeError: Expected binary or unicode string, got None

Hi,

Any solution for this error?

drecryptos avatar Oct 10 '19 06:10 drecryptos

@SteveIb please can you explain more of your solution, am also facing the same problem

Traceback (most recent call last): File "model_main.py", line 109, in tf.app.run() File "D:\Deep_Learning_CNN\deep_learning\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "D:\Deep_Learning_CNN\deep_learning\lib\site-packages\absl\app.py", line 300, in run _run_main(main, args) File "D:\Deep_Learning_CNN\deep_learning\lib\site-packages\absl\app.py", line 251, in _run_main sys.exit(main(argv)) File "model_main.py", line 71, in main FLAGS.sample_1_of_n_eval_on_train_examples)) File "D:\Tensorflow\models\research\object_detection\model_lib.py", line 605, in create_estimator_and_inputs pipeline_config_path, config_override=config_override) File "D:\Tensorflow\models\research\object_detection\utils\config_util.py", line 103, in get_configs_from_pipeline_file proto_str = f.read() File "D:\Deep_Learning_CNN\deep_learning\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 122, in read self._preread_check() File "D:\Deep_Learning_CNN\deep_learning\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 84, in _preread_check compat.as_bytes(self.__name), 1024 * 512) File "D:\Deep_Learning_CNN\deep_learning\lib\site-packages\tensorflow\python\util\compat.py", line 65, in as_bytes (bytes_or_text,)) TypeError: Expected binary or unicode string, got None

any solution

zambang83 avatar Oct 11 '19 18:10 zambang83

@all I train the ssd_inception_v2_coco_2018_01_28, faster_rcnn_inception_v2_coco_2018_01_28, ssd_mobilenet_v2_coco_2018_03_29. However when I try to train on both the faster_rcnn_nas_coco_2018_01_28 and faster_rcnn_resnet50_coco_2018_01_28 I get the following error

python model_main.py -- logtostderr -- train_dir=training/ --pipeline_config_path=training/faster_rcnn_nas_coco.config

aceback (most recent call last): File "model_main.py", line 109, in tf.app.run() File "D:\Deep_Learning_CNN\deep_learning\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "D:\Deep_Learning_CNN\deep_learning\lib\site-packages\absl\app.py", line 300, in run _run_main(main, args) File "D:\Deep_Learning_CNN\deep_learning\lib\site-packages\absl\app.py", line 251, in _run_main sys.exit(main(argv)) File "model_main.py", line 71, in main FLAGS.sample_1_of_n_eval_on_train_examples)) File "D:\Tensorflow\models\research\object_detection\model_lib.py", line 605, in create_estimator_and_inputs pipeline_config_path, config_override=config_override) File "D:\Tensorflow\models\research\object_detection\utils\config_util.py", line 103, in get_configs_from_pipeline_file proto_str = f.read() File "D:\Deep_Learning_CNN\deep_learning\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 122, in read self._preread_check() File "D:\Deep_Learning_CNN\deep_learning\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 84, in _preread_check compat.as_bytes(self.__name), 1024 * 512) File "D:\Deep_Learning_CNN\deep_learning\lib\site-packages\tensorflow\python\util\compat.py", line 65, in as_bytes (bytes_or_text,)) TypeError: Expected binary or unicode string, got None

please any solution

zambang83 avatar Oct 11 '19 18:10 zambang83

@ALL I train the ssd_inception_v2_coco_2018_01_28, faster_rcnn_inception_v2_coco_2018_01_28, ssd_mobilenet_v2_coco_2018_03_29. However when I try to train on both the faster_rcnn_nas_coco_2018_01_28 and faster_rcnn_resnet50_coco_2018_01_28 I get the following error

python model_main.py -- logtostderr -- train_dir=training/ --pipeline_config_path=training/faster_rcnn_nas_coco.config

aceback (most recent call last): File "model_main.py", line 109, in tf.app.run() File "D:\Deep_Learning_CNN\deep_learning\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "D:\Deep_Learning_CNN\deep_learning\lib\site-packages\absl\app.py", line 300, in run _run_main(main, args) File "D:\Deep_Learning_CNN\deep_learning\lib\site-packages\absl\app.py", line 251, in _run_main sys.exit(main(argv)) File "model_main.py", line 71, in main FLAGS.sample_1_of_n_eval_on_train_examples)) File "D:\Tensorflow\models\research\object_detection\model_lib.py", line 605, in create_estimator_and_inputs pipeline_config_path, config_override=config_override) File "D:\Tensorflow\models\research\object_detection\utils\config_util.py", line 103, in get_configs_from_pipeline_file proto_str = f.read() File "D:\Deep_Learning_CNN\deep_learning\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 122, in read self._preread_check() File "D:\Deep_Learning_CNN\deep_learning\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 84, in _preread_check compat.as_bytes(self.__name), 1024 * 512) File "D:\Deep_Learning_CNN\deep_learning\lib\site-packages\tensorflow\python\util\compat.py", line 65, in as_bytes (bytes_or_text,)) TypeError: Expected binary or unicode string, got None

please any solution

I fixed the error by giving the absolute directory path where ever it required.

python model_main.py -- logtostderr -- train_dir=give the full path/training/ --pipeline_config_path=give the full path/training/faster_rcnn_nas_coco.config

drecryptos avatar Oct 12 '19 05:10 drecryptos

@drecryptos thanks for your response. I restarted my computed and it works.

zambang83 avatar Oct 12 '19 07:10 zambang83

you can try something like this !python /content/models/research/object_detection/export_tflite_ssd_graph.py --pipeline_config_path=$pipeline_fname --trained_checkpoint_prefix= $last_model_path --output_directory= $output_directory --add_postprocessing_op=true -— max_detections 10

vidalbenjoe avatar Oct 28 '19 02:10 vidalbenjoe

Got same issue with tf.lite.TocoConverter

MaratZakirov avatar May 06 '20 09:05 MaratZakirov