저는 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가 있습니다.