Inception-v3 is trained for the ImageNet Large Visual Recognition Challenge using the data from 2012. This is a standard task in computer vision, where models try to classify entire images into 1000 classes, like "Zebra", "Dalmatian", and "Dishwasher".
先下载Inception-V3模型到任意目录中,并解压出来:
mkdir ~/tensorflow-related/model
cd
~/tensorflow-related/model
wget http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz
tar xf inception-2015-12-05.tgz
cd
/usr/lib/python3.5/site-packages/tensorflow/models/image/imagenet
python3.5 classify_image.py --model_dir /root/tensorflow-related/model --image_file /root/tensorflow-related/
test
-images/mobike.jpg
/usr/lib/python3.5/site-packages/tensorflow/python/ops/array_ops.py:1750: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future
result_shape.insert(dim, 1)
W tensorflow/core/framework/op_def_util.cc:332] Op BatchNormWithGlobalNormalization is deprecated. It will cease to work in GraphDef version 9. Use tf.nn.batch_normalization().
bicycle-built-for-two, tandem bicycle, tandem (score = 0.33731)
tricycle, trike, velocipede (score = 0.16082)
unicycle, monocycle (score = 0.12926)
mountain bike, all-terrain bike, off-roader (score = 0.10689)
parking meter (score = 0.01563)
[root@alarmpi imagenet]# python3.5 classify_image.py --model_dir /root/tensorflow-related/model --image_file /root/tensorflow-related/test-images/mobike.jpg
/usr/lib/python3.5/site-packages/tensorflow/python/ops/array_ops.py:1750: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future
result_shape.insert(dim, 1)
W tensorflow/core/framework/op_def_util.cc:332] Op BatchNormWithGlobalNormalization is deprecated. It will cease to work in GraphDef version 9. Use tf.nn.batch_normalization().
mountain bike, all-terrain bike, off-roader (score = 0.56671)
tricycle, trike, velocipede (score = 0.12035)
bicycle-built-for-two, tandem bicycle, tandem (score = 0.08768)
lawn mower, mower (score = 0.00651)
alp (score = 0.00387)
可见,TensorFlow认为图片是山地自行车(mountain bike)/全地形自行车(all-terrain bike)/越野车(off-roader)的概率是0.56671,识别结果还算可以。
文章来源:
http://www.codelast.com/
『5』
计算速度问题
上面的一次图像识别试验,总共花了50多秒的时间!这么慢的速度在实际应用中基本没有实用价值。
但实际上,这个时间是可以大幅缩短的。