Amazon Ubuntu Deep Learning Instance Configuring Steps

Git server building. $ ssh-­keygen -­t rsa ­-C "user.email" Modifying hooks: $ vim sample.git/hooks/post-receive Sample code for hooks: #!/bin/sh GIT_WORK_TREE=/home/ubuntu/Deployment/sample git checkout -f chmod -R 777 /home/ubuntu/Deployment/sample Install bazel. 1). Add Bazel distribution URI as a package source (one time setup)

echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add - [Read More]

Convert mp3 to mp4 In Batch

Solution 1:
ls *.mp3 | while read mp3File ; do outputFile=$(basename "${mp3File}" .mp3) ; ffmpeg -i "${mp3File}" -loop 1 -i image.png -c:a copy -c:v libx264 -shortest "${outputFile}".mp4 ; done

Solution 2:

$ mkdir out
$ for f in *.mp3; do ffmpeg -f lavfi -i color=s=160x120:r=2 -i "$f" \
-c:v libx264 -preset ultrafast -c:a copy -shortest \
out/"${f%.mp3}.mp4"; done
[Read More]

Amazon Ubuntu Instance Suffers `Permission Denied(publickey).`

N.B. There are dozens of reasons to lead to this problem, for example, wrong permission of your pem file, incorrect username(e.g., ec2-user, ubuntu),wrong spelling in your command, etc..

The reason which causes my problem, if I am right, is that I run command `sudo chmod -R ./` under the wrong directory, namely, my home folder.

The solution is just setting your home folder permissions back.

