리눅스 운영체제 사용전환 및 딥러닝에 필요한 모든 것 설치완료
근래 10일 정도를 리눅스로 체제 전환 및 딥러닝에 필요한 환경을 설치했다.
구축한 환경:
- 리눅스 체제 ( 우분투 18.04)
- anaconda 에서의 jupyter, tensorflow(cpu버전, gpu는 내 노트북에 해당안됨) , opencv , 다양한 라이브러리 등 설치
- pip3 에서 tensorflow, opencv 등 설치
- pip3 환경과 anaconda (가상환경이름 : ML) 두 가지 환경으로 사용예정 (적절하게 필요시 바꿔가며)
- 주 작업창으로 pycharm 과 jupyter notebook 사용 ( 이 2가지 환경 모두 anaconda ML 환경 )
pycharm 환경 예시 :
|
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 |
from tensorflow.examples.tutorials.mnist import input_data import tensorflow as tf mnist_data = input_data.read_data_sets('MNIST_data', one_hot=True) input_size = 784 no_classes = 10 batch_size = 100 total_batches = 200 x_input = tf.placeholder(tf.float32, shape=[None, input_size]) y_input = tf.placeholder(tf.float32, shape=[None, no_classes]) weights = tf.Variable(tf.random_normal([input_size,no_classes])) bias = tf.Variable(tf.random_normal([no_classes])) logits = tf.matmul(x_input, weights) + bias softmax_cross_entropy = tf.nn.softmax_cross_entropy_with_logits( labels=y_input, logits=logits) loss_operation = tf.reduce_mean(softmax_cross_entropy) optimiser = tf.train.GradientDescentOptimizer( learning_rate=0.5).minimize(loss_operation) session = tf.Session() session.run(tf.global_variables_initializer()) for batch_no in range(total_batches): mnist_batch = mnist_data.train.next_batch(batch_size) _, loss_value = session.run([optimiser, loss_operation], feed_dict={ x_input : mnist_batch[0], y_input : mnist_batch[1] }) print(loss_value) predictions = tf.argmax(logits,1) correct_predictions = tf.equal(predictions, tf.argmax(y_input, 1)) accuracy_operation = tf.reduce_mean( tf.cast(correct_predictions,tf.float32)) test_images, test_labels = mnist_data.test.images, mnist_data.test.labels accuracy_value = session.run(accuracy_operation, feed_dict={ x_input : test_images, y_input : test_labels }) print('Accuracy: ',accuracy_value) session.close() |

jupyter notebook 환경 예시 :

