日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

tensorflow环境下的识别食物_在win10环境下进行tensorflow物体识别(ObjectDetection)训练...

發布時間:2023/12/18 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 tensorflow环境下的识别食物_在win10环境下进行tensorflow物体识别(ObjectDetection)训练... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

安裝ObjectDetection,CPU和GPU都需要

解壓module.rar放到C:\TFWS\models目錄

地址:https://github.com/tensorflow/models

解壓protoc-3.6.1-win32.zip,將\bin\protoc.exe復制到C:\Windows\System32下。

地址:https://github.com/protocolbuffers/protobuf/releases

編譯proto文件,需要在power shell下執行。C:\TFWS\models\research目錄下(最前面時PS命令的都在power shell下執行)

cd C:\TFWS\models\research

Get-ChildItem object_detection/protos/*.proto | Resolve-Path -Relative | %{ protoc $_ --python_out=. }

準備slim庫,刪除BUILD文件如果有的話,否則以下會報錯。

cd C:\TFWS\models\research\slim

del BUILD

進入虛擬機環境venv。分別執行以下命令。

cd C:\TFWS\models\research\slim

python setup.py build

python setup.py install

安裝,執行以下命令。(會下載一些依賴,時間可能很長,連接超時可以重新執行)

cd C:\TFWS\models\research

python setup.py build

python setup.py install

安裝開發所需組件。(venv中)

pip install numpy

pip install opencv-python

pip install matplotlib

pip install jupyter

pip?install?-i?https://pypi.tuna.tsinghua.edu.cn/simple?pandas

pip install Pillow

pip install Cython

制作圖片訓練集

安裝windows版本的labelImg_v1.8.1.rar

https://github.com/tzutalin/labelImg

1.準備數據(一旦使用lableimg生成xml后,請勿更改圖片路徑)

分析代碼結構:(可跳過)

C:\TFWS\models\research\object_detection\object_detection_tutorial.ipynb

GitHub官網給出的各種模型:

https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md

人工lableimg標注圖片(越多越好)

Lableimg下載:https://github.com/tzutalin/labelImg

使用方法:

Open dir 打開圖片目錄;

Change save dir更改xml存儲路徑;

Create react box 標注矩形框;快捷鍵 W

Ctrl+S 保存

可以設置默認lable:user the default lable

下一張圖片:D

上一張圖片:A

2.生成TFRecord,xml to csv ,csv to tfrecord。

c:\TFWS\VENVCPU\Scripts\activate

cd C:\TFWS\models\research\object_detection

注意:更改xml_to_csv和csv_to_tfrecord里面的相關路徑(指的是:Lableimg圈出來的圖片以及生成的xml)以及tfrecord中的lable。

python do_xml_to_csv_train.py

python do_xml_to_csv_test.py

生成tfrecord:(注意路徑)

python do_generate_tfrecord.py --csv_input=do_data/pictrain/do_train_labels.csv --output_path=do_data/pictrain/do_train.record --image_path=do_data/pictrain

python do_generate_tfrecord.py --csv_input=do_data/pictest/do_test_labels.csv --output_path=do_data/pictest/do_test.record --image_path=do_data/pictest

3.修改配置文件

下載地址:ssd_mobilenet_v1_coco.config

修改:

PATH_TO_BE_CONFIGURED改為自己的路徑;

更改num_classes;

更改batch_size:1;或者更大(會影響訓練效果,越大效果越穩定,但時間更久)

建議注釋一下兩行:

#fine_tune_checkpoint: "C:\\TFWS\\models\\research\\object_detection\\do_data\\training\\model.ckpt"

#from_detection_checkpoint: true

更改完成后在training目錄下創建:do_label_map_pbtxt文件,寫標簽配置,例如:兩個標簽對應num classes應該為2

item {

id: 1

name: 'keyboard'

}

item {

id: 2

name: 'mouse'

}

4.開始訓練。(venv中,重復測試請刪除其他文件 除了do_label_map_pbtxt和ssd_mobilenet_v1_coco.config文件)

cd C:\TFWS\models\research\object_detection\legacy

python train.py --logtostderr --train_dir=C:\TFWS\models\research\object_detection\do_data\training --pipeline_config_path=C:\TFWS\models\research\object_detection\do_data\training\ssd_mobilenet_v1_coco.config

中途打斷可以繼續輸入上述命令,會從上次的checkpoint繼續執行。

5.導出模型(重復導出請刪除result內全部內容)。

cd C:\TFWS\models\research\object_detection

python export_inference_graph.py \ --input_type image_tensor \? --pipeline_config_path? do_data\training\ssd_mobilenet_v1_coco.config \? --trained_checkpoint_prefix ?do_data\training\model.ckpt-500 \? --output_directory do_data\result

6.測試模型。

更改testpb.py里面的路徑相關參數。

cd C:\TFWS\models\research\object_detection

python testpb.py? # 該文件測試模型并且輸出到img標注。需要注意目錄結構。在do_data文件夾下新建img文件夾,測試圖片放入。可能需要更改Num_classes.

總結

以上是生活随笔為你收集整理的tensorflow环境下的识别食物_在win10环境下进行tensorflow物体识别(ObjectDetection)训练...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。