I'm trying to build a custom CNN classifier for a load of cancer images (.png) using Tensorflow 1.1.0 and TFLearn 0.3.1 by largely following someone else's CNN classifier here, however when I try to fit my model Tensorflow is throwing out the following errors:
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)]]
I am using tflearn.data_utils.image_preloader to read the png files in however I have also tried using a few other approaches but seem to always get the same error back. A lot of research has suggested this may be due to bad image files however I get the same issue after wget'ing a dozen jpg images, so it has to be something else. Any advice would be appreciated, my code is below, with the larger project at my 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')
Sorry for late answer (might help others)
I had the same problem and the problem is in your code for regression u have written
learning_rate='0.001'
But the learning rate is a float
value not a string
so just write :
learning_rate = 0.001
It will work