我正在尝试使用Tensorflow 1.1.0和TFLearn 0.3.1为大量癌症图像(.png)构建自定义CNN分类器,主要是跟随其他人的CNN分类器here,但是当我尝试为了适应我的模型,Tensorflow会抛出以下错误:
W tensorflow/core/framework/op_kernel.cc:983] Unimplemented: Cast string to float is not supported
E tensorflow/core/common_runtime/executor.cc:594] Executor failed to create kernel. Unimplemented: Cast string to float is not supported
[[Node: Adam/apply_grad_op_0/update_FullyConnected_1/b/Cast_2 = Cast[DstT=DT_FLOAT, SrcT=DT_STRING, _class=["loc:@FullyConnected_1/b"], _device="/job:localhost/replica:0/task:0/cpu:0"](Adam/apply_grad_op_0/learning_rate)]]
W tensorflow/core/framework/op_kernel.cc:983] Unimplemented: Cast string to float is not supported
E tensorflow/core/common_runtime/executor.cc:594] Executor failed to create kernel. Unimplemented: Cast string to float is not supported
[[Node: Adam/apply_grad_op_0/update_FullyConnected_1/b/Cast_2 = Cast[DstT=DT_FLOAT, SrcT=DT_STRING, _class=["loc:@FullyConnected_1/b"], _device="/job:localhost/replica:0/task:0/cpu:0"](Adam/apply_grad_op_0/learning_rate)]]
W tensorflow/core/framework/op_kernel.cc:983] Unimplemented: Cast string to float is not supported
E tensorflow/core/common_runtime/executor.cc:594] Executor failed to create kernel. Unimplemented: Cast string to float is not supported
[[Node: Adam/apply_grad_op_0/update_conv_1/W/Cast_2 = Cast[DstT=DT_FLOAT, SrcT=DT_STRING, _class=["loc:@conv_1/W"], _device="/job:localhost/replica:0/task:0/cpu:0"](Adam/apply_grad_op_0/learning_rate)]]
我正在使用tflearn.data_utils.image_preloader来读取png文件,但我也尝试使用其他一些方法,但似乎总是得到相同的错误。许多研究表明,这可能是由于图像文件不良造成的,但是在拍摄了十几个jpg图像之后我得到了同样的问题,所以它必须是其他的东西。任何建议都会受到赞赏,我的代码在下面,我的git here
上有更大的项目import numpy as np
import tflearn
from tflearn.data_preprocessing import ImagePreprocessing
from tflearn.data_utils import image_preloader
from tflearn.layers.core import input_data, fully_connected, dropout
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.estimator import regression
def train():
training_path = 'images/train'
image_height = 32
image_width = 32
colour_channels = 3
X, Y = image_preloader(
training_path,
image_shape=(image_height, image_width),
mode='folder',
categorical_labels=True,
normalize=True)
X = np.reshape(X, (-1, image_height, image_width, colour_channels))
img_prep = ImagePreprocessing()
img_prep.add_featurewise_zero_center()
img_prep.add_featurewise_stdnorm()
network = input_data(shape=[None, image_height, image_width, colour_channels],
data_preprocessing=img_prep,
name='input')
network = conv_2d(network, 32, 3, activation='relu', name='conv_1')
network = max_pool_2d(network, 2)
network = conv_2d(network, 64, 3, activation='relu', name='conv_2')
network = conv_2d(network, 64, 3, activation='relu', name='conv_3')
network = max_pool_2d(network, 2)
network = fully_connected(network, 512, activation='relu')
network = dropout(network, 0.5)
network = fully_connected(network, 2, activation='softmax')
network = regression(
network,
optimizer='adam',
loss='categorical_crossentropy',
learning_rate='0.001')
model = tflearn.DNN(
network,
checkpoint_path='tmp/tflearn/cnn/checkpoints/model.tflearn',
tensorboard_verbose=3,
tensorboard_dir='tmp/tflearn/cnn/logs/')
model.fit(
X, Y,
validation_set=0.2,
n_epoch=1000,
shuffle=True,
batch_size=100,
run_id='model',
snapshot_epoch=True)
model.save('tmp/tflearn/cnn/model/model_final.tflearn')
答案 0 :(得分:1)
很抱歉迟到的回答(可能会帮助他人)
我遇到了同样的问题,问题出现在您编写的回归代码中
learning_rate='0.001'
但学习率为float
而不是string
,所以只需写一下:
learning_rate = 0.001
它会起作用