Author Topic: Running YOLO on ODROID: YODROID  (Read 236 times)

0 Members and 1 Guest are viewing this topic.

Offline Flavio58

Running YOLO on ODROID: YODROID
« Reply #1 on: March 13, 2018, 05:06:56 AM »
Advertisement
Running YOLO on ODROID: YODROID


YOLO is a neural network model that is able to recognise everyday objects very quickly from images. There’s also TinyYOLO which runs on mobile devices pretty well. This guide tells you how to get TinyYOLO installed and running on your ODROID XU4. To follow along, log into your ODROID, and run these commands:

Step 1: Install TensorFlow
Update your system
First, we make sure everything is up to date.



Code: [Select]
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y
sudo reboot

Get some swap
Bazel won’t build without this on the ODROID XU4. Pop in a blank 8GB USB drive, which will get erased, and run:

Code: [Select]
sudo blkid
Check the device name, usually /dev/sda1, and with that name, run:

Code: [Select]
sudo mkswap /dev/sda1
sudo swapon /dev/sda1
sudo swapon

Install the requirements
We’ll need real Oracle Java, instead of OpenJDK. I tried OpenJDK, built Bazel with it, but it failed to SHA-1 hash downloads, and so was useless. So, we install:

Code: [Select]
sudo apt-get install pkg-config zip g++ zlib1g-dev unzip
sudo apt-get install gcc-4.8 g++-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 100
sudo apt-get install python-pip python-numpy swig python-dev
sudo pip install wheel
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java8-set-default
java -version

Install Bazel build system
Google builds things using Bazel. TensorFlow is from Google. Thus, we need to build Bazel first. This takes about a half an hour. Go get some lunch.

Code: [Select]
wget https://github.com/bazelbuild/bazel/releases/download/0.5.4/bazel-0.5.4-dist.zip
unzip -d bazel bazel-0.5.4-dist.zip
cd bazel
sudo ./compile.sh

Now, Java will run out of heap here. So, we need to:

Code: [Select]
sudo vi scripts/bootstrap/compile.sh
And find the line with “run” on it, and add some memory flags, changing it to:

Code: [Select]
run “${JAVAC}” -J-Xms256m -J-Xmx384m -classpath “${classpath}” -sourcepath “${sourcepath}” \
And we compile again.

Code: [Select]
sudo ./compile.sh
sudo cp output/bazel /usr/local/bin/bazel

Get TensorFlow
Now we can actually download and configure TensorFlow.

Code: [Select]
git clone --recurse-submodules https://github.com/tensorflow/tensorflow.git
cd tensorflow

I couldn’t get the latest version of TensorFlow to install, it had BoringSSL C99 compile issues, so checkout version 1.4.0, and configure:

Code: [Select]
git checkout tags/v1.4.0
./configure

Say no to most things, including OpenCL:



Build TensorFlow
Then, we build. If you thought Bazel took a long time to build, then you haven’t built software before. Hold on to your hats. We’re in for a ride here.

bazel build -c opt --copt="-mfpu=neon-vfpv4" --copt="-funsafe-math-optimizations" --copt="-ftree-vectorize" --copt="-fomit-frame-pointer" --local_resources 8192,8.0,1.0 --verbose_failures tensorflow/tools/pip_package:build_pip_package
Building…

1,900 / 4,909 files… error.

Oop, NEON doesn’t work. Ok, let’s turn that off. But, we’ll want to fix it later.

bazel build -c opt --copt="-funsafe-math-optimizations" --copt="-ftree-vectorize" --copt="-fomit-frame-pointer" --local_resources 8192,8.0,1.0 --verbose_failures tensorflow/tools/pip_package:build_pip_package
3,700 / 4,622 files… error.

In file included from tensorflow/compiler/xla/service/llvm_ir/llvm_util.cc:30:0:
./tensorflow/core/lib/core/casts.h: In instantiation of 'Dest tensorflow::bit_cast(const Source&) [with Dest = long long int; Source = void (*)(const char*, long long int)]':
tensorflow/compiler/xla/service/llvm_ir/llvm_util.cc:400:67:   required from here
./tensorflow/core/lib/core/casts.h:91:3: error: static assertion failed: Sizes do not match
Alright, XLA is causing problems. It’s new, and not needed. Let’s drop it for now and reconfigure and rebuild without it.

2,345 / 3,683 files…

3,112 / 3,683 files…

3,682 / 3,683 files…

Built!

Target //tensorflow/tools/pip_package:build_pip_package up-to-date:
 bazel-bin/tensorflow/tools/pip_package/build_pip_package
Quick! Install it!

bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
sudo pip2 install /tmp/tensorflow_pkg/tensorflow-1.4.0-cp27-cp27mu-linux_armv7l.whl --upgrade --ignore-installed
See the footnotes for issues here.

Is it real?

python2
>>> import tensorflow
>>> print(tensorflow.__version__)
1.4.0
That feels good. Onto YOLOing.

Step 2: SO YOLO.
I’m sure there are a few implementations of YOLO out there by now. Let’s pick one. This guy seems to know what he’s talking about. Let’s try his stuff.

# Get code
git clone https://github.com/experiencor/basic-yolo-keras.git
cd basic-yolo-keras
# Get weights from https://1drv.ms/f/s!ApLdDEW3ut5fec2OzK4S4RpT-SU
# Or Raccoon: https://1drv.ms/f/s!ApLdDEW3ut5feoZAEUwmSMYdPlY
wget <authurl>/tiny_yolo_features.h5
wget <authurl>/tiny_yolo_raccoon.h5

# Edit config
vi config.json         # Change model to "Tiny Yolo"
# Download a raccoon
wget https://upload.wikimedia.org/wikipedia/commons/b/be/Racoon_in_Vancouver.jpg
# Run
python2 predict.py -c config.json -i Racoon_in_Vancouver.jpg -w tiny_yolo_raccoon.h5
Missing imaug. Ok, looks like we’ll need a few things.

sudo pip2 install imgaug
sudo pip2 install keras
sudo pip2 install h5py
H5py and scipy take a little while to install. Ok, let’s try that again. Can it find a raccoon in this image of a raccoon?


Where is it?
python2 predict.py -c config.json -i Racoon_in_Vancouver.jpg -w tiny_yolo_raccoon.h5
Yes! Now that’s a detected raccoon!


I see you. You can’t hide. From the ODROID.
__________________________________________________________________

Footnotes.
At first when I ran:

sudo pip install /tmp/tensorflow_pkg/tensorflow-1.4.0-cp27-cp27mu-linux_armv7l.whl --upgrade --ignore-installed
It ran using python 3 and failed to install, so after some googling and learning about pip filename rules, I figured it out and just used pip2 instead.

Then, the most fun issue was when I first ran import tensorflow. I got this fun message:

>>> import tensorflow
Traceback (most recent call last):
 File “<stdin>”, line 1, in <module>
 File “tensorflow/__init__.py”, line 24, in <module>
 from tensorflow.python import *
 File “tensorflow/python/__init__.py”, line 49, in <module>
 from tensorflow.python import pywrap_tensorflow
 File “tensorflow/python/pywrap_tensorflow.py”, line 25, in <module>
 from tensorflow.python.platform import self_check
ImportError: No module named platform
Oh no! It’s broken in some way. So I googled the issue, and it seemed to be about locales:

No module named tensorflow.python.platform · Issue #36 · tensorflow/tensorflow

github.com   
So I set a locale first (after also seeing that it needed to be capital US), and rebuilt, and it still gave me the same issue. Hm. I’ll take a look at it tomorrow.

export LC_ALL=en_US.UTF-8
export LANG=en_us.UTF-8
The next day, with fresh googling powers, revealed that actually… it was just that I was just running it in the build directory! It has a directory called tensorflow in it, and python was looking up into that to find things. So just changing directories to another fixed the issue. So easy. Such a fail.

https://hackernoon.com/running-yolo-on-odroid-yolodroid-5a89481ec141


Consulente in Informatica dal 1984

Software automazione, progettazione elettronica, computer vision, intelligenza artificiale, IoT, sicurezza informatica, tecnologie di sicurezza militare, SIGINT. 

Facebook:https://www.facebook.com/flaviobernardotti58
Twitter : https://www.twitter.com/Flavio58

Cell:  +39 366 3416556

f.bernardotti@deeplearningitalia.eu

#deeplearning #computervision #embeddedboard #iot #ai

 

Related Topics

  Subject / Started by Replies Last post
Yolo 3

Started by Flavio58 Darknet

0 Replies
134 Views
Last post June 23, 2018, 11:10:09 PM
by Flavio58
0 Replies
147 Views
Last post July 12, 2018, 10:06:34 AM
by Flavio58
0 Replies
56 Views
Last post October 20, 2018, 04:06:53 AM
by Flavio58
0 Replies
55 Views
Last post October 27, 2018, 02:04:27 AM
by Flavio58
0 Replies
97 Views
Last post February 21, 2019, 12:09:54 PM
by Marco1971

Sitemap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326