TensorFlow运行出错:UnicodeEncodeError: ‘utf-8’ codec can’t encode character ‘\udcce’ in position 2559: s

2022年6月19日09:17:53

TensorFlow运行利用slim读取TFRecord中的数据:

一开始报错:UnicodeEncodeError: 'utf-8' codec can't encode character '\udcce' in position 2559: surrogates not allowed

想了好久才发现原来是路径的问题,之前是在Windows下复制的路径(flower数据集的地址):D:\tmp\data\flowers

但是tensorflow下的路径不是这样的,斜杠相反:D:/tmp/data/flowers

这样一来,程序就跑通了


import tensorflow as tf
from datasets import flowers
import pylab 

slim = tf.contrib.slim

DATA_DIR="D:/tmp/data/flowers"

#选择数据集validation
dataset = flowers.get_split('validation', DATA_DIR)

#创建一个provider
provider = slim.dataset_data_provider.DatasetDataProvider(dataset)
#通过provider的get拿到内容
[image, label] = provider.get(['image', 'label'])
print(image.shape)

sess = tf.InteractiveSession()
tf.global_variables_initializer().run()
#启动队列
tf.train.start_queue_runners()
#获取数据
image_batch, label_batch = sess.run([image, label])
#显示
print(label_batch)
pylab.imshow(image_batch)
pylab.show()

  • 作者:无止境x
  • 原文链接:https://blog.csdn.net/xjp_xujiping/article/details/81394640
    更新时间:2022年6月19日09:17:53 ,共 798 字。