Kerasで学習させようと思い、実行したところ
Cast string to float is not supportednoのエラーがでます。
CSVを数値にしたと思ったのですが、なかなか改善されません・・・。
そもそもこのエラーは、文字列から数値に変更するだけで問題ないでしょうか?
python
1import numpy as np 2import csv 3from tensorflow.keras.models import Sequential 4from tensorflow.keras.layers import Dense, Input 5 6train_data=[] 7train_label =[] 8test_data = [] 9with open('result.csv') as f: 10 reader = csv.reader(f) 11 for row in reader: 12 train_data.append(row) 13 #train_data = np.array(row) 14 #print(train_data) 15 16with open('resulttime.csv') as f: 17 reader = csv.reader(f) 18 for row in reader: 19 train_label.append(row) 20 21with open('test.csv') as f: 22 reader = csv.reader(f) 23 for row in reader: 24 test_data.append(row) 25 26train_data1 = np.array(train_data) 27train_label1 = np.array(train_label) 28 29# Sequentialモデル使用(Sequentialモデルはレイヤを順に重ねたモデル) 30model = Sequential() 31 32# 全結合層(2層->4層) 33model.add(Dense(4, input_dim=1645, activation="tanh")) 34 35# 結合層(4層->1層):入力次元を省略すると自動的に前の層の出力次元数を引き継ぐ 36model.add(Dense(1, activation="sigmoid")) 37 38# モデルをコンパイル 39model.compile(loss="binary_crossentropy", optimizer="sgd", metrics=["accuracy"]) 40 41model.summary() 42 43#訓練 44model.fit(train_data1,train_label1, epochs=300) 45model.save('model.h5') 46 47
Error
1020-03-17 15:19:13.444838: W tensorflow/core/framework/op_kernel.cc:1632] OP_REQUIRES failed at cast_op.cc:123 : Unimplemented: Cast string to float is not supported 22020-03-17 15:19:13.444987: E tensorflow/core/common_runtime/executor.cc:654] Executor failed to create kernel. Unimplemented: Cast string to float is not supported 3 [[{{node Cast}}]] 4Traceback (most recent call last): 5 File "C:/Users/ishido.y/PycharmProjects/NLC/deeplearning.py", line 44, in <module> 6 model.fit(train_data1,train_label1, epochs=300) 7 File "C:\Users\ishido.y\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 819, in fit 8 use_multiprocessing=use_multiprocessing) 9 File "C:\Users\ishido.y\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py", line 342, in fit 10 total_epochs=epochs) 11 File "C:\Users\ishido.y\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py", line 128, in run_one_epoch 12 batch_outs = execution_function(iterator) 13 File "C:\Users\ishido.y\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training_v2_utils.py", line 98, in execution_function 14 distributed_function(input_fn)) 15 File "C:\Users\ishido.y\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow_core\python\eager\def_function.py", line 568, in __call__ 16 result = self._call(*args, **kwds) 17 File "C:\Users\ishido.y\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow_core\python\eager\def_function.py", line 632, in _call 18 return self._stateless_fn(*args, **kwds) 19 File "C:\Users\ishido.y\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow_core\python\eager\function.py", line 2363, in __call__ 20 return graph_function._filtered_call(args, kwargs) # pylint: disable=protected-access 21 File "C:\Users\ishido.y\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow_core\python\eager\function.py", line 1611, in _filtered_call 22 self.captured_inputs) 23 File "C:\Users\ishido.y\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow_core\python\eager\function.py", line 1692, in _call_flat 24 ctx, args, cancellation_manager=cancellation_manager)) 25 File "C:\Users\ishido.y\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow_core\python\eager\function.py", line 545, in call 26 ctx=ctx) 27 File "C:\Users\ishido.y\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow_core\python\eager\execute.py", line 67, in quick_execute 28 six.raise_from(core._status_to_exception(e.code, message), None) 29 File "<string>", line 3, in raise_from 30tensorflow.python.framework.errors_impl.UnimplementedError: Cast string to float is not supported 31 [[node Cast (defined at /Users/ishido.y/PycharmProjects/NLC/deeplearning.py:44) ]] [Op:__inference_distributed_function_593] 32 33Function call stack: 34distributed_function
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/03/18 07:56