1. 程式人生 > >用mobilenet模型跑tensorflow CNN的樣例:image_retrain.py和label_image.py

用mobilenet模型跑tensorflow CNN的樣例:image_retrain.py和label_image.py

系統是 ubuntu 16.04,tensorflow版本是1.6, cuDNN版本是7.0。git clone tensorflow後試著跑了一下image_retrain.py(以下簡稱retrain)和label_image.py(以下簡稱label)。retain訓練新的mobilenet分類器成功,用label測試新分類器也成功。但是用label在tensorflow 1.4以下的環境中測試新分類器中出錯。錯誤提示如下:


> InvalidArgumentError (see above for traceback): 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: import/MobilenetV1/MobilenetV1/Conv2d_0/Conv2D = > Conv2D[T=DT_FLOAT, data_format="NHWC", dilations=[1, 1, 1, 1], > padding="SAME", strides=[1, 2, 2, 1], use_cudnn_on_gpu=true, > _device="/job:localhost/replica:0/task:0/device:GPU:0"](_arg_import/input_0_0/_1, > import/MobilenetV1/Conv2d_0/weights). (Check whether your > GraphDef-interpreting binary is up to date with your > GraphDef-generating binary.). [[Node: > import/MobilenetV1/MobilenetV1/Conv2d_0/Conv2D = Conv2D[T=DT_FLOAT, > data_format="NHWC", dilations=[1, 1, 1, 1], padding="SAME", > strides=[1, 2, 2, 1], use_cudnn_on_gpu=true, > _device="/job:localhost/replica:0/task:0/device:GPU:0"](_arg_import/input_0_0/_1, > import/MobilenetV1/Conv2d_0/weights)]]

而且在tensorflow 1.4的環境下,執行image_retrain.py(更新日期為2018年2月28日)也報錯。
讀程式碼可知,新retain下載的mobilenet地址是
data_url = 'http://download.tensorflow.org/models/mobilenet_v1_2018_02_22/'
舊retrain下載的mobilenet的地址是
data_url = 'http://download.tensorflow.org/models/mobilenet_v1_'
而且根據github上的image_retain.py檔案描述 Modify retrain script to output TFLite compatible quantized models.
大致可以猜測到新的mobilenet由tensorflow 1.6構造,已經不相容tensorflow 1.4了。
所以,由於種種原因不能升級到tensorflow 1.6版本的同學,要把老版本的mobilenet和image_retrain.py留好了。