Models: TypeError: Expected binary or unicode string, got None`

Created on 10 Sep 2018  Â·  25Comments  Â·  Source: tensorflow/models

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.

awaiting response

Most helpful comment

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

All 25 comments

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

Thanks. I solved this problem

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

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

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 notifications@github.com
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

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

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 notifications@github.com
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

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"

The same error

@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-packagestensorflow\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-packagestensorflow\python\lib\iofile_io.py", line 125, in read
self._preread_check()
File "D:\Anacoda\anacoda\lib\site-packagestensorflow\python\lib\iofile_io.py", line 85, in _preread_check
compat.as_bytes(self.__name), 1024 * 512, status)
File "D:\Anacoda\anacoda\lib\site-packagestensorflow\python\util\compat.py", line 61, in as_bytes
(bytes_or_text,))
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"

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 ?

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

@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.

@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-packagestensorflow\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-packagestensorflow\python\lib\iofile_io.py", line 125, in read
self._preread_check()
File "D:\Anacoda\anacoda\lib\site-packagestensorflow\python\lib\iofile_io.py", line 85, in _preread_check
compat.as_bytes(self.__name), 1024 * 512, status)
File "D:\Anacoda\anacoda\lib\site-packagestensorflow\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?

@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-packagestensorflow\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-packagestensorflow\python\lib\iofile_io.py", line 122, in read
self._preread_check()
File "D:\Deep_Learning_CNN\deep_learning\lib\site-packagestensorflow\python\lib\iofile_io.py", line 84, in _preread_check
compat.as_bytes(self.__name), 1024 * 512)
File "D:\Deep_Learning_CNN\deep_learning\lib\site-packagestensorflow\python\util\compat.py", line 65, in as_bytes
(bytes_or_text,))
TypeError: Expected binary or unicode string, got None

any solution

@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-packagestensorflow\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-packagestensorflow\python\lib\iofile_io.py", line 122, in read
self._preread_check()
File "D:\Deep_Learning_CNN\deep_learning\lib\site-packagestensorflow\python\lib\iofile_io.py", line 84, in _preread_check
compat.as_bytes(self.__name), 1024 * 512)
File "D:\Deep_Learning_CNN\deep_learning\lib\site-packagestensorflow\python\util\compat.py", line 65, in as_bytes
(bytes_or_text,))
TypeError: Expected binary or unicode string, got None

please any solution

@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-packagestensorflow\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-packagestensorflow\python\lib\iofile_io.py", line 122, in read
self._preread_check()
File "D:\Deep_Learning_CNN\deep_learning\lib\site-packagestensorflow\python\lib\iofile_io.py", line 84, in _preread_check
compat.as_bytes(self.__name), 1024 * 512)
File "D:\Deep_Learning_CNN\deep_learning\lib\site-packagestensorflow\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 thanks for your response. I restarted my computed and it works.

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

Got same issue with tf.lite.TocoConverter

I have just encountered this error myself. This is likely nothing more than a syntax issue - check, check and doublecheck your commands and paths

It's absolutely just a typo or syntax issue in your command. My mistake was that I wrote --pipeline_config_pat instead of --pipeline_config_path. Missed an 'h'.

I:BERT_VEC:[graph:opt: 46]:model config: C:/Users/11360/PycharmProjects/test_albert/albert_base/albert_config.json
I:BERT_VEC:[graph:opt: 52]:build graph...
E:BERT_VEC:[graph:opt:145]:fail to optimize the graph!
E:BERT_VEC:[graph:opt:146]:tf.placeholder() is not compatible with eager execution.

Exception in thread Thread-1:

Traceback (most recent call last):
None
File "C:\ProgramData\Anaconda3\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "C:\ProgramData\Anaconda3\lib\threading.py", line 865, in run
self._target(self._args, *self._kwargs)
File "C:\Users11360\PycharmProjectstest_albert\albert\extract_feature.py", line 117, in predict_from_queue
for i in prediction:
File "C:\ProgramData\Anaconda3\lib\site-packagestensorflow_estimator\python\estimator\estimator.py", line 622, in predict
features, None, ModeKeys.PREDICT, self.config)
File "C:\ProgramData\Anaconda3\lib\site-packagestensorflow_estimator\python\estimator\estimator.py", line 1148, in _call_model_fn
model_fn_results = self._model_fn(features=features, **kwargs)
File "C:\Users11360\PycharmProjectstest_albert\albert\extract_feature.py", line 94, in model_fn
graph_def.ParseFromString(f.read())
File "C:\ProgramData\Anaconda3\lib\site-packagestensorflow_core\python\lib\iofile_io.py", line 123, in read
self._preread_check()
File "C:\ProgramData\Anaconda3\lib\site-packagestensorflow_core\python\lib\iofile_io.py", line 85, in _preread_check
self._read_buf = pywrap_tensorflow.CreateBufferedInputStream(compat.as_bytes(self.__name), 1024 * 512)
File "C:\ProgramData\Anaconda3\lib\site-packagestensorflow_core\python\util\compat.py", line 71, in as_bytes
raise TypeError('Expected binary or unicode string, got %r' %(bytes_or_text))
TypeError: Expected binary or unicode string, got None

What to do?

hello so here I try to train a model of mask r cnn on my own give with the command
python D:\Projet\CV-CommonTools\model_main.py /
--model_dir training /
--pipeline_config_path training\mask_rcnn_inception_v2.config /
--num_train_steps 60000 /
--sample_1_of_n_eval_examples=0 /
--alsologtostderr

but i get the following error

Traceback (most recent call last):
  File "D:\Projet\CV-CommonTools\model_main.py", line 110, in <module>
    tf.app.run()
  File "C:\Users\Ibrahim\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "C:\Users\Ibrahim\AppData\Local\Programs\Python\Python36\lib\site-packages\absl\app.py", line 299, in run
    _run_main(main, args)
  File "C:\Users\Ibrahim\AppData\Local\Programs\Python\Python36\lib\site-packages\absl\app.py", line 250, in _run_main
    sys.exit(main(argv))
  File "D:\Projet\CV-CommonTools\model_main.py", line 71, in main
    FLAGS.sample_1_of_n_eval_on_train_examples))
TypeError: create_estimator_and_inputs() missing 1 required positional argument: 'hparams'

could someone guided me please

Was this page helpful?
0 / 5 - 0 ratings

Related issues

noumanriazkhan picture noumanriazkhan  Â·  3Comments

jacknlliu picture jacknlliu  Â·  3Comments

nmfisher picture nmfisher  Â·  3Comments

sun9700 picture sun9700  Â·  3Comments

atabakd picture atabakd  Â·  3Comments