pages tagged Docker http://meng6net.localhost/tag/Docker/ <p><small>Copyright © 2005-2020 by <code>Meng Lu &lt;lumeng3@gmail.com&gt;</code></small></p> Meng Lu's home page ikiwiki Tue, 29 Aug 2017 18:36:58 +0000 Installing and configuring Docker http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_docker/ http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_docker/ Docker computing configuration documentation draft installation note software Sun, 02 Jul 2017 01:09:02 +0000 2017-08-29T18:36:58Z <h2>macOS</h2> <h3>Homebrew</h3> <pre><code>brew cask install docker brew cask install docker-toolbox </code></pre> <h2>Create a virtual machine</h2> <pre><code>bash$ docker-machine create default </code></pre> <h2>Start the virtual machine</h2> <p>Start the virtual machine <code>default</code>:</p> <pre><code>bash$ docker-machine start bash$ docker-machine env export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.99.100:2376" export DOCKER_CERT_PATH="/Users/meng/.docker/machine/machines/default" export DOCKER_MACHINE_NAME="default" # Run this command to configure your shell: # eval $(docker-machine env) bash$ eval "$(docker-machine env default)" </code></pre> <h2>Verify that the docker machine is working</h2> <pre><code>bash$ docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world b04784fba78d: Pull complete Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/ </code></pre> <h2>Run and test the 'tensorflow/tensorflow' Docker image</h2> <pre><code>bash$ docker run -it tensorflow/tensorflow:1.1.0 bash Unable to find image 'tensorflow/tensorflow:1.1.0' locally 1.1.0: Pulling from tensorflow/tensorflow c62795f78da9: Pull complete d4fceeeb758e: Pull complete 5c9125a401ae: Pull complete 0062f774e994: Pull complete 6b33fd031fac: Pull complete 353b34ef0a98: Pull complete 4f6aefc14b68: Pull complete ce066374c6ca: Pull complete c0755a91ab3a: Pull complete f03279b52d25: Pull complete d1c27c29b7e3: Pull complete 23807c5f4b3e: Pull complete Digest: sha256:27bd43f1cf71c45eb48cb6e067b7cef47b168ac11c685d55a3495d27f0d59543 Status: Downloaded newer image for tensorflow/tensorflow:1.1.0 root@d000fef7e8dc:/notebooks# root@d000fef7e8dc:/notebooks# python Python 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; &gt;&gt;&gt; import tensorflow as tf &gt;&gt;&gt; hello = tf.constant('Hello, TensorFlow!') &gt;&gt;&gt; sess = tf.Session() # It will print some warnings here. 2017-06-29 06:08:55.848559: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. 2017-06-29 06:08:55.848626: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. 2017-06-29 06:08:55.848663: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. &gt;&gt;&gt; print(sess.run(hello)) Hello, TensorFlow! &gt;&gt;&gt; </code></pre> <h2>List all virtual machines</h2> <pre> <code>$ docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS default - virtualbox Stopped Unknown </code></pre> <h2>Delete a virtual machine</h2> <pre><code>$ docker-machine rm default About to remove default WARNING: This action will delete both local reference and remote instance. Are you sure? (y/n): y Successfully removed default </code></pre> <h2>References</h2> <ul> <li> https://stackoverflow.com/questions/21871479/docker-cant-connect-to-docker-daemon</li> </ul> Installing and configuring TensorFlow http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_TensorFlow/ http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_TensorFlow/ Docker TensorFlow computing configuration documentation draft installation note software Sat, 01 Jul 2017 21:23:24 +0000 2017-07-01T21:23:24Z <h2>Install TensorFlow using 'tensorflow/tensorflow' Docker image</h2> <h3>Start the Docker virtual machine</h3> <p>Create a virtual machine if not already</p> <pre><code>bash$ docker-machine create default </code></pre> <p>Start the virtual machine <code>default</code>:</p> <pre><code>bash$ docker-machine start Starting "default"... (default) Check network to re-create if needed... (default) Waiting for an IP... Machine "default" was started. Waiting for SSH to be available... Detecting the provisioner... Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command. &gt;&gt;&gt; elapsed time 35s bash$ docker-machine env export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.99.100:2376" export DOCKER_CERT_PATH="/Users/meng/.docker/machine/machines/default" export DOCKER_MACHINE_NAME="default" # Run this command to configure your shell: # eval $(docker-machine env) bash$ eval "$(docker-machine env default)" </code></pre> <h3>Start 'tensorflow/tensorflow' Docker image</h3> <pre><code>$ export MY_WORKSPACE_DIR='/Users/meng/workspace' $ docker run -it \ --net=host \ --publish 6006:6006 \ --volume ${MY_WORKSPACE_DIR}/tensorflow_test:/tensorflow_test \ --workdir /tensorflow_test \ tensorflow/tensorflow:1.1.0 bash root@30d79c2e5fc3:/tensorflow_test# pwd /tensorflow_test </code></pre> <h3>Start TensorBoard</h3> <pre> <code>root@30d79c2e5fc3:/tensorflow_test# tensorboard --logdir training_summaries &amp; [1] 12 root@30d79c2e5fc3:/tensorflow_test# Starting TensorBoard 47 at http://0.0.0.0:6006 (Press CTRL+C to quit) root@30d79c2e5fc3:/tensorflow_test# </code></pre> <p>Open TensorBoard at</p> <pre><code>http://192.168.99.100:6006 </code></pre> <p>in a Web browser, where the IP is the same as <code>DOCKER_HOST</code> in the output of <code>docker-machine env</code>.</p> <h3>Download training data</h3> <pre> <code># curl -O http://download.tensorflow.org/example_images/flower_photos.tgz # tar xzf flower_photos.tgz # find flower_photos -type f | wc -l 3671 # cp -R flower_photos flower_photos_subset # rm flower_photos_subset/*/[2-9]* # find flower_photos_subset/ -type f | wc -l 1202 </code></pre> <h3>Download training script</h3> <pre> <code># curl -O https://raw.githubusercontent.com/tensorflow/tensorflow/r1.1/tensorflow/examples/image_retraining/retrain.py </code></pre> <h3>Training</h3> <pre><code># python retrain.py \ --bottleneck_dir=bottlenecks \ --how_many_training_steps=500 \ --model_dir=inception \ --summaries_dir=training_summaries/basic \ --output_graph=retrained_graph.pb \ --output_labels=retrained_labels.txt \ --image_dir=flower_photos_subset </code></pre> <h2>Python script to classify new images of flowers</h2> <p>Create a new file <code>label_image.py</code>:</p> <pre><code>import os, sys import tensorflow as tf os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # change this as you see fit image_path = sys.argv[1] # Read in the image_data image_data = tf.gfile.FastGFile(image_path, 'rb').read() # Loads label file, strips off carriage return label_lines = [line.rstrip() for line in tf.gfile.GFile("retrained_labels.txt")] # Unpersists graph from file with tf.gfile.FastGFile("retrained_graph.pb", 'rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) tf.import_graph_def(graph_def, name='') with tf.Session() as sess: # Feed the image_data as input to the graph and get first prediction softmax_tensor = sess.graph.get_tensor_by_name('final_result:0') predictions = sess.run(softmax_tensor, \ {'DecodeJpeg/contents:0': image_data}) # Sort to show labels of first prediction in order of confidence top_k = predictions[0].argsort()[-len(predictions[0]):][::-1] for node_id in top_k: human_string = label_lines[node_id] score = predictions[0][node_id] print('%s (score = %.5f)' % (human_string, score)) </code></pre> <p>Classify a new image:</p> <pre> <code># python label_image.py flower_photos/daisy/99306615_739eb94b9e_m.jpg daisy (score = 0.47996) dandelion (score = 0.24667) sunflowers (score = 0.24508) tulips (score = 0.02018) roses (score = 0.00811) </code></pre> <h3>Exit the Docker image and stop the Docker virtual machine</h3> <p>Ctrl+D to exit Docker image and then run</p> <pre><code>$ docker-machine stop </code></pre> <h2>References</h2> <ul> <li> https://codelabs.developers.google.com/codelabs/tensorflow-for-poets</li> </ul>