使用TensorFlow识别照片中的物体

Posted 熊猫滚滚

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用TensorFlow识别照片中的物体相关的知识,希望对你有一定的参考价值。

1.环境ubuntu14.04.5

安装TensorFlow

官方文档:https://www.tensorflow.org/install/install_linux

sudo pip  install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.0.1-cp27-none-linux_x86_64.whl  

注意:后面的网址根据不同设置而不同:

 1 Python 2.7  
 2   
 3 CPU only:  
 4   
 5 https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.0.1-cp27-none-linux_x86_64.whl  
 6 GPU support:  
 7   
 8 https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.0.1-cp27-none-linux_x86_64.whl  
 9 Note that GPU support requires the NVIDIA hardware and software described in NVIDIA requirements to run TensorFlow with GPU support.  
10   
11 Python 3.4  
12   
13 CPU only:  
14   
15 https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.0.1-cp34-cp34m-linux_x86_64.whl  
16 GPU support:  
17   
18 https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.0.1-cp34-cp34m-linux_x86_64.whl  
19 Note that GPU support requires the NVIDIA hardware and software described in NVIDIA requirements to run TensorFlow with GPU support.  
20   
21 Python 3.5  
22   
23 CPU only:  
24   
25 https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.0.1-cp35-cp35m-linux_x86_64.whl  
26 GPU support:  
27   
28 https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.0.1-cp35-cp35m-linux_x86_64.whl  
29 Note that GPU support requires the NVIDIA hardware and software described in NVIDIA requirements to run TensorFlow with GPU support.  
30   
31 Python 3.6  
32   
33 CPU only:  
34   
35 https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.0.1-cp36-cp36m-linux_x86_64.whl  
36 GPU support:  
37   
38 https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.0.1-cp36-cp36m-linux_x86_64.whl  

我选择了相当于:python2.7 纯CPU

 

自动安装无误,若有安装失败,可能是网络问题,重新执行一遍试试。

也有可能是若干依赖没有装好:先把 各种依赖都安一遍 

下载神经网络模型:http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz

1 mkdir model  
2 tar -xf archive_name.tar -C model/  

下载代码:https://codeload.github.com/tensorflow/models/zip/master

1 unzip models-master.zip  
2 cd models-master/tutorials/image/imagenet/  

其中的classify_image.py是我们实现物体识别的主代码

接下来做几个测试

1 classify_image.py --model_dir /home/usr/model --image_file /home/usr/model/cropped_panda.jpg  
2 classify_image.py --model_dir /home/usr/model --image_file /home/usr/model/testkb.jpg  
3 classify_image.py --model_dir /home/usr/model --image_file /home/usr/model/testmous.jpg  

1 giant panda, panda, panda bear, coon bear, ailuropoda melanoleuca (score = 0.89107)
2 computer keyboard, keypad (score = 0.64016)
3 mouse, computer mouse(score = 0.89453)

 

以上是关于使用TensorFlow识别照片中的物体的主要内容,如果未能解决你的问题,请参考以下文章

业界 | 谷歌开源TensorFlow Object Detection API物体识别系统

深度学习基于tensorflow的小型物体识别训练(数据集:CIFAR-10)

玩转谷歌物体识别API,用TensorFlow和OpenCV打造实时识别应用

在Keras中使用VGG进行物体识别

Tensorflow2.5—入门实践综合篇——物体识别花朵分类猫狗识别风格迁移文本分类

使用 Intel Realsense D415 进行物体识别