[英]cannot reshape array of size 20000 into shape (8,50,50,3)
Now iterate over our dataset n_epoch times for iteration in range(epoch): print("Iteration no: {} ".format(iteration))现在迭代我们的数据集 n_epoch 次以在 range(epoch) 中迭代: print("Iteration no: {} ".format(iteration))
previous_batch=0
# Do our mini batches:
for i in range(no_itr_per_epoch):
current_batch=previous_batch+batch_size
x_input=X_train[previous_batch:current_batch]
x_images=np.reshape(x_input,[batch_size,50,50,3])
y_input=Y_train[previous_batch:current_batch]
y_label=np.reshape(y_input,[batch_size,2])
previous_batch=previous_batch+batch_size
_,loss=sess.run([train_step, cross_entropy], feed_dict={x: x_images,y_: y_label})
if i % 100==0 :
print ("Training loss : {}" .format(loss))
x_test_images=np.reshape(X_test[0:n_test],[n_test,50,50,3])
y_test_labels=np.reshape(Y_test[0:n_test],[n_test,2])
Accuracy_test=sess.run(accuracy,
feed_dict={
x: x_test_images ,
y_: y_test_labels
})
Accuracy_test=round(Accuracy_test*100,2)
x_val_images=np.reshape(X_val[0:n_val],[n_val,50,50,3])
y_val_labels=np.reshape(Y_val[0:n_val],[n_val,2])
Accuracy_val=sess.run(accuracy,
feed_dict={
x: x_val_images ,
y_: y_val_labels
})
Accuracy_val=round(Accuracy_val*100,2)
print("Accuracy :: Test_set {} % , Validation_set {} % " .format(Accuracy_test,Accuracy_val))
ValueError: cannot reshape array of size 20000 into shape (8,50,50,3) ValueError:无法将大小为 20000 的数组重塑为形状 (8,50,50,3)
def process_img(img): def process_img(img):
8 * 50 * 50 * 3 = 60,000. 8 * 50 * 50 * 3 = 60,000。 Therefore the original with size 20,000 can't be resized to the new shape.
因此,大小为 20,000 的原件无法调整为新形状。 What you can do is reshape it to (8, 50, 50, 1) and then broadcast, since 8 * 50 * 50 = 20,000.
你可以做的是将它重塑为 (8, 50, 50, 1) 然后广播,因为 8 * 50 * 50 = 20,000。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.