报错:’utf-8′ codec can’t decode byte 0xd5 in position 98: invalid continuation byte

在运行下面代码的时候,报了错误:'utf-8' codec can't decode byte 0xd5 in position 98: invalid continuation byte
代码如下:

import os
import numpy as np
#import input_D } Ydata
#import model
N_CLASSES = 2  # 2个输出神经元,[1,0] 或者 [0,1]猫和狗的概率
IMG_W = 208  # 重新定义图片的大小,图片如果过大则训练比较慢
IMG_H = 208
BATCH_SIZE = 32  #每批数据的大小
CAPACITY = 256
MAX_STEP = 15000 # 训练的步数,应当 >= 10000
learning_rate = 0.0001 # 学习率,建议刚开始的 learning_rate <= 0.0001
def run_training():
# 数据集
train_dir = 'D:/Python/data/DogVsCat/kaggle/train'   #My dir--20170727-csq
#logs_train_dir 存放训| k ( T } 9练模型的过程+ / H d ? F的数据,在tensorboard 中查看
logs_train_dir = 'D:/Python/data/DogVsCat/kaggle/'
# 获取图片和标签集
train, train_label = get_files(train_dir)
# 生成批次
t & - g t Grain_batch, train_la= { 0 { X p ] ^ ,bel_batch = get_batch(train,
trF c %ain_label,
IMG_W,
IMG_H,
BATCH_SIZE,
CAPACITY)
# 进入模型
train_logits = inference(train_batch, BATCH_SW d A F / l j T /IZE, N_CLASSES)
# 获取 losw G q s ns
train_loss = lI $ 1 n S  U 0 _osses(train_logits,Y Q - T train_label_batch)
# 训练
train_op = trainning(trainc w I 0 { 1 k X t_loss, learning_rate)
# 获取准确率
train__acce ^ N = evaluation(train_logits, train_label_batch? m ? u 5)j o T d V - {
# 合并 summary
summary_op = tf.summary.merge_all()
sess = tf.Session()
# 保存summary
train_writer = tf.summary.FileWriter(logsR * z } ) U d ;_train_dir, sess.graph)
su | 1aver = tf.train.Saver()
sess.run(tf.global_variables_initializer())
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord% S ] L K V [ U X)
try:
for step in np.arange(MAX_STEP):
if coord.should_% ` t Sstop():
break
_,U G m [  # R tra_loss, tra_acc = sess.run([train_op, train_ v G [ O 4 { w_loss, train__acc])
if step % 50 == 0:
print('Step %d, train loss = %.2f,J J E = | train accuracy = %.2f%%' %(step, tra_loss, tra_acc*100.0))
summary_str = sess.run(summary_op)
train_writer.add_summary(summary_str, step)
if step % 2000 == 0 or (step + 1) == MAX_STEP:
# 每隔2000步保存一下模型,模型保存在 checkpoint_path 中
checkpoint_path = os.path.join(logs_train) e ; / P m 4 q f_dir, 'model.ckpt'; w ] d ) ^ ])
saver.savet b [ j 9 F(sess, checkpoint_path, global_step=step)
except tI  } c %f.errors.OutOfRangeError:
pr} | , ;int('Done training -- epoch limit reached')
finally:
coord.ra j f c 5 & { equest_stop()
coord.join(threads)
sess.close()
# train
run_training()

在网: 9 l i - M O n上找了都不行,求解决。

回答

读取文件编码不统一可以尝试在代码后添加命令
例如
path = './PlayNow.ini'
path_config.read(path,encoding='UTF-16')