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
_
これは私のコードです:
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)
_
コードの前にこのコードを追加してください
from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSession
config = ConfigProto()
config.gpu_options.allow_growth = True
session = InteractiveSession(config=config)
_
私の問題は私が同じプログラムの別のシェルを開いたことでした。 2倍のウィンドウをチェックしてみてください。