实例介绍
在ubuntu系统上,tensorflow 的安装、图像识别应用、训练自己的图像识别模型。2016年版本。
00 imagenet ensortiov G tr mp imagenet 位置 二进制可 音王文件夹 桌面 classify Imag crapped panda. Jpg Imagenet 2512 magenet_synset. Inceptlon-2015-12- insorflow graph def pb lence labe to human label 05. bgz H视频 map proto. pbtxt map. txt 白图片 口文档 leso ulrelgurel-desktop: -/tensornow/tensortlow/models/Image/r 忘下载 LICENsE Lifeiglifei-desktop: -/tensorf low/tensorfLow/madels/image/ inagenets python classi d音乐 u tensorflow/core/framework /op_def_util. cc: 332] Op BatchNormwithclobaLNormalizot 画回攻站 is deprecated. It wiLL cease to work in GraphDet version 9. Use tr nn. batch 设备 giant panda, panda, panda bear, coan bear, Ailuropoda melanoleuca (score =0.892 回计机 indri, indris, Indri indri, Indri brevicaudatus (score =0.00859 网超 Lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens (score a e. 浏览则络 e264 l/example custard apple (score-000111) 旦连按到服务睡 ear thstdr(score LitetQlitet-desktop: -/tensor low/tensor Low/made ls/trage/tmagenets 2.C++AP的用法 下载数据集: s cd"/tensorfloy swgethttps://storage.googleapis.com/download.tensorflow.org/models/inceptiondec_2015.zip-otensorflow/examples/label_image/data/inceptiondec_2015.zip S unzip tensorflow/examples/label image/ data/inception dec 2015.zip-d tensorflow/ examples/label image /data/ 编译例程 label image的C++代码: s bazel build tensorflow/examples/label image/. 运亻 sbazel-bin/tensorflow/examples/label_image/label_image 该例程对默认图像的识别结果如下: 位置 ⊙晶近使用的 grace hopper pg imagenet comp inception dec tensorfiow 画康面 graph label 2015.zip inception graph. pb H视频 白图片 o90 lifeiolifei-desktop:-/bensorflow lifetelitet-desktop:s cd -/tensorflowl 下载 lifetolifet-desktop:-/tensorrlows bazelbin/tensor fLow/examples/Label_tmage/tabe tmage 引乐 tensor flow/core/framework/op def util. cc: 3321 op BatchNormw i thGlobalNormaltzat 回收站 ion is deprecated. It will cease ta work in GraphDef version 9. Use tf, nn, batch normalization( 设督 tensor flow/examples/label_image/rain. cc: 205] military uniform (865):0.647298 回计算机 tensor fLow/exer ples/label_image frain. cc: 2053 suit(794): 0.0477195 tensor flow/examples/label_image/rain. cc: 205] academic gown(B96):0.0232406 园络 tensor flow/exar ples/label_imagerain. cc: 205] bow tie(817):0.0157355 tensor f1。w/ examples/ Label阳 age/raIn.cc:2051boL。tte(948):0.0145024 浏宽网络 lifetelifet-desktop:-/tensorflows 挥接到酮务 冂见,该例程确的识別出了画面中的多和元素。 还可以用来识别自己提供的图像,将图像放在~ tensorflow日录下: S bazel-bintensorflow/examples/label_imagelabel_image -image=womensoldier png 1ee0 lifeiolifei-desktop:-/tensorflow tensorflou/exampLes/label image/rain. cc: 295] spotlight (593):0.0927165 tensorflow/exampLes/label image/rain. cc: 285] groom (848):0.6199024 《上张》下张口國图5¢ tensorf low/examples/label image/rain. cc: 295] lotion (894):0.9182831 ifeiglifei-desktop:-/tensorflows bazel-bin/ tensarflow/examples/label_ inage/labe w tensorflowcore/ frar eworkyop-def_util. cc: 332] cp BatchNornkl thGlobalNorralizat ton is deprecated. It wilL cease to work in GraphDet version 9.Use tt. nn.batch I tensorflow/exampLes/label_inage/rain. cC: 2951 jelLyfish(647):0.28619 tensor low/exampLes mage/rain. CC: 21 4466 tensorflow/exampLes/label image/rain.cc hower cap (868): 0.0415869 ensorflow/exampLes/label image/rain. cc1 285] dugong (193):0.9399437 nsorflow/examples/label_ image/main. cc: 295] electric ray (145): 0.0173142 sktop: /tcnsorflows bazcL-bin tenscrflow/examples/labclinagc/ labc magc=wonensoldter Jp ion is deprecated. It wilt cease to work in Gr aphDef version 9. Use Lf.nn. batch I tensor low/examp Les/labeL_image/rain. cc: 295] military unitar(866): 6.404335 I tensorflow/exampLes/label image/main. cc: 2351 bearskin(849):a.107544 I tensorflow/examples/label_image/rain. cc: 235] coho (418):0.0230596 I tensorflowexamples/label_image/rain. cc: 235] assault rifle (510):3.022492 526×333像素41.3KB99% 第11张,共11张 0.8158589 可见,仍然识別出了图像中的主要元素。 三、训练自己的图像识别模型 使用了 Image retrain例程,编译: S cd /tensorflow s bazel build tensorflow/ examples/image retraining retrain 在 python脚本注释中可以查看对自行添加图像的月录放置要求: /tensorflow/tensorflow/examples/image training/retrain. py 我收集∫网终上一些于势图像,第一类是心形动作,其他于势都放入 other分类。图像文件放置的位置是 /gestrue_photos/heart /gestrue photos other 图像名字简单为好,例如:h1jpg、h2jpg… 子日录名就是分类的名字 行 s bazel-bin/tensorflow/examples/image_ retraining/retrain --image dir /gestrue_ photos 该脚本首先会下载官方数据集。同上,若下载不成功则需要手动下载,链接在上述 retrain.py文件中,下载默认位置为/tmp/ magenet,数据集为 inception-2015-12-05.tgz 训练过程: lifeigplifei-nspiron-N4030: /te nsorFlow 2616-16-2512:21:25,641623 p3940: Train accuracy=100.3% 2016-10-2512:27:25,.041749step394; Cross entropy=0.60282合 tep 3940: validation accuracy 261100391! step 3950: Train accuracy 2015:10-2512:2726.106511:5tep3950: Cross en tropy=0.081973 92813行6吃7的6,31219送3956: validation accuracy1% 86动tEp3 seeretropyna录的 strain的phom 201t22229251回了年轨新男外次之后住该径下将 2616-16 28.189378:5tep3976: cross entropy=6.002114 2016-10-2512:27:28.273827:step3976: VaLidation accuracy=166.% 261610-2512:27:29.244303:step3986: Train accuracv=100.8% 2616-10-2512:27:29.24442e:step398: Cross en tropy=0.01983 2016-10-2512:2729323593:5tep398: alidation accuracy=100,0% 20616-10-2512:27:36,365579:step3998: validaTion accur acy=16.% 261618-2512:27:31.225248:Step3999: Train accuracy=16.8% 2616-10-2512:27:31.225377:step3999: Cross entropy=0.661932 2616-102512:27:31.314361:5te399 validation accuracy=10,B%快速回 Final test accuracy=82.8% Converted 2 variables to const ops 训练完毕后,有/tmp下生成两个文件 output graph. pb和 output labels.txt,分别是训练后的图结构和到分类标签的映射。 得到这两个文件后即可用于对自己的图像进行识別,使用茄子大头贴和笔记本摄像头拍摄自己的心形手势照片: cd"/tensorflow sbazel-bin/tensorflow/examples/ label image/label image graph=/tmp/output_ graph. pb --labels=/tmp/output labels. txt --output layer=final result image=SHOME/+/Webcam/2016-10-25-133534 jpg 识別结果 国(1%)4)10月25日15:150 2002139 = 日回图 譬 h3. h5. jpg h6.jpg h7. jpg h10. jpg hi1.jp h12.jpg h13 pg h14 x-+ lifeioLiIfeH-nspiron-N4030:"/tensorflow hin e. [[ file- reader Readfile[_ device=" /job.localhost/replica:a/task: e LgLifct-Inspilron-N4030: -/tensor f Lows bazcl-bin'tensor flow/examples/LabeL_ima tmp/output b Labels/ tmp/output Labels. txt ou bca/2616 133534.1pg 40×480像素37.0KB69% 第1张,共1 ensor Low/core/fanwork/o cc:968」Mot d: /hame/Lifel/Webcam/2016 卫连接副服 ncpg 534.jP5.jpg ⊙o ensorflow/core/framework/op kerneL. cc: 968] Not found: /hame/Ltfet/webcam/2016 W tensorfLow/core/framework/op_ kerneL.cc: 968] Not found: /hame/lifei/Webcam/2016 16-25·133534.jpg tensorflow/examples/LabeL_image/matn CC: 296] Not found: /home lifet/Webcam/201 6-1-25-133534 ode: file_ reader= ReadFile[ device="/job: localhost /replica: e/ task: e /cpu: 0"1(Const/Canst ifeiglifet- Inspiron-N4030:-/tensorflows bazel-bini'tensorflow/examples/label_ima label in graph=/tmp/output_graph. pb--Labels=/tmp/output_labels, txt Lput_Layer=finaL_result-image=SHOME/EH/Webcam/2016-16-25-133534jpy W tensorflow/core/ framework/op_def_util. cc: 3321 op BatchNornwithGlabalNormaliza ion is deprecated. It will cease to work in GraphDef wersion 9. Use tf. nn.batch I tensorfLowexamples /Label_image/main. cc: 205] other(1):0.966414 I tensorflow/examples/label image/ main. cc: 205] heart (0):0.0335862 lifeielifet- Insptiron-N4030: -/tensor flows 可见,完全识别错了 原因是,深度学习对输入训练数据要求较高:特征鲜明、栉本数昰大、图像要代表性,每一个別至少要冇100张输入。 四、训练自己的图像识别模型(官方的花卉识别数据集) 下载数据集 scurl-ohttp://download.tensorflow.org/exampleimages_/flowerphotostgz Star xzf flower_ photos. tg 该数据集包含了 daisy、 dandelion、 roses、 sunflowers、 tulips尢种花卉,每种提供了600~900张照片。 训练 S bazel-bin/tensorflow/examples/image retraining/retrain--image dir"/flower photos 在旧DELL笔记本(CPU为M480)上的训练时问约为24小时 训练完毕后即可识别 sbazel-bin/tensorflow/examples/label image/label image graph=/tmp/output_graph. pb --labels=/tmp/output labels. txt output layer=final result\ --image=SHOME/flower_photos/daisy/21652746_cc379e0eea_m. jpg 识別结果 ifeigLifei-InspironnN4030: -/tensorfLows bazel-bin/tensorflow/examples/label_imal ge/Label_image >s/u:graph=/tmp /outputmgraph pbl--Labels=/tmp/output Labels. txt A age=sHoE/flowe os/daisy/21652746 cc379eeeea jpg tensorflow/core/framework/op-def_util. cc: 332] op BatchNormwithGLobalNormalizat ion is deprecated. It wilL cease to work in GraphDef version 9. Use tf. nn. batch llization() I tensorflow/examples/label image/main. cc: 205l daisy (4):0.997822 I tensorf Low/examp les/Label_image/main. cc: 205] sunfLowers (3): 0.0015008 I tensorflow/examples/label image/main. cc: 205] dandelion (2): 0.000432897 I tensorflow/examplesLabel_ image/ main. cc: 205] tulips(o):0.00016656 I tensor Low/exampLes/labe mage/main. cc: 205] roses (1):7.79277e-05 lifeiglifei-Insptron-N4030 /tensor Lows 可见,能够很好的识别出 dasiy Tensorflow基本的使用规则就是,需要大量的训练数据: dandelion Q正使用的 主文件大 8684108 981921 10143973 10691189 □血 hid?raf n.: 2928dsf6r6 n. jpg 6h51555d2f n.jpg 4r Holab268 m pg 3de 463364 m jpg aH5764b22d n jpg 2cac18B34 Ipy 6a371b07-jpr 祖 自图 下 Oaf057c4ea, jp 2488a83Bcc rjps 5Ca340b473 m ipq ebd7c7abba n, ipg f03e867Ea7 m jpg 3e7452c5b2 n jpg 2a2e646a8 m. jpg 49 2F6c159oe5. jpg 661585G5 n pg 回收站 设备 D ubuntu 14.0A 国计算机 xA63B91ff_m. Pg 7615bea r. Jpg 53ed1d25a9 ]pg ed 卫浏览阿络 旦连接H器 9e3bdo9fD. jpg n jpg dzodcoofar_. jpg 5d81d355%d d/darbo n.jpg 145173475 t/c 6341ee n JFg d24346t20 jpg F305574d97. pg 44d bcen. jpg 21adaf 4: 21.jpg H5)80 125/f_n jpg 55h 12)aeac_n- jpg = 77851562 253622355 3203b69jpq E055fcb4 jpa n.jpg 8fa1710431 m jpg b2622b4238 r jpg d72504a7/d njpq 93a0143f6.jpg c19801752cpq dda66<5338 m pg d77br4d515-1 7be3rboa7叫pq 7oba8rac n jpg 519b781dc9 m jpg c5r3erc71 m ecB9115319pg 5ddrebc116 m pq E9101bocec n Ipq 越3757 err. pc 当题 77207005 E85159 91 cs/nelf_ n jpg2器39mj9阳331d0mjg2 bfd 73605 nl jps07 dscam jpg想22cj4出50d1 I'.Jpg 234jp61jpg 签 -ac200 E1DA1工 李飞 sume.cn@aliyun.com 2016年10月26囗 【实例截图】
【核心代码】
标签:
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论