2017-12-30 51 views
0

저는 Stanford의 CS20SI : Tensorflow for Deep Learning Research를 사용하고 있습니다. 이 코드에Tensorflow를 통한 MNIST의 로지스틱 회귀 속도

import time 
import numpy as np 
import tensorflow as tf 
from tensorflow.examples.tutorials.mnist import input_data 
# Step 1: Read in data 
# using TF Learn's built in function to load MNIST data to the folder data/mnist 
MNIST = input_data.read_data_sets("/data/mnist", one_hot=True) 

# Batched logistic regression 
learning_rate = 0.01 
batch_size = 128 
n_epochs = 25 

X = tf.placeholder(tf.float32, [batch_size, 784], name = 'image') 
Y = tf.placeholder(tf.float32, [batch_size, 10], name = 'label') 

#w = tf.Variable(tf.random_normal(shape = [int(shape[1]), int(Y.shape[1])], stddev = 0.01), name='weights') 
#b = tf.Variable(tf.zeros(shape = [1, int(Y.shape[1])]), name='bias') 

w = tf.Variable(tf.random_normal(shape=[784, 10], stddev=0.01), name="weights") 
b = tf.Variable(tf.zeros([1, 10]), name="bias") 

logits = tf.matmul(X,w) + b 

entropy = tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=Y) 
loss = tf.reduce_mean(entropy) #computes the mean over examples in the batch 

optimizer = tf.train.GradientDescentOptimizer(learning_rate = learning_rate).minimize(loss) 

init = tf.global_variables_initializer() 

with tf.Session() as sess: 
    sess.run(init) 
    n_batches = int(MNIST.train.num_examples/batch_size) 
    for i in range(n_epochs): 
     start_time = time.time() 
     for _ in range(n_batches): 
      X_batch, Y_batch = MNIST.train.next_batch(batch_size) 
      opt, loss_ = sess.run([optimizer, loss], feed_dict = {X: X_batch, Y:Y_batch}) 
     end_time = time.time() 
     print('Epoch %d took %f'%(i, end_time - start_time)) 

이 MNIST 데이터 세트와 로지스틱 회귀 분석을 수행한다 : 나는 다음과 같은 코드에 관한 질문이 있습니다. 저자의 주 : 나는 그것을 실행할 때

내 Mac에서 실행,

0.5 128 개 실행 두 번째 배치 크기와 모델의 배치 버전은 그러나 각각의 시대는, 약 2 초 정도 걸립니다 총 실행 시간은 1 분 정도입니다. 이 예가 그 시간이 걸리는 것이 합리적입니까? 현재 나는 Ryzen 1700없이 OC (3.0GHz)와 GPU Gtx 1080없이 OC가 있습니다.

답변

1

나는이 코드를 GTX Titan X (Maxwell)에서 시도했고, 기원 당 약 0.5 초를 보냈다. GTX 1080이 비슷한 결과를 가져올 수 있어야합니다.

최신 tensorflow 및 cuda/cudnn 버전을 사용해보십시오. 환경 변수가 설정되지 않는 제한 (GPU가 표시되는지, 메모리 텐서 흐름이 사용 가능한지 등)이 없는지 확인하십시오. 마이크로 벤치 마크를 실행하여 카드의 명시된 FLOPS를 달성 할 수 있는지 확인할 수 있습니다 (예 : Testing GPU with tensorflow matrix multiplication