美文网首页
人工智能ImageAI体验实录

人工智能ImageAI体验实录

作者: HackerTao | 来源:发表于2019-01-24 06:30 被阅读0次

前言
尝试
第一次尝试
第二次尝试
第三次尝试
总结

前言

本机环境

windows 7
python 3.7.1rc1
pycharm 2018.2.4

ImageAI的Git仓库
ImageAI 中文文档

第三次尝试最终成功,效果图


timg.jpg
timgnew.jpg

尝试

按照官方文档
python的版本要求3.5.1以上
安装tensorflow,要求tensorflow1.4以上

pip3 install --upgrade tensorflow 

第一次尝试

C:\Users\hackertao>python -V
Python 3.7.1rc1

C:\Users\hackertao>pip -V
pip 10.0.1 from c:\users\hackertao\appdata\local\programs\python\python37\lib\site-packages\pip (python 3.7)

C:\Users\hackertao>pip install --upgrade tensorflow
Collecting tensorflow
  Could not find a version that satisfies the requirement tensorflow (fromversions: )
No matching distribution found for tensorflow

第二次尝试

根据网上说明从https://www.lfd.uci.edu/~gohlke/pythonlibs/#tensorflow下载tensorflow‑1.9.0‑cp37‑cp37m‑win_amd64.whl,安装成功,但运行报错。

第三次尝试

重新下载安装python3.6,并修改系统变量指向新安装的路径

C:\Users\hackertao>python -V
Python 3.6.8

C:\Users\hackertao>pip -V
pip 19.0 from c:\users\hackertao\appdata\local\programs\python\python36\lib\site
n 3.6)

C:\Users\hackertao>pip list
Package    Version
---------- -------
pip        19.0
setuptools 40.6.2
C:\Users\hackertao>d:

D:\>cd tools

D:\tools>mkdir testai

D:\tools>dir
 驱动器 D 中的卷是 NewDisk
 卷的序列号是 2061-1ACA
 D:\tools 的目录
2019/01/24  05:53    <DIR>          .
2019/01/24  05:53    <DIR>          ..
2019/01/24  05:53    <DIR>          testai

D:\tools>cd testai

D:\tools\testai>python -m venv venv

D:\tools\testai>dir
 驱动器 D 中的卷是 NewDisk
 卷的序列号是 2061-1ACA

 D:\tools\testai 的目录

2019/01/24  05:54    <DIR>          .
2019/01/24  05:54    <DIR>          ..
2019/01/24  05:54    <DIR>          venv
               0 个文件              0 字节
               3 个目录 371,119,284,224 可用字节
D:\tools\testai>venv\Scripts\activate.bat

#弹出新的窗口
(venv) D:\tools\testai>python -V
Python 3.6.8

(venv) D:\tools\testai>pip list
Package    Version
---------- -------
pip        18.1
setuptools 40.6.2
You are using pip version 18.1, however version 19.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

(venv) D:\tools\testai>python -m pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/46/dc/7fd5df840efb3e56c8b4f768793a237ec4ee5989
1959d6a215d63f727023/pip-19.0.1-py2.py3-none-any.whl (1.4MB)
238kB/s eta 0:00:01
    100% |████████████████████████████████| 1.4MB 234kB/s
Installing collected packages: pip
  Found existing installation: pip 18.1
    Uninstalling pip-18.1:
      Successfully uninstalled pip-18.1
Successfully installed pip-19.0.1

新建一个文件requirement.txt,内容如下

tensorflow==1.12.0
numpy==1.16.0
scipy==1.2.0
opencv-python==4.0.0.21
Pillow==5.4.1
matplotlib==3.0.2
h5py==2.9.0
Keras==2.2.4

继续上面的操作

(venv) D:\tools\testai>dir
 D:\tools\testai 的目录
2019/01/24  06:04    <DIR>          .
2019/01/24  06:04    <DIR>          ..
2019/01/23  06:11               135 requirement.txt
2019/01/24  05:54    <DIR>          venv

(venv) D:\tools\testai>pip install -r requirement.txt
#等安装完成即可
(venv) D:\tools\testai>pip list
Package             Version
------------------- --------
absl-py             0.7.0
astor               0.7.1
cycler              0.10.0
gast                0.2.2
grpcio              1.18.0
h5py                2.9.0
Keras               2.2.4
Keras-Applications  1.0.6
Keras-Preprocessing 1.0.5
kiwisolver          1.0.1
Markdown            3.0.1
matplotlib          3.0.2
numpy               1.16.0
opencv-python       4.0.0.21
Pillow              5.4.1
pip                 19.0.1
protobuf            3.6.1
pyparsing           2.3.1
python-dateutil     2.7.5
PyYAML              3.13
scipy               1.2.0
setuptools          40.6.2
six                 1.12.0
tensorboard         1.12.2
tensorflow          1.12.0
termcolor           1.1.0
Werkzeug            0.14.1
wheel               0.32.3
(venv) D:\tools\testai>pip install https://github.com/OlafenwaMoses/ImageAI/releases/download/2.0.2/
imageai-2.0.2-py3-none-any.whl
Collecting imageai==2.0.2 from https://github.com/OlafenwaMoses/ImageAI/releases/download/2.0.2/imag
eai-2.0.2-py3-none-any.whl
  Downloading https://github.com/OlafenwaMoses/ImageAI/releases/download/2.0.2/imageai-2.0.2-py3-non
