2017-09-07 2 views
1

어떻게 뉴런 네트워크의 레이어를 tensorflow로 수정할 수 있습니까?뉴런 네트워크의 레이어를 수정하십시오.

예를 들어,이 예제 프로그램에서 다른 신경망을 훈련하여 두 번째 계층을 알면 (예 : B) 말하십시오. 이를 고정 레이어로 사용하고 아래의 네트워크에서 첫 번째 레이어를 계산할 수 있습니까?

import tensorflow as tf 
x = tf.placeholder(tf.float32, [None, 784]) 

#layer 1 
W1 = tf.Variable(tf.zeros([784, 100])) 
b1 = tf.Variable(tf.zeros([100])) 
y1 = tf.matmul(x, W1) + b1 #remove softmax 

#layer 2 
W2 = tf.Variable(tf.zeros([100, 10])) 
b2 = tf.Variable(tf.zeros([10])) 
y2 = tf.nn.softmax(tf.matmul(y1, W2) + b2) 

#output 
y = y2 
y_ = tf.placeholder(tf.float32, [None, 10]) 

답변

1

특정 변수를 학습 가능하지 않도록 지정할 수 있으며 저장된 값으로 변수를 초기화 할 수 있습니다. 같은 뭔가 : saved_weightssaved_biases 각각 당신의 사전 배운 가중치 행렬과 바이어스 벡터를 포함

W2 = tf.Variable(saved_weigths, trainable=False) 
b2 = tf.Variable(saved_biases, trainable=False) 
y2 = tf.nn.softmax(tf.matmul(y1, W2) + b2) 

. 참고 : Variable docs.

관련 문제