TypeError: 'urban' has type str, but expected one of: bytes
在前面添加"b"(例如,b'urban'),或者处理为variableName.encode("utf8")
Variable count_var2 already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope?
在开始的地方添加:
tf.reset_default_graph()
File "F:Program FilesPythonPython36lib andom.py", line 275, in shuffle
x[i], x[j] = x[j], x[i]
TypeError: 'range' object does not support item assignment
后来定位原因是tfrecord是基于python2写的,里面range返回的list对象,但是再python3里面返回的是range对象。
1 shuffled_index = range(len(filenames)) 2 random.seed(12345) 3 random.shuffle(list(shuffled_index))
如此修改,问题解决
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 247: character maps to <undefined>
with open(file=filename, mode="rb") as f:
将mode由"r"转变为"rb"
https://blog.csdn.net/qq_41185868/article/details/82843781
TypeError: 'RGB' has type str, but expected one of: bytes
1 colorspace = b'RGB' 2 channels = 3 3 image_format = b'JPEG' 4 5 example = tf.train.Example(features=tf.train.Features(feature={ 6 ... 7 'image/colorspace': _bytes_feature(colorspace), 8 ... 9 'image/format': _bytes_feature(image_format), 10 ... 11 return example
在colorspace以及image_format中添加了'b',问题解决。
TypeError: 'water' has type str, but expected one of: bytes
1 def _bytes_feature(value): 2 """Wrapper for inserting bytes features into Example proto.""" 3 print("value值是: ", value) 4 if(type(value) is not bytes): 5 value = value.encode("utf8") 6 return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
def _bytes_feature(value): """Wrapper for inserting bytes features into Example proto.""" print("value值是: ", value) if(type(value) is not bytes):
注意bytes是python3中引入的一个类型;pyton2的时候后,string类型是可以当成byte来处理的,比如传输,但是到了python3时代,bytes和string是严格区分的;所有有了上面这段判断,如果不是bytes需要转换为byte(注意类型判断使用的是"is/ is not";
ValueError: invalid literal for int() with base 10: 'lOOOOO'
argument = "lOOOOOO" argument = int(argument) print("complete")
后来发现那个圈其实是大写的"O"而不是"0"... ... 请问,这一条可以不写吗?后来想明白了原因,我是从PDF中直接粘出来的,PDF是一个根据图片生成的命令,会做一些莫名其妙的转换,发生了0转O的情况。