e-any.whl (151kB)
    100% |████████████████████████████████| 153kB 176kB/s
Installing collected packages: imageai
Successfully installed imageai-2.0.2

下载https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/resnet50_coco_best_v2.0.1.h5放到项目根路径下

新建FirstDection.py

# coding:utf-8
from imageai.Detection import ObjectDetection
import os

execution_path = os.getcwd()

detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath(os.path.join(execution_path, "resnet50_coco_best_v2.0.1.h5"))
detector.loadModel()
detector = detector.detectObjectsFromImage(input_image=os.path.join(execution_path, "timg.jpg"), output_image_path=os.path.join(execution_path, "timgnew.jpg"))

for eachObject in detector:
     print(eachObject["name"] , " : " , eachObject["percentage_probability"], " : ", eachObject["box_points"] )

到网上下载一张图片并重名名为timg.jpg,或者修改FirstDection.py里的文件名


timg.jpg
(venv) D:\tools\testai>dir
 D:\tools\testai 的目录
2019/01/24  06:13    <DIR>          .
2019/01/24  06:13    <DIR>          ..
2019/01/23  07:34               551 FirstDection.py
2019/01/23  06:11               135 requirement.txt
2019/01/23  07:17       152,661,008 resnet50_coco_best_v2.0.1.h5
2019/01/23  05:31            38,260 timg.jpg
2019/01/24  05:54    <DIR>          venv

(venv) D:\tools\testai>python FirstDection.py
Using TensorFlow backend.
2019-01-24 06:20:36.800210: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports i
nstructions that this TensorFlow binary was not compiled to use: AVX2
car  :  59.85320806503296  :  [141 136 167 158]
truck  :  55.627310276031494  :  [ 76 125 104 154]
bus  :  56.11525774002075  :  [177 130 211 163]
person  :  72.99579977989197  :  [101 133 120 198]
person  :  74.8095691204071  :  [121 129 141 196]
car  :  74.34787154197693  :  [  0 137  24 201]
truck  :  64.91233706474304  :  [  1  97  60 168]
car  :  71.6873824596405  :  [323 133 408 198]
truck  :  53.766125440597534  :  [424 127 499 213]
truck  :  50.21634101867676  :  [214  56 330 201]
person  :  86.6084635257721  :  [325 135 467 330]

(venv) D:\tools\testai>dir

 D:\tools\testai 的目录

2019/01/24  06:17    <DIR>          .
2019/01/24  06:17    <DIR>          ..
2019/01/24  06:20               585 FirstDection.py
2019/01/23  06:11               135 requirement.txt
2019/01/23  07:17       152,661,008 resnet50_coco_best_v2.0.1.h5
2019/01/23  05:31            38,260 timg.jpg
2019/01/24  06:17           101,934 timgnew.jpg
2019/01/24  05:54    <DIR>          venv

timgnew.jpg

总结

这只是图片识别的示例代码,更多的请大家移步github仓库或中文网站的说明,主要在搭建环境中耗费很多的时间,官方文档在安装这块的说明不严谨导致的。

相关文章

  • 人工智能ImageAI体验实录

    前言尝试第一次尝试第二次尝试第三次尝试总结 前言 本机环境 ImageAI的Git仓库ImageAI 中文文档 第...

  • ImageAi初体验

    识别结果: person : 99.87643957138062 是人的概率99.87643957138062 识...

  • 10行代码让你轻松搞定对象检测

    摘要:十行代码轻松搞定对象检测?快来看看如何使用ImageAI。 计算机视觉是人工智能领域中最重要的一个分支。计算...

  • ImageAI:自定义预测模型训练

    ImageAI:自定义预测模型训练 ImageAI 提供4种不同的算法及模型来执行自定义预测模型训练,通过以下简单...

  • ImageAI:对象检测

    ImageAI 提供了非常方便和强大的方法来对图像执行对象检测并从图像中提取每个对象。目前仅支持当前最先进的 Re...

  • ImageAI:图像预测

    ImageAI 提供4种不同的算法及模型来执行图像预测,通过以下简单几个步骤即可对任何图片执行图像预测。提供用于图...

  • ImageAI的安装

    依赖 在应用程序开发中使用ImageAI之前必须安装以下依赖项: python (使用3.7.7,不要使用pyth...

  • 人工智能课程走进科技

    人工智能应用场景体验,人工智能教学和开发工具,人工智能辅助教学和学习用具等智能产品供所有学生体验,人工智能教师培训...

  • 10 行Python 代码,实现 AI 目标检测技术,真给力!

    只需10行Python代码,我们就能实现计算机视觉中目标检测。 from imageai.Detection im...

  • 翻译界的人工智能,真的是狼来了吗?

    魔脑神笔——新型人工智能产品,多国语言同声翻译的流畅体验。他着重于为个人服务带来随身的翻译体验。 人工智能并非镜花...

网友评论

      本文标题:人工智能ImageAI体验实录

      本文链接:https://www.haomeiwen.com/subject/mgvejqtx.html