kleinyuan / tensorflow-yolo-ios Goto Github PK
View Code? Open in Web Editor NEWReal time object detection demo App with Yolo on iOS based on tensorflow framework
License: MIT License
Real time object detection demo App with Yolo on iOS based on tensorflow framework
License: MIT License
First off, thank you for putting this repo together!
In preparation for training my own model on YOLO and converting to TF I wanted to prove out the pattern by taking the TinyYOLO VOC weights/config and recreating the frozen memmapped graph that you provide in this repo. After going through the Darkflow docs as well as Tensorflow for Mobile Poets I came up with the following process for converting the graph. The graph loads and runs on my iPhone; however, it seems to just randomly identify non-objects (typically 20-30 per second) which inevitably runs out of memory and crashes the application. I'll provide the steps I took for converting the graph below. Could you please share how you created your graph or provide some feedback?
BTW, the first big red flag I see is when I freeze the TinyYOLO VOC weights using Darkflow my graph is 61MB, but yours is 180MB?!
Here's my process:
Grab TinyYOLO VOC weights and config (I've used PJ's config as well as yours, there are a few differences):
wget https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/tiny-yolo-voc.cfg
wget https://pjreddie.com/media/files/tiny-yolo-voc.weights
Next I validate that the weights/configs work before freezing:
flow --model tiny-yolo-voc.cfg --load tiny-yolo-voc.weights --gpu 0.9 --json
Next I freeze the graph and validate it still identifies the objects (everything works great):
flow --model tiny-yolo-voc.cfg --load tiny-yolo-voc.weights --savepb --gpu 0.9
flow --pbLoad built_graph/tiny-yolo-voc.pb --metaLoad built_graph/tiny-yolo-voc.meta --imgdir sample_img/ --json --gpu 0.9
Then I optimize the graph for inference and test again (still works):
bazel-bin/tensorflow/python/tools/optimize_for_inference \
--input=/yoloz/tiny/built_graph/tiny-yolo-voc.pb \
--output=/yoloz/tiny/built_graph/optimized_graph.pb \
--input_names=input \
--output_names=output \
--frozen_graph=True
Then I quantize and round the graph and validate (still works, but some accuracy drops as expected):
bazel-bin/tensorflow/tools/quantization/quantize_graph \
--input=/yoloz/tiny/built_graph/optimized_graph.pb \
--output=/yoloz/tiny/built_graph/rounded_graph.pb \
--output_node_names=output \
--mode=weights_rounded
Finally I enable memory mapping in the graph:
bazel-bin/tensorflow/contrib/util/convert_graphdef_memmapped_format \
--in_graph=/yoloz/tiny/built_graph/rounded_graph.pb \
--out_graph=/yoloz/tiny/built_graph/mmapped_graph.pb
I've tried cutting out steps such as quantizing and memory mapping, but I still run into the same issue where it just randomly identifies non-existent objects. Here's an example from the iOS logs of it just seeing tons of non-existent objects:
48 boxes
cow 0.26528638082959 (-716.969760456415, -15.0664010845897, 2253.67373242581, 124.151942685188)
person 60.9147208802824 (406.176437143808, 247.405798095825, 109.771308640561, 79.8200096378618)
sheep 39.6371332656176 (701.706673330065, 173.24449355272, 162.208712026626, 0.201273832795577)
aeroplane 14.7475192095906 (422.813935954874, -672.132180748015, 0.435470956695015, 1851.95653674813)
bottle 34.4575969911148 (-3691.35341221254, 230.732243466384, 7407.03830472379, 118.209991155339)
bottle 15.252358611848 (297.912561621646, 253.622715234777, 103.666117939307, 156.487766640486)
person 2.02568703175324 (-1223.67370049141, 403.496686780806, 2378.22481550453, 17.7921825504054)
person 46.802289779278 (1029.42971074394, 59.8810085550473, 0.0603049292979604, 6.32803476229502)
person 5.02492657361699 (-242.108751411802, -179.995665610159, 768.943885578703, 172.626105837104)
bottle 8.12876115292863 (1.31502027136079, 112.241214824463, 83.795759190395, 137.321676756878)
bottle 17.4926418818899 (-2195.20377769767, 44.7168849437375, 5036.41495845117, 109.233492394215)
bottle 10.0492816390524 (-348.11391411164, -823.872093321802, 1358.45449526415, 976.078075378695)
horse 11.7777611150507 (-5199.91062956631, 209.564810465238, 10445.2793049104, 193.588701516892)
sofa 2.90329754699323 (-580.55927439087, -1201.57429169997, 605.32719492025, 2319.642035421)
sheep 2.31771116209555 (335.281302477022, -265.169598244711, 303.744002610247, 615.620747373669)
bus 10.6498479187201 (-24099.0875846469, -55.1337276379371, 48149.893631693, 531.781720515113)
person 2.18346198169684 (245.163570981687, -659.499791728503, 452.623426099545, 547.663504813206)
tvmonitor 0.347630301506097 (250.864021547363, 230.171159402745, 178.092564045225, 107.932911465985)
bottle 9.95446473408515 (578.688593486094, 225.090434384003, 29.7744054641031, 5.09407076904225)
cow 9.39130423078825 (751.656599451878, 494.282862500461, 1.09127926019101, 0.0376114695453585)
cow 16.8039449513635 (-636.942771411139, -4146.12791663897, 105.520065759871, 8539.38077769234)
cow 15.3530701945051 (10.8899058785902, -2004.09817131406, 28.3976730276271, 4464.49136457081)
cow 6.18686360683682 (-1872.86129217465, 317.97697050232, 4741.10130713052, 5.93505212236634)
cow 41.8923066953403 (-5090.64552303113, -433.732989685124, 11922.7837276564, 842.91523490483)
person 7.01425882730575 (196.017857693368, 10.762791441239, 0.29155214652136, 133.058044741693)
cow 21.7848502025759 (-215.860215658783, -249.177102701316, 267.580321846654, 392.007555619633)
tvmonitor 5.30925632140537 (528.546262539762, 472.202107788961, 27.6917343533151, 152.522967437084)
tvmonitor 5.94156905219603 (565.858886985312, -920.189522495108, 318.533761354198, 2161.87640869381)
bus 8.98683072242511 (-6645.9226178394, 139.156692264233, 14659.6244466323, 374.677935877221)
cow 8.49134918033451 (432.454714344806, -2111.24702880055, 1.80568608554533, 4125.33471449469)
cow 23.8006362877428 (473.681844977678, -9128.2631528842, 239.033443917267, 18220.9025116129)
cow 32.4949977552751 (138.42400573552, -18035.3928847779, 387.916661080797, 36465.6768464101)
person 8.77725236878837 (502.371345131116, 210.051040886286, 42.5160061576193, 20.3697629750902)
diningtable 4.05980503916737 (-2256.01118752883, 343.210714264253, 5658.08545452834, 55.0627622079917)
tvmonitor 10.4713313523678 (-1818.03733710679, 194.896162589751, 4932.72937689972, 177.472580818184)
tvmonitor 12.2691757717801 (-18778.2914532181, 128.871683567611, 37271.2059504048, 29.0849889945601)
pottedplant 14.22723577094 (-28173.1173244905, -208.326447582406, 56501.6760140867, 546.753047487035)
tvmonitor 13.8996401643171 (-11994.0013712802, 370.284081045691, 24092.6758117422, 19.6677094960988)
bottle 24.2488610989835 (-195.202285100031, 385.567696758806, 1132.05653811156, 12.4024115628028)
person 17.197114360953 (-451.579067209645, -418.735144345297, 0.0300114537946303, 1134.27591314155)
Any help you can provide is greatly appreciated! Thanks! π
Hey, @KleinYuan .
Nice work on it :D π
There are a couple of things that's sort of an issue to me.
I installed the tensorflow on Ubuntu 16.04 and trained my own model
referring https://github.com/tensorflow/models/blob/master/object_detection/g3doc/running_locally.md on this.
After that, expert it to pb file,
and replace your 'tiny-yolo-voc.pb', 'vod.txt' with my own 'frozen_inference_graph.pb', 'txt' file.
but i've got error below ...
= = = = = = = = = = = = = = = = = = = =
/tensorflow-yolo-ios/tensorflow-yolo-ios/tensorflow-yolo-ios/tfWrap.mm:72] Loading model with memory mapped
2017-08-26 02:09:12.685433: E /tensorflow-yolo-ios/tensorflow-yolo-ios/tensorflow-yolo-ios/tensorflow_utils.mm:185] MMap failed with Corrupted memmapped model file: /var/containers/Bundle/Application/F9C63DBE-8A8B-44DB-B131-8C36A8B6F0DA/tensorflow-yolo-ios.app/frozen_inference_graph.pb Invalid directory offset
2017-08-26 02:09:12.685496: I /tensorflow-yolo-ios/tensorflow-yolo-ios/tensorflow-yolo-ios/tfWrap.mm:75] Loaded model with memory mapped
2017-08-26 02:09:12.685523: F /tensorflow-yolo-ios/tensorflow-yolo-ios/tensorflow-yolo-ios/tfWrap.mm:82] Couldn't load model: Data loss: Corrupted memmapped model file: /var/containers/Bundle/Application/F9C63DBE-8A8B-44DB-B131-8C36A8B6F0DA/tensorflow-yolo-ios.app/frozen_inference_graph.pb Invalid directory offset
= = = = = = = = = = = = = = = = = = = =
Actually, this model is working properly on Android object detection app.
so i'm really confused.
Is there any tips to generate own pb model for this project ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.