TypeError: Tensor objects are only iterable when eager execution is enabled. To iterate over this t
TypeError: Tensor objects are only iterable when eager execution is enabled. To iterate over this tensor use tf.map_fn.
//錯誤資訊
TypeError Traceback (most recent call last)
<ipython-input-11-f6a31a59ae6e> in <module>()
----> 1 loss3,RMSE_train1,MAE_train1,tv,train_pred_concat,RMSE_train_normalized,MAE_train1_normalized=train_lstm()
2 #print('train_loss:',loss3)
<ipython-input-10-dba5b61ed852> in train_lstm(batch_size, time_step)
83 #訓練集的預測資料和真實資料
84 train_pred_concat=[]
---> 85 train_pred_concat=train_predata(pred_train1)#有可能需要placeholder一下,看執行情況,標準化的訓練集預測資料
86 train_end=len(normalized_train_data)
87 train_y_normalized=normalized_train_data[0:train_end-1,3]
<ipython-input-8-f538bad668c6> in train_predata(pred_traindata, time_step)
19 b=train_pred5[-1].T#取出最後一行,即編號為17495的那行
20 train_pred_concat=tf.concat((train_pred6,b),axis=0)#湊出完整的預測資料(標準化版)
---> 21 pd.DataFrame(train_pred_concat).to_csv('E:\\TF_jupyter\\sht\\bishe_LSTM\\github-LSTM\\足球\\lstm_new\\new_SOC_Untitled14\\train_pred_concat.csv')
22 #print('---return train_pred_concat---')
23 return train_pred_concat
D:\anaconda3\envs\tensorflow\lib\site-packages\pandas\core\frame.py in __init__(self, data, index, columns, dtype, copy)
500 elif isinstance(data, abc.Iterable) and not isinstance(data, (str, bytes)):
501 if not isinstance(data, (abc.Sequence, ExtensionArray)):
--> 502 data = list(data)
503 if len(data) > 0:
504 if is_dataclass(data[0]):
D:\anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py in __iter__(self)
475 if not context.executing_eagerly():
476 raise TypeError(
--> 477 "Tensor objects are only iterable when eager execution is "
478 "enabled. To iterate over this tensor use tf.map_fn.")
479 shape = self._shape_tuple()
TypeError: Tensor objects are only iterable when eager execution is enabled. To iterate over this tensor use tf.map_fn.
解決方法
sess=tf.InteractiveSession()
pd.DataFrame(train_pred_concat.eval()).to_csv('E:\\TF_jupyter\\sht\\bishe_LSTM\\github-LSTM\\足球\\lstm_new\\new_SOC_Untitled14\\train_pred_concat.csv')
分析
由錯誤資訊可以看出,錯誤的地方在pd.DataFrame(train_pred_concat).to_csv(‘E:\TF_jupyter\sht\bishe_LSTM\github-LSTM\足球\lstm_new\new_SOC_Untitled14\train_pred_concat.csv’)
這是因為train_pred_concat是Tensor變數,不能這樣直接儲存,需要.eval()一下才正確,注意括號不能省略,否則不起作用!!!!
歡迎批評指正
相關文章
- TypeError: “ModelBase is not iterable”Error
- tensorflow學習之 Eager execution
- TensorFlow 2.0 的核心功能將是“Eager Execution”
- TensorFlow引入了動態圖機制Eager Execution
- 終於!TensorFlow引入了動態圖機制Eager Execution
- TypeError: only integer scalar arrays can be converted to a scalar indexErrorIndex
- TypeError: can‘t concat str to bytesError
- ORA-38301:can not perform DDL/DML over objects in Recycle BinORMObject
- Iterable介面
- 使用 Eager Execution 編碼並執行圖表:以通過 RevNet 優化程式碼為例優化
- Iterable object of JavaScriptObjectJavaScript
- When you issue "ALTER TABLESPACE xxx READ ONLY",what will oracle do?Oracle
- REST is not enabled. use -rest to turn onREST
- 神經風格遷移:使用 tf.keras 和 Eager Execution,藉助深度學習創作藝術作品Keras深度學習
- Javascript教程(七)iterableJavaScript
- TensorFlow 2.0將把Eager Execution變為預設執行模式,你該轉向動態計算圖了模式
- hibernate list和iterate
- iterate的巢狀使用巢狀
- Tensor與tensor深入分析與異同
- MySQl報錯之@@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_MODE = ONMySql
- ObjectsObject
- ld: -pie can only be used when targeting iOS 4.2 or later clang: error: linker command failed with eiOSErrorAI
- ERROR 1840 (HY000) at line 24: @@GLOBAL.GTID_PURGED can only be set when @@GLOBAError
- 釋出Tensor2Tensor,加快深度學習研究深度學習
- row_number() over,rank() over,dense_rank() over的區別
- python generator iterator和iterable objectPythonObject
- sum()over()和count()over()分析函式函式
- TypeError: object() takes no parametersErrorObject
- Uncaught TypeError: $(...).attr(...) is undefinedErrorUndefined
- TypeError: SizeOnlySource is not a constructorErrorStruct
- Uncaught TypeError: i is not a functionErrorFunction
- over (partition by)
- Import OverImport
- Iterator與Iterable(迭代器與可迭代)
- MySQL報錯Table 'plugin' is read only [ERROR] Can't open the mysql.plugin table.MySqlPluginError
- Can't find the 'libpq-fe.h header when trying to install pg gemHeader
- Troubleshooting when srvctl can't start RAC instance, but sqlplus can start it [ID 844272.1]SQL
- oracle execution planOracle