Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having problem with tensorflow 2.0.0 : Unimplemented: Cast string to float is not supported #375

Closed
SomyKamble opened this issue Nov 13, 2019 · 2 comments
Labels

Comments

@SomyKamble
Copy link

@SomyKamble SomyKamble commented Nov 13, 2019

history <- model %>% fit(trainx,y_train,epochs=50,batch_size=5,validation_split=0.2)
2019-11-13 18:03:25.393757: W tensorflow/core/framework/op_kernel.cc:1599] OP_REQUIRES failed at cast_op.cc:123 : Unimplemented: Cast string to float is not supported
2019-11-13 18:03:25.396018: E tensorflow/core/common_runtime/executor.cc:642] Executor failed to create kernel. Unimplemented: Cast string to float is not supported
[[{{node Cast}}]]

reticulate::py_config()
python: C:\conda\envs\r-reticulate\python.exe
libpython: C:/conda/envs/r-reticulate/python36.dll
pythonhome: C:\conda\envs\R-RETI1
version: 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 14:00:49) [MSC v.1915 64 bit (AMD64)]
Architecture: 64bit
numpy: C:\conda\envs\R-RETI
1\lib\site-packages\numpy
numpy_version: 1.17.4
tensorflow: C:\conda\envs\R-RETI~1\lib\site-packages\tensorflow_init_.p

python versions found:
C:\conda\envs\r-reticulate\python.exe
C:\Users\somy\AppData\Local\Programs\Python\Python38\python.exe
C:\conda\python.exe
C:\Users\somy\AppData\Local\Programs\Python\Python38\python.exe

tensorflow::tf_config()
TensorFlow v2.0.0 (C:\conda\envs\R-RETI~1\lib\site-packages\tensorflow_init_.p)
Python v3.6 (C:\conda\envs\r-reticulate\python.exe)

@dfalbel
Copy link
Member

@dfalbel dfalbel commented Nov 27, 2019

This looks like a bug in your code. what's trainx? Is it a numeric matrix?

@SomyKamble
Copy link
Author

@SomyKamble SomyKamble commented Nov 27, 2019

Hi @dfalbel ,

Thank you for your reply .
I haved solved the issue, I guess you were right there is a bug in my code :
I request you to please refer to the below R code and share your valuable thoughts for the same.

library(mlbench)
library(keras)

data2<-data(BreastCancer)
data2<-BreastCancer
data2<-na.omit(data2)
data2<-data2[,-1]

for(i in 1:ncol(data2)){
data2[,i]<-as.numeric(as.factor(data2[,i]))
}

data2<-as.matrix(data2)

dim(data2)
data2[,10]<-as.numeric(as.factor(data2[,10]))

split<-sample(1:2,nrow(data2),prob = c(0.8,0.2),replace = T)

train<-data2[split==1,]

test<-data2[split==2,]

trainx<-train[,1:9]

train_y<-as.numeric(as.factor(train[,10]))

train_y<-train_y-1

y_train<- to_categorical(train_y)

testx<-test[,1:9]
test_y<-as.numeric(as.factor(test[,10]))
test_y<-test_y-1
y_test<-to_categorical(test_y)

model<-keras_model_sequential()

model %>%
layer_dense(units =512, activation = 'relu',input_shape = 9) %>%
layer_dense(units = 10, activation = 'relu')%>%
layer_dense(units = 10, activation = 'relu')%>%
layer_dense(units = 2, activation = 'sigmoid')

model %>% compile(
loss='binary_crossentropy',
optimizer='adam',
metrics=c('accuracy')
)

summary(model)

trainx<-as.matrix(trainx)
class(trainx)
history <- model %>% fit(trainx,y_train,epochs=50,batch_size=5,validation_split=0.2)

plot(history)

score <- model %>% evaluate(testx, y_test)

cat('Test loss:', score$loss, "\n")
cat('Test accuracy:', score$acc, "\n")

sam<-predict_classes(model,testx)

library(caret)

table(sam,test_y)
confusionMatrix(table(sam,test_y))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants