Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Expected binary or unicode string, got None` #5276

Closed
hammadullah125 opened this issue Sep 10, 2018 · 26 comments
Closed

TypeError: Expected binary or unicode string, got None` #5276

hammadullah125 opened this issue Sep 10, 2018 · 26 comments
Assignees
Labels
stat:awaiting response Waiting on input from the contributor

Comments

@hammadullah125
Copy link

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.

@tensorflowbutler tensorflowbutler added the stat:awaiting response Waiting on input from the contributor label Sep 10, 2018
@tensorflowbutler
Copy link
Member

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

@hammadullah125
Copy link
Author

Thanks. I solved this problem

@sumeetssaurav
Copy link

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

@hammadullah125
Copy link
Author

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

@sumeetssaurav
Copy link

sumeetssaurav commented Sep 13, 2018 via email

@hammadullah125
Copy link
Author

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

@sumeetssaurav
Copy link

sumeetssaurav commented Sep 13, 2018 via email

@SteveIb
Copy link

SteveIb commented Nov 18, 2018

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"

@dibet
Copy link

dibet commented Mar 12, 2019

The same error

@Look4-you
Copy link

@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

@devimonica
Copy link

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 ?

@ghost
Copy link

ghost commented Aug 16, 2019

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

@jrasor
Copy link

jrasor commented Aug 18, 2019

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

@drecryptos
Copy link

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

@zambang83
Copy link

@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
Copy link

@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

@drecryptos
Copy link

@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

@zambang83
Copy link

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

@vidalbenjoe
Copy link

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

@MaratZakirov
Copy link

Got same issue with tf.lite.TocoConverter

@IamSierraCharlie
Copy link

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

@ArefAz
Copy link

ArefAz commented May 14, 2020

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

@wangjun1136027660
Copy link

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:\Users\11360\PycharmProjects\test_albert\albert\extract_feature.py", line 117, in predict_from_queue
for i in prediction:
File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py", line 622, in predict
features, None, ModeKeys.PREDICT, self.config)
File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py", line 1148, in _call_model_fn
model_fn_results = self._model_fn(features=features, **kwargs)
File "C:\Users\11360\PycharmProjects\test_albert\albert\extract_feature.py", line 94, in model_fn
graph_def.ParseFromString(f.read())
File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\python\lib\io\file_io.py", line 123, in read
self._preread_check()
File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\python\lib\io\file_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-packages\tensorflow_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

@wangjun1136027660
Copy link

What to do?

@ISS88
Copy link

ISS88 commented Jul 10, 2020

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

@antoineneidecker
Copy link

antoineneidecker commented May 10, 2021

Got this error when converting a model to tf lite, this is the first result when googling the error.

TypeError: Expected binary or unicode string, got <tensorflow.python.keras.engine.functional.Functional object at 0x7f4c60136cd0>

I was passing in the model instead of the directory in which the model is saved.
converter = tf.lite.TFLiteConverter.from_saved_model(model)

Hope this helps someone else
See documentation for more info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:awaiting response Waiting on input from the contributor
Projects
None yet
Development

No branches or pull requests