2017-11-15 16 views
1

: MNIST 자습서 - Julia.jlERROR : LoadError : Tensorflow 오류 : 상태 : 호환되지 않는 모양 : 나는의 예에서 TensorFlow을 배우고 <a href="https://malmaud.github.io/tfdocs/tutorial/" rel="nofollow noreferrer">multilayer CNN Tutorial</a></p> <p>에서 적응 모델의 구현 [16] 대 [16,9]

자습서와 달리, 나는 cifar-10에 대해 나만의 맞춤 이미지 (32 X 32 (RGB)) 형식을 사용하고 있습니다. csv의 각 행은 마지막 레이블 인 3073 개의 열입니다.

그리고 나는 훈련을 위해 처음 240 개의 행을 선택하기 위해 어레이 슬라이싱을 사용하고 나머지는 테스트를 위해 300 개의 행을 가지고 있습니다.

Incompatible shapes: [16] vs. [16,9]

실제로 나는 240 트레이닝 세트 구 개 클래스와 테스트를위한 60 개 이미지가

images_train = 240 X 3072 labels_train = 240 X 1 images_test = 60 X 3072 labels_test = 60 X 1 .

내가 오류 얻을 네트워크를 훈련하려고 : 너트 쉘 그래서 나는 4 개 배열이 .

enter image description here

코드는 다음과 같습니다

using TensorFlow 
using Distributions 
include("loader.jl") 

session = Session(Graph()) 
function weight_variable(shape) 
    initial = map(Float32, rand(Normal(0, .001), shape...)) 
    return Variable(initial) 
end 

function bias_variable(shape) 
    initial = fill(Float32(.1), shape...) 
    return Variable(initial) 
end 

function conv2d(x, W) 
    nn.conv2d(x, W, [1, 1, 1, 1], "SAME") 

end 

function max_pool_2x2(x) 
    nn.max_pool(x, [1, 2, 2, 1], [1, 2, 2, 1], "SAME") 
end 

x = placeholder(Float32) 
y_ = placeholder(Float32) 

W_conv1 = weight_variable([5, 5, 3, 32]) 
b_conv1 = bias_variable([32]) 

x_image = x #reshape(x, [-1, 32, 32, 3]) 

h_conv1 = nn.relu(conv2d(x_image, W_conv1) + b_conv1) 
h_pool1 = max_pool_2x2(h_conv1) 

W_conv2 = weight_variable([5, 5, 32, 64]) 
b_conv2 = bias_variable([64]) 

h_conv2 = nn.relu(conv2d(h_pool1, W_conv2) + b_conv2) 
h_pool2 = max_pool_2x2(h_conv2) 

W_fc1 = weight_variable([8*8*64, 1024]) # 
b_fc1 = bias_variable([1024]) 

h_pool2_flat = reshape(h_pool2, [-1, 8*8*64]) 
h_fc1 = nn.relu(h_pool2_flat * W_fc1 + b_fc1) 

keep_prob = placeholder(Float32) 
h_fc1_drop = nn.dropout(h_fc1, keep_prob) 

W_fc2 = weight_variable([1024, 9]) 
b_fc2 = bias_variable([9]) 

y_conv = nn.softmax(h_fc1_drop * W_fc2 + b_fc2) 


cross_entropy = reduce_mean(-reduce_sum((y_ .* log(y_conv)), axis=[2])) 

train_step = train.minimize(train.AdamOptimizer(1e-4), cross_entropy) 

correct_prediction = indmax(y_conv, 2) .== indmax(y_, 2) 

accuracy = reduce_mean(cast(correct_prediction, Float32)) 

run(session, global_variables_initializer()) 

for i in 1:100 
    images_train,labels_train = batching(16) # randomly generate batches from training dataset (16,32,32,3) 
    if i%4 == 1 
     train_accuracy = run(session, accuracy, Dict(x=>images_train, y_=>labels_train, keep_prob=>1.0)) 
     info("step $i, training accuracy $train_accuracy") 
    end 
    run(session, train_step, Dict(x=>images_train, y_=>labels_train, keep_prob=>.5)) 
end 

images_test, labels_test = testloader() # (60, 33,32,3), (60,) Arrays 


test_accuracy = run(session, accuracy, Dict(x=>images_test, y_=>labels_test, keep_prob=>1.0)) 
info("test accuracy $test_accuracy") 

답변

1

reshape(A,(16,1))

가 호환성의 문제를 해결 적용.