python3 slim微调时 数据转TFRecord和tf.ConfigProto设置问题

采用InceptionV3来微调自己的数据

一.GPU问题

Cannot assign a device for operation 'InceptionV3/AuxLogits/Conv2d_2b_1x1/weights/RMSProp1': Could not satisfy explicit device specification '/device:GPU:0' because no supported kernel for GPU devices is available.

翻了一些资料,可能是定义在图中的op只能在CPU中运行,GPU不支持

解决方法:

1.将以下参数由False设置为True,但是这样的话,整个程序都在CPU上运行,会很慢。所以可以用第二种方式

2.设置tf.ConfigProto

config = tf.ConfigProto(allow_soft_placement = True)
sess = tf.Session(config = config)

这种方式适合在session中,如果是slim里,由于本身将session封装好了,不需要创建,所以用



二.在python3环境中将数据转为TFRecord时遇到的问题(python2好像没有这个问题)

return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
TypeError: 'rock' has type str, but expected one of: bytes

解决方式:

转byte feature时用tf.compat.as_bytes(value)将字节或 Unicode 转换为 bytes,使用 UTF-8 编码文本。如图:


猜你喜欢

转载自blog.csdn.net/lisa_ren_123/article/details/80199256