gpt4 book ai didi

python - Tensorflow Executor 无法创建内核。未实现: Cast string to float is not supported

转载 作者:太空宇宙 更新时间:2023-11-03 15:09:22 25 4
gpt4 key购买 nike

我正在尝试使用 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 文件,但是我也尝试过使用其他一些方法,但似乎总是得到相同的错误。许多研究表明这可能是由于图像文件损坏造成的,但是在 wget'ing 十几个 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')

最佳答案

抱歉回答晚了(可能对其他人有帮助)

我遇到了同样的问题,问题出在你编写的回归代码中

learning_rate='0.001'

但是学习率是一个float值而不是string所以只需写:

learning_rate = 0.001

它会起作用

关于python - Tensorflow Executor 无法创建内核。未实现: Cast string to float is not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44356424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com