I touched Tensorflow and keras

*** This is an overview of Tensorflow Study Group @ Honmachi held on August 25th. *** ***

What is GCP?

Abbreviation for Google Cloud Platform. It's the Google version of AWS (Amazon Web Services). The billing system is complicated and I'm afraid to use it for a while, but this time I want to try ML Engine (a service that builds a model of Tensorflow) because it is very easy to create a server. I chose this.

https://cloud.google.com/

Create an instance of Compute Engine

This time I would like to install tensorflow on a simple virtual machine and run it.

Create a new instance. I chose "Ubuntu 17" as the boot disk.

Screen Shot 2017-08-21 at 11.37.55.png

Access this instance using the "External IP" that will be assigned after it is created (replace the part labeled YOUR_IP with the IP you got here).

Ubuntu setup

First, log in with ssh.

ssh ubuntu@YOUR_IP

Install the required packages.

sudo -i
apt -y update
apt -y upgrade

apt -y install python3-pip python3-dev
pip3 install --upgrade pip
pip3 install opencv-python tensorflow
exit

This time, I have introduced a package so that tensorflow works with Python3 (not 2.x). Check if the library can be loaded normally as follows.

$ python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> node1 = tf.constant(3.0, dtype=tf.float32)
>>> node2 = tf.constant(4.0) # also tf.float32 implicitly
>>> print(node1, node2)
Tensor("Const:0", shape=(), dtype=float32) Tensor("Const_1:0", shape=(), dtype=float32)
>>> 

--Reference: https://www.tensorflow.org/get_started/get_started

Move Tensorflow to see

I have installed Tensorflow, but I want the tutorial code, so I'll get the source code from GitHub.

git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow/tensorflow/examples/tutorials/mnist/

Click here for the simplest sample. The data set for learning and evaluating mnist (handwritten characters) is downloaded from the Internet, and the model construction and evaluation are completed in an instant.

python3 mnist_softmax.py

For the contents of this program, please refer to the following URL. (I'm not good at theory, so I'll escape from this area to the topic of how to put it to practical use ...)

--https://www.tensorflow.org/get_started/mnist/beginners (translated version)

Play with image recognition

(It's a little inconvenient because it's just made) I made an application that starts tensorflow when uploading an image from a browser to the server and displays the result of classifying the image. Also, since the sample code of tensorflow has been evaluated as it is without saving the model, there is also a modified code to save the model using Saver (train-*. Py).

git clone https://github.com/lumbermill/takachiho.git
sudo apt install apache2 php rake
cd ~/takachiho/webapps/01-tensorflow
#Deploy php
rake install
#Build and deploy a model
cd ~/takachiho/raspi/07-coffee
python3 train-mnist1.py --data_dir=/tmp/tensorflow/mnist/input_data/ --log_dir=/var/www/html/tensorflow/models/

The screen looks like this. If you are interested in the source code, please refer to the above repository.

Screen Shot 2017-08-27 at 8.30.56.png

Try a pre-built model of keras

First, install and download the sample program.

sudo pip3 install keras h5py
curl -O https://raw.githubusercontent.com/asataniAIR/Image_DL_Tutorial/master/VGG/VGG16_Demo.py

If you specify an image as an argument, it will guess what it is. Easy!

$ python3 VGG16_Demo.py sample.jpg
Using TensorFlow backend.
:
Omission
:
('n03947888', 'pirate', 0.98744524)
('n04147183', 'schooner', 0.010494102)
('n04606251', 'wreck', 0.0010530388)
('n03240683', 'drilling_platform', 0.00052914425)
('n03344393', 'fireboat', 0.00010963867)

Other

(Keywords that I couldn't go into too much detail)

Related Links

-Build Tensorflow iOS demo

Recommended Posts

I touched Tensorflow and keras
I tried to implement Grad-CAM with keras and tensorflow
I touched HaikuFinder
Compare raw TensorFlow with tf.contrib.learn and Keras
Summary of Tensorflow / Keras
optuna, keras and titanic
I touched TensorFlow's Tensorboard
I tried running TensorFlow
I touched AWS Chalice
I touched Wagtail (3). Investigation and implementation of pop-up messages.
I touched Wagtail (1) and let's override the save method.
Clipping and normalization in TensorFlow
I touched the Qiita API
Asynchronous I / O and non-blocking I / O
Python environment construction and TensorFlow
63rd day I installed tensorflow.
I touched Wagtail (2). Introducing django-extensions.
I tried using magenta / TensorFlow
I compared blade and jinja2
[Python] Hit Keras from TensorFlow and TensorFlow from c ++ to speed up execution
Pydroid 3 --I tried OpenCV and TensorFlow options for IDE for Python 3 (Android)
Challenge image classification with TensorFlow2 + Keras 9-Learning, saving and loading models-
[Reading Notes] Hands-on Machine Learning with Scikit-Learn, Keras, and TensorFlow Chapter 1
MNIST (DCNN) with Keras (TensorFlow backend)
I tried the TensorFlow tutorial 1st
I tried the TensorFlow tutorial 2nd
I compared Qiskit and Blueqat (beginner)
I tried TensorFlow tutorial CNN 4th
Keras as wrapper of Theano & TensorFlow
[TensorFlow] [Keras] Neural network construction with Keras
Compare DCGAN and pix2pix with keras
I personally compared Java and Ruby
I played with PyQt5 and Python3
I touched something called Touch Designer
I implemented the VGG16 model in Keras and tried to identify CIFAR10