Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function call stack: train_function

I am getting following error while training the functional model created using keras:

File "D:\Age_prediction\testmatrixshape.py", line 34, in <module>
    cnn_lstm.fit(X_train, y_train, batch_size=10, epochs=10)
  File "C:\Users\Pranaswi Reddy\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\keras\engine\training.py", line 66, in _method_wrapper
    return method(self, *args, **kwargs)
  File "C:\Users\Pranaswi Reddy\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\keras\engine\training.py", line 848, in fit
    tmp_logs = train_function(iterator)
  File "C:\Users\Pranaswi Reddy\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\eager\def_function.py", line 580, in __call__
    result = self._call(*args, **kwds)
  File "C:\Users\Pranaswi Reddy\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\eager\def_function.py", line 644, in _call
    return self._stateless_fn(*args, **kwds)
  File "C:\Users\Pranaswi Reddy\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\eager\function.py", line 2420, in __call__
    return graph_function._filtered_call(args, kwargs)  # pylint: disable=protected-access
  File "C:\Users\Pranaswi Reddy\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\eager\function.py", line 1661, in _filtered_call
    return self._call_flat(
  File "C:\Users\Pranaswi Reddy\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\eager\function.py", line 1745, in _call_flat
    return self._build_call_outputs(self._inference_function.call(
  File "C:\Users\Pranaswi Reddy\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\eager\function.py", line 593, in call
    outputs = execute.execute(
  File "C:\Users\Pranaswi Reddy\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\eager\execute.py", line 59, in quick_execute
    tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
tensorflow.python.framework.errors_impl.UnimplementedError:  Cast string to float is not supported
     [[node Cast (defined at D:\Age_prediction\testmatrixshape.py:34) ]] [Op:__inference_train_function_2171]

Function call stack:
train_function

This is my code:

from tensorflow import keras
from tensorflow.keras.layers import Input,Dense,Conv1D,MaxPooling1D,LSTM
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from tensorflow.keras.models import Model


file = pd.read_csv("D:\\Age_prediction\\final_FE.csv", header=None)

file.rename(columns={12:'class'},inplace=True)
y = file['class']
X = file.drop(columns = 'class', axis =1 )
#X=X.values.reshape(X.shape[0],X.shape[1],1)
X_train, X_test, y_train, y_test = train_test_split(X, y,  train_size=None, test_size=0.20, random_state= 6)
X=X_train.values.reshape(X_train.shape[0],X_train.shape[1],1)
X_test=X_test.values.reshape(X_test.shape[0],X_test.shape[1],1)

input_layer=Input(shape=(12,1))
conv1d=Conv1D(filters=64,
              kernel_size=12,
              strides=1,
              padding='causal',
              activation='relu')(input_layer)
pool=MaxPooling1D(pool_size=2,
                   padding='same',
                   strides=1)(conv1d)
lstm=LSTM(25,activation='relu')(pool)
output_layer=Dense(10,activation='softmax')(lstm)
cnn_lstm=Model(inputs=input_layer,outputs=output_layer,name="cnn_lstm")
cnn_lstm.compile(optimizer='adam',loss='binary_crossentropy')
cnn_lstm.summary()

cnn_lstm.fit(X_train, y_train, batch_size=10, epochs=10)
like image 892
Pranaswi Reddy Avatar asked Aug 08 '20 11:08

Pranaswi Reddy


1 Answers

Check that your all input doesn't contain any data of type "string". if so change them e.g. you can use TensorFlow categorical_column_* function

like image 117
Tou You Avatar answered Oct 11 '22 23:10

Tou You