一个异常纠结了好久,到处找原因,还好费了半天功夫,真相水落石出:原来文档中早就写清楚了,怎么不看文档!怎么不看文档!怎么不看文档!
事情是这样子的:
我的电脑上目前的环境是这样的:Tensorflow 1.7,CUDA 9.0, CUDNN 7.1。 用这个环境训练agents到目前位置也没出现过什么问题。直到今天,我训练了一个visual observation的agent。训练过程都很正常,没有出现任何错误。当我把brain类型改成Internal,准备再unity中使用训练好的模型时,错误出现了:
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训练的模型和Unity中TFCSharp的版本不匹配,但是不知道具体是什么版本啊!只好google去了。
真相如此,那只能把TF降级到1.4的版本了,但是还不止需要降级TF......还需要降级成配套的CUDA 8.0,以及CUDNN 6.0!这下会搞得其他依赖于cuda的conda环境也要出问题呀!没办法。。。