一個異常糾結(jié)了好久雪情,到處找原因,還好費了半天功夫鸭巴,真相水落石出:原來文檔中早就寫清楚了眷细,怎么不看文檔!怎么不看文檔鹃祖!怎么不看文檔溪椎!
事情是這樣子的:
我的電腦上目前的環(huán)境是這樣的:Tensorflow 1.7,CUDA 9.0恬口, CUDNN 7.1校读。 用這個環(huán)境訓(xùn)練agents到目前位置也沒出現(xiàn)過什么問題。直到今天祖能,我訓(xùn)練了一個visual observation的agent歉秫。訓(xùn)練過程都很正常,沒有出現(xiàn)任何錯誤芯杀。當(dāng)我把brain類型改成Internal端考,準(zhǔn)備再unity中使用訓(xùn)練好的模型時雅潭,錯誤出現(xiàn)了:
TFException: NodeDef mentions attr 'dilations' not in Op<name=Conv2D; signature=input:T, filter:T -> output:T; attr=T:type,allowed=[DT_HALF, DT_FLOAT]; attr=strides:list(int); attr=use_cudnn_on_gpu:bool,default=true; attr=padding:string,allowed=["SAME", "VALID"]; attr=data_format:string,default="NHWC",allowed=["NHWC", "NCHW"]>; NodeDef: conv2d_2/Conv2D = Conv2D[T=DT_FLOAT, data_format="NHWC", dilations=[1, 1, 1, 1], padding="VALID", strides=[1, 4, 4, 1], use_cudnn_on_gpu=true](visual_observation_0, conv2d_2/kernel/read). (Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.).
TensorFlow.TFStatus.CheckMaybeRaise (TensorFlow.TFStatus incomingStatus, System.Boolean last) (at <6ed6db22f8874deba74ffe3e566039be>:0)
TensorFlow.TFGraph.Import (TensorFlow.TFBuffer graphDef, TensorFlow.TFImportGraphDefOptions options, TensorFlow.TFStatus status) (at <6ed6db22f8874deba74ffe3e566039be>:0)
TensorFlow.TFGraph.Import (System.Byte[] buffer, TensorFlow.TFImportGraphDefOptions options, TensorFlow.TFStatus status) (at <6ed6db22f8874deba74ffe3e566039be>:0)
TensorFlow.TFGraph.Import (System.Byte[] buffer, System.String prefix, TensorFlow.TFStatus status) (at <6ed6db22f8874deba74ffe3e566039be>:0)
CoreBrainInternal.InitializeCoreBrain (Communicator communicator) (at Assets/ML-Agents/Scripts/CoreBrainInternal.cs:123)
Brain.InitializeBrain (Academy aca, Communicator communicator) (at Assets/ML-Agents/Scripts/Brain.cs:209)
Academy.InitializeEnvironment () (at Assets/ML-Agents/Scripts/Academy.cs:230)
Academy.Awake () (at Assets/ML-Agents/Scripts/Academy.cs:208)
跟著錯誤輸出中的stack翻了一遍代碼,感覺沒有問題叭刺亍扶供!Import出錯有可能是TF訓(xùn)練的模型和Unity中TFCSharp的版本不匹配,但是不知道具體是什么版本傲衙鳌椿浓!只好google去了。
最后在ML-Agents的github的issue中終于找到了答案(https://github.com/Unity-Technologies/ml-agents/issues/609):目前只支持TF1.4版本闽晦!我使用TF1.7訓(xùn)練時扳碍,使用了TF1.4中沒有的操作,即錯誤中提到的dilations這種2D卷積操作仙蛉。那為什么以前使用是正常的呢笋敞?因為還沒有用visual observation來訓(xùn)練過。
真相如此荠瘪,那只能把TF降級到1.4的版本了夯巷,但是還不止需要降級TF......還需要降級成配套的CUDA 8.0,以及CUDNN 6.0哀墓!這下會搞得其他依賴于cuda的conda環(huán)境也要出問題呀趁餐!沒辦法。篮绰。后雷。
這么重要的問題,官方文檔應(yīng)該有講胺透鳌臀突!回去扒了扒官方的安裝文檔,果然......https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Installation-Windows.md