Stop your problematic instance. Create a new instance and stop the new problem-free instance. The newly created instance should be in the same `Availability Zone` like ‘us-west-2c’ which can be set on the ‘Network’ step under which the menu is ‘Subnet’.
  • Detach your ‘ebs volume’ from the problematic instances and attach it on your new problem-free instance.
  • Your need input your instance id as well as the mount point which looks like ‘/dev/sda2’. Start your new instance and mount the second drive that you just attached.

    [ubuntu ~]$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvdf 202:80 0 100G 0 disk xvda1 202:1 0 8G 0 disk / [ubuntu ~]$ sudo mount /dev/xvdf/ /mnt [Read More]

  • PERMISSION DENIED (PUBLICKEY).

    A problem occurred while I `git push` to my git server on ec2.

    I handled this by following this three guide of which their original links are:

    http://stackoverflow.com/questions/13363553/git-error-host-key-verification-failed-when-connecting-to-remote-repository

    https://chenhuachao.com/2016/05/26/ssh%E5%87%BA%E9%94%99-sign-and-send-pubkey-signing-failed-agent-refused-operation/

    Sorry for missing out the second source link, I will add that later.

    sign_and_send_pubkey: signing failed: agent refused operation
    Permission denied (publickey).
    fatal: Could not read from remote repository.

    1. mkdir ~/.ssh
    2. vim known_hosts – if you already have known_hosts, skip this.
    3. ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
    4. ssh-keygen -t rsa -C "user.email"
    5. Add the id_rsa.pub key to SSH keys list on your GitHub profile.

    Set up your client

    1. Generate your key
      • ssh-keygen
    2. Configure ssh to use the key
      • vim ~/.ssh/config
    3. Copy your key to your server
      • ssh-copy-id -i /path/to/key.pub SERVERNAME

    Your config file from step 2 should have something similar to the following:

    Host SERVERNAME Hostname ip-or-domain-of-server User USERNAME PubKeyAuthentication yes IdentityFile ./path/to/key [Read More]

    使用 tf.train.Saver 中断和恢复 Tensorflow 的训练数据

    ''' Save and Restore a model using TensorFlow. This example is using the MNIST database of handwritten digits (http://yann.lecun.com/exdb/mnist/) Author: Aymeric Damien Project: https://github.com/aymericdamien/TensorFlow-Examples/ ''' from __future__ import print_function # Import MNIST data from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) import tensorflow as tf # Parameters learning_rate = 0.001 batch_size = 100 display_step = 1 model_path = "/tmp/model.ckpt" # Network Parameters n_hidden_1 = 256 # 1st layer number of features n_hidden_2 = 256 # 2nd layer number of features n_input = 784 # MNIST data input (img shape: 28*28) n_classes = 10 # MNIST total classes (0-9 digits) # tf Graph input x = tf.placeholder("float", [None, n_input]) y = tf.placeholder("float", [None, n_classes]) # Create model def multilayer_perceptron(x, weights, biases): # Hidden layer with RELU activation layer_1 = tf.add(tf.matmul(x, weights['h1']), biases['b1']) layer_1 = tf.nn.relu(layer_1) # Hidden layer with RELU activation layer_2 = tf.add(tf.matmul(layer_1, weights['h2']), biases['b2']) layer_2 = tf.nn.relu(layer_2) # Output layer with linear activation out_layer = tf.matmul(layer_2, weights['out']) + biases['out'] return out_layer # Store layers weight & bias weights = { 'h1': tf.Variable(tf.random_normal([n_input, n_hidden_1])), 'h2': tf.Variable(tf.random_normal([n_hidden_1, n_hidden_2])), 'out': tf.Variable(tf.random_normal([n_hidden_2, n_classes])) } biases = { 'b1': tf.Variable(tf.random_normal([n_hidden_1])), 'b2': tf.Variable(tf.random_normal([n_hidden_2])), 'out': tf.Variable(tf.random_normal([n_classes])) } # Construct model pred = multilayer_perceptron(x, weights, biases) # Define loss and optimizer cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=pred, labels=y)) optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost) # Initializing the variables init = tf.global_variables_initializer() # 'Saver' op to save and restore all the variables saver = tf.train.Saver() # Running first session print("Starting 1st session...") with tf.Session() as sess: # Initialize variables sess.run(init) # Training cycle for epoch in range(3): avg_cost = 0. total_batch = int(mnist.train.num_examples/batch_size) # Loop over all batches for i in range(total_batch): batch_x, batch_y = mnist.train.next_batch(batch_size) # Run optimization op (backprop) and cost op (to get loss value) _, c = sess.run([optimizer, cost], feed_dict={x: batch_x, y: batch_y}) # Compute average loss avg_cost += c / total_batch # Display logs per epoch step if epoch % display_step == 0: print("Epoch:", '%04d' % (epoch+1), "cost=", \ "{:.9f}".format(avg_cost)) print("First Optimization Finished!") # Test model correct_prediction = tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1)) # Calculate accuracy accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float")) print("Accuracy:", accuracy.eval({x: mnist.test.images, y: mnist.test.labels})) # Save model weights to disk save_path = saver.save(sess, model_path) print("Model saved in file: %s" % save_path) # Running a new session print("Starting 2nd session...") with tf.Session() as sess: # Initialize variables sess.run(init) # Restore model weights from previously saved model saver.restore(sess, model_path) print("Model restored from file: %s" % save_path) # Resume training for epoch in range(7): avg_cost = 0. total_batch = int(mnist.train.num_examples / batch_size) # Loop over all batches for i in range(total_batch): batch_x, batch_y = mnist.train.next_batch(batch_size) # Run optimization op (backprop) and cost op (to get loss value) _, c = sess.run([optimizer, cost], feed_dict={x: batch_x, y: batch_y}) # Compute average loss avg_cost += c / total_batch # Display logs per epoch step if epoch % display_step == 0: print("Epoch:", '%04d' % (epoch + 1), "cost=", \ "{:.9f}".format(avg_cost)) print("Second Optimization Finished!") # Test model correct_prediction = tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1)) # Calculate accuracy accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float")) print("Accuracy:", accuracy.eval( {x: mnist.test.images, y: mnist.test.labels})) [Read More]