Tensorflow 填坑日记

来源:互联网 发布:龙江网络 客服电话多少 编辑:程序博客网 时间:2024/06/05 04:47

坑一、UnicodeEncodeError: 'utf-8' codec can't encode character '\udcce' in position 1936: surrogates not a

这个坑搞了我很久,开始以为是python的版本问题 然后一路pint命令下去 发现是label_map_util.py这边的

with tf.gfile.FastGFile(path, 'r') as fid:  

label_map_string = fid.read()

出了问题 我单独抽出来

于是自己写了一段

import matplotlib.pyplot as plt;  import tensorflow as tf;    image_raw_data_jpg = tf.gfile.FastGFile('D:\我的图片s\1.jpg', 'rb').read()    with tf.Session() as sess:      img_data_jpg = tf.image.decode_jpeg(image_raw_data_jpg) #解码      img_data_jpg = tf.image.convert_image_dtype(img_data_jpg, dtype=tf.uint8)      encode_image_jpg = tf.image.encode_jpeg(img_data_jpg) #jpg编码      encode_image_png = tf.image.encode_png(img_data_jpg)#png编码        with tf.gfile.GFile('output.jpg', 'wb') as f:          f.write(encode_image_jpg.eval())          with tf.gfile.GFile('output.png', 'wb') as f:          f.write(encode_image_png.eval())  
发现还是

UnicodeEncodeError: 'utf-8' codec can't encode character '\udcd5' in position 1942: surrogates not allowed

于是 我发现路径我打多了一个s

D:\我的图片s\1.jpg

于是我猜测是路径不对引起的读取错误

于是我

直接写

# In[ ]:label_map = label_map_util.load_labelmap("D:\\models-master\\research\\object_detection\\data\\mscoco_label_map.pbtxt")categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True)category_index = label_map_util.create_category_index(categories)
好了 运行通过 

问题:路径不对造成的读取错误

-------------------------------------------------未完待续----------------------------------------------------------------------------------------




原创粉丝点击