Unity ML-Agents 抛出TFException

一个异常纠结了好久,到处找原因,还好费了半天功夫,真相水落石出:原来文档中早就写清楚了,怎么不看文档!怎么不看文档!怎么不看文档!
事情是这样子的:
我的电脑上目前的环境是这样的:Tensorflow 1.7,CUDA 9.0, CUDNN 7.1。 用这个环境训练agents到目前位置也没出现过什么问题。直到今天,我训练了一个visual observation的agent。训练过程都很正常,没有出现任何错误。当我把brain类型改成Internal,准备再unity中使用训练好的模型时,错误出现了:

TFException: NodeDef mentions attr 'dilations' not in Op 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训练的模型和Unity中TFCSharp的版本不匹配,但是不知道具体是什么版本啊!只好google去了。

最后在ML-Agents的github的issue中终于找到了答案(https://github.com/Unity-Technologies/ml-agents/issues/609):目前只支持TF1.4版本!我使用TF1.7训练时,使用了TF1.4中没有的操作,即错误中提到的dilations这种2D卷积操作。那为什么以前使用是正常的呢?因为还没有用visual observation来训练过。

真相如此,那只能把TF降级到1.4的版本了,但是还不止需要降级TF......还需要降级成配套的CUDA 8.0,以及CUDNN 6.0!这下会搞得其他依赖于cuda的conda环境也要出问题呀!没办法。。。

这么重要的问题,官方文档应该有讲啊!回去扒了扒官方的安装文档,果然......https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Installation-Windows.md

你可能感兴趣的:(Unity ML-Agents 抛出TFException)