Function call stack: train_function

25,686

Solution 1

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

Solution 2

add this code before your code

from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSession

config = ConfigProto()
config.gpu_options.allow_growth = True
session = InteractiveSession(config=config)

Solution 3

I had this error when all the y_train (groundtruth values) had the same value (single class). When fixed it and y_train became with several classes, it solved the problem.

Share:
25,686
Pranaswi Reddy
Author by

Pranaswi Reddy

Updated on January 04, 2022

Comments

  • Pranaswi Reddy
    Pranaswi Reddy over 2 years

    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)
    
  • Pranaswi Reddy
    Pranaswi Reddy over 3 years
    Thanks for your quick response.I am working on age prediction from speech signal .There are 2 labels,adult and young in target column.Is this the reason for getting above error .You suggested me to use TensorFlow categorical_coumn function .But i am confused how to use and when i checked for it,i found 2 functions feature_column.embedding_column & feature_column.indicator_column.Now i am confused which one to use .And what exactly is to be done.I will feel it's a great help if u respond.
  • Tou You
    Tou You over 3 years
    Start by the most simple thing: do your inputs (X_train, y_train) contain strings?
  • user
    user almost 3 years
    can you help in this please stackoverflow.com/questions/68225332/…
  • PeJota
    PeJota almost 3 years
    Can you please elaborate on why this would work?