author | non-mainstream

Products | AI Technology base




Wage does not rise , INVISTA GPU The price of . therefore , One more competitor , It's always good .




recently ,Google Announce launch for ROCm GPU Of TensorFlow v1.8, These include Radeon Instinct MI25. about AMD
In terms of in-depth learning acceleration work in progress , This is a major milestone .




ROCm  Namely Radeon Open ecosystem (Radeon Open Ecosystem), It's us Linux Go up GPU Open source software foundation of computing . and
TensorFlow Implementation uses  MIOpen, This is a high optimization for deep learning GPU Routine Library .




AMD Provides a pre built  whl  software package , The installation process is simple , Similar to installation Linux currency TensorFlow. at present Google Installation instructions and pre built
Docker image . below , Let's teach you everything .






▌ How to AMD Of GPU Run on TensorFlow?




first , You need to install open source ROCm stack , For detailed installation instructions, please refer to :

https://rocm.github.io/ROCmInstall.html




then , You need to install other related ROCm software package :




sudo apt update
sudo apt install rocm-libs miopen-hip cxlactivitylogger





last , install TensorFlow ( adopt Google Pre built whl software package ):




sudo apt install wget python3-pip 
wget http://repo.radeon.com/rocm/misc/tensorflow/tensorflow-1.8.0
-cp35-cp35m-manylinux1_x86_64.whl
pip3 install ./tensorflow-1.8.0-cp35-cp35m-manylinux1_x86_64.whl







▌ROCm-docker Installation guide




Rocm-docker Installation guide for :

https://github.com/RadeonOpenCompute/ROCm-docker/blob/master/quick-start.md




start-up TensorFlow v1.8 docker image :




alias drun=
'sudo docker run -it --network=host --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v 
$HOME/dockerx:/dockerx -v /data/imagenet/tf:/imagenet'
drun rocm/tensorflow:rocm1.8.2-tf1.8-python2





When you use ROCm Container time , Here are some common and very practical docker command :




*
A new docker Containers typically do not contain metadata repository commands apt. therefore , Trying to use apt Before installing new software , Please first make sure the command sudo apt update
Normal operation of .

*
The following error message appears , It usually means that the current user has no execution docker Permissions for ; You need to use sudo Command or add your users to docker group .      



*
Command to open another terminal in a running container :

             

*
Copy files from host to running docker Command on :

             

*
From running docker Commands for copying files from containers to hosts :

             

*
When pulling an image , Received a message that there is no space left on the device , Please check docker Storage driver the engine is using . If it is “ Device mapper (device
mapper)”, This means “ Device mapper ” Storage driver limits image size limit , At this point, you can refer to the quick start guide for solutions for changing storage drivers , The links are as follows :

https://github.com/RadeonOpenCompute/ROCm-docker/blob/master/quick-start.md






▌ Practice Guide






1, image recognition




We will use TensorFlow A tutorial for Inception-v3 Image recognition task :

https://www.tensorflow.org/tutorials/image_recognition




Here's how to run the code :




cd ~ && git clone https://github.com/tensorflow/models.git
cd ~/models/tutorials/image/imagenet
python3 classify_image.py





after , You will see a list of tags with relevant scores , The script above is used to classify panda images , So you will see the following results :




giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca (score = 0.
89103)
indri, indris, Indri indri, Indri brevicaudatus (score = 0.00810)
lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens (score = 0.
00258)
custard apple (score = 0.00149)
earthstar (score = 0.00141)







2, speech recognition




next , Let's try TensorFlow Speech recognition course of :

https://www.tensorflow.org/tutorials/audio_recognition




Here is the running code :




cd ~ && git clone https://github.com/tensorflow/tensorflow.git
cd ~/tensorflow
python3 tensorflow/examples/speech_commands/train.py





After a few hours of running under the default settings , You're going to see an increasing trend in accuracy :




[...]
INFO:tensorflow:Step 18000: Validation accuracy = 88.7% (N=3093)
INFO:tensorflow:Saving to "/tmp/speech_commands_train/conv.ckpt-18000"
INFO:tensorflow:set_size=3081
INFO:tensorflow:Confusion Matrix:
[[254   2   0   0   0   1   0   0   0   0   0   0]
[  3 195   5   5  11   8   4   5   7   0   4  10]
[  0   4 239   0   1   1   9   1   0   0   1   0]
[  0   5   0 220   1   7   2   4   0   1   1  11]
[  1   1   0   0 258   0   4   0   0   2   4   2]
[  2   5   0  15   1 211   2   0   2   0   2  13]
[  1   2  15   0   6   0 240   2   0   0   1   0]
[  1  13   0   0   3   0   2 237   0   1   2   0]
[  0   5   1   0   2   1   1   3 231   2   0   0]
[  0   3   0   0  21   1   3   3   5 225   1   0]
[  0   0   1   1   8   1   3   0   0   2 232   1]
[  0  14   0  34   6   5   5   2   0   1   0 184]]
INFO:tensorflow:Final test accuracy = 88.5% (N=3081)





If you want to test a trained model , You can try the following :




python3 tensorflow/examples/speech_commands/freeze.py \
--start_checkpoint=/tmp/speech_commands_train/conv.ckpt-18000 \
--output_file=/tmp/my_frozen_graph.pb

python3 tensorflow/examples/speech_commands/label_wav.py --graph=/tmp/my
_frozen_graph.pb --labels=/tmp/speech_commands_train/conv_labels.txt --wav=/tmp/
speech_dataset/left/a5d485dc_nohash_0.wav





You will see “left” The highest score for the label :




left (score = 0.74686)
right (score = 0.12304)
unknown (score = 0.10759)







3, many GPU train




last , Let's use multiple GPU To train ResNet-50. We will use TensorBoard
To monitor progress , So our workflow is divided into two terminals and one browser . first , We assume that you will ImageNet Data set on “/ data / imagenet”( Changeable ) lower .




1) First terminal




cd ~ && git clone https://github.com/tensorflow/benchmarks.git 
cd ~/benchmarks
git checkout -b may22 ddb23306fdc60fefe620e6ce633bcd645561cb0d
MODEL=resnet50
NGPUS=4
BATCH_SIZE=64
ITERATIONS=5000000

TRAIN_DIR=trainbenchmarks${MODEL}
rm -rf "${TRAIN_DIR}"

python3 ./scripts/tf_cnn_benchmarks/tf_cnn_benchmarks.py \
   --model=${MODEL} --data_name=imagenet --data_dir=/data/imagenet \
   --train_dir="${TRAIN_DIR}" --print_training_accuracy=True \
   --summary_verbosity 2 --save_summaries_steps 10 --save_model_secs=3600 \
   --variable_update=parameter_server --local_parameter_device=cpu \
   --num_batches=${ITERATIONS} --batch_size=${BATCH_SIZE} \
   --num_gpus=${NGPUS} 2>&1 | tee /dockerx/tf-imagenet.txt





2) Second terminal




hostname -I        # find your IP address
tensorboard --logdir train_benchmarks_resnet --host <ip_address>





3) Open in browser Tensorboard




link : http://<ip_address>:6006/




use TensorBoard, You can see loss Smaller and smaller , The trend of higher and higher accuracy .









Reference link :

https://medium.com/tensorflow/amd-rocm-gpu-support-for-tensorflow-33c78cc6a6cf






--【 finish 】--



2018 AI Developer Conference
AI Under the upsurge , Technology and landing go hand in hand .




2018 AI Developers Conference 『AI Technology and Application 』 As the core , Invite domestic and foreign top bull , Take you through the project AI.




Instant code scanning , Rush to buy welfare tickets !






click 「 Read the original 」, Excellent information first