tensorflow / models

Models and examples built with TensorFlow
Other
77.18k stars 45.76k forks source link

Textsum error: a bytes-like object is required, not 'str' #4036

Closed abslamp closed 4 years ago

abslamp commented 6 years ago

System information

Source code / logs

Simply used the toy data provided with Textsum and renamed it to training-0. The example training code (changed dir to use in cmd) caused many of this error:

Exception in thread Thread-xxx: Traceback (most recent call last): File "C:\Users\xxx\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916, in _bootstrap_inner self.run() File "C:\Users\xxx\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864, in run self._target(*self._args, self._kwargs) File "\?\C:\Users\xxx\AppData\Local\Temp\Bazel.runfiles_0br8l4_4\runfiles__main\textsum\batch_reader.py", line 139, in _FillInputQueue data.ToSentences(article, include_token=False)] File "\?\C:\Users\xxx\AppData\Local\Temp\Bazel.runfiles_0br8l4_4\runfiles__main__\textsum\data.py", line 215, in ToSentences return [s for s in s_gen] File "\?\C:\Users\xxx\AppData\Local\Temp\Bazel.runfiles_0br8l4_4\runfiles__main__\textsum\data.py", line 215, in return [s for s in s_gen] File "\?\C:\Users\xxx\AppData\Local\Temp\Bazel.runfiles_0br8l4_4\runfiles\main__\textsum\data.py", line 189, in SnippetGen start_p = text.index(start_tok, cur) TypeError: a bytes-like object is required, not 'str'**

cotitan commented 6 years ago

System information

Got the same error. Could it be a problem caused by version.

yhliang2018 commented 6 years ago

@peterjliu @nealwu Could you help on the issue? Thanks.

wei-yuan commented 6 years ago

@yhliang2018 Same error here, have you figured out yet? My setup is Ubuntu 06.04 and tf 1.7, seems it removed from models in r1.7

yhliang2018 commented 6 years ago

@k-w-w Do you have any idea on this issue? Feel free to add people to this thread if they can help.

k-w-w commented 6 years ago

It looks like this issue appears when using python 3 (error does not appear with python 2).

A quick fix would be to decode the bytes in _GetExFeatureText(self, ex, key) in batch_reader.py:

return ex.features.feature[key].bytes_list.value[0].decode('utf-8')

I'll submit a PR with this change if the code runs to completion without error.

ersinyar commented 6 years ago

@k-w-w That trick does not work for me. I still have the same problem. Have you found a way to solve this issue?

k-w-w commented 6 years ago

@ersinyar Are you getting the same error? Also are you running with python 3?

ersinyar commented 6 years ago

@k-w-w I am getting a similar error. I was following the post given in https://eilianyu.wordpress.com/2016/10/17/text-summarization-using-sequence-to-sequence-model-in-tensorflow-and-gpu-computing/. When I try to convert from text to binary before training as explained in the post, I get an error stating that

TypeError: "b'AFP'" has type str, but expected one of: bytes

I run on Python 3 and latest Tensorflow. The post I follow uses TF r0.11 and Python 2.7. First, I thought that latest version of TF might be problematic and I tried different versions. But, I kept getting the same error.

k-w-w commented 6 years ago

@ersinyar The code was most likely intended to run with Python 2, so if that is available to you I would recommend using Py2 instead of applying the fixes. Dealing with differing string encoding can be pretty messy. If you must use Py3, applying the changes in this commit should work.

Hexa4C commented 5 years ago

It looks like this issue appears when using python 3 (error does not appear with python 2).

A quick fix would be to decode the bytes in _GetExFeatureText(self, ex, key) in batch_reader.py:

return ex.features.feature[key].bytes_list.value[0].decode('utf-8')

I'll submit a PR with this change if the code runs to completion without error.

I got the same error using python3. And this WORKS for me! Thank you!

Anatolist commented 4 years ago

System information **What is the top-level directory of the model you are using: Object_Detection Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No OS Platform and Distribution (e.g., Linux Ubuntu 16.04):Ubuntu 18 TensorFlow installed from (source or binary): binary TensorFlow version (use command below): 2.0 Bazel version (if compiling from source): CUDA/cuDNN version: N/A GPU model and memory: N/A Exact command to reproduce: python3 legacy/train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/ssd_mobilenet_v1_pets.config

I 've configured my model, and when I run this command I get the error: File "/home/anatoli/my_tensorflow/my_tensorflow/models/research/object_detection/utils/label_map_util.py", line 143, in load_labelmap TypeError: a bytes-like object is required, not 'str' Could you give me more explanations to fix my problem? Thank U

yhliang2018 commented 4 years ago

You may follow the changes in this commit to fix this. Close this bug for now.