Incompatible shapes of test and train set in tensorflow
up vote
0
down vote
favorite
I am trying to build a CNN network with tensorflow package. My train data sets are 237 images with 100X100 in 6 classes and my test sets are 30 images with same size and classes.
Everything is going well except last part that I want to measure accuracy with
acc=tf.reduce_mean(tf.cast(matches,tf.float32))
I cannot understand why it make error while I am testing with test sets (both data and label) that it is compatible “(30,100,100,1) vs (30,6)”.
Can anyone explain why and what is possible solution.
Note: when I apply batch size 30 (equal to number my test set row) on train data it works.i assume the model expect that the train and test set should be equal number of row that it doesn't make set (usually 70% train vs 30% test) i checked some post with same error title but i couldn’t get it, in face, i think although the error title was same but their problem was different. mostly they had issue with flatten layer.
screenshot from data set info
enter image description here
here is the simple code
…
convo_1=…(x_img,shape=[5,5,1,32])
convo_1_pooling=…(convo_1)
convo_2=…(x_img,shape=[5,5,32,64])
convo_2_pooling=…(convo_2)
convo_3=…(x_img,shape=[5,5,64,128])
convo_3_pooling=…(convo_3)
convo_3_flat=tf.reshape(convo_3_pooling,[-1,13*13*128])
full_layer_one=tf.nn.relu(sp.normal_full_layer(convo_3_flat,21632))
# DROPOUT
hold_prob=tf.placeholder(tf.float32)
full_one_dropout=tf.nn.dropout(full_layer_one,keep_prob=hold_prob)
y_pred=sp.normal_full_layer(full_one_dropout,6)
# LOOS FUNCTION
cross_entropy=tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y,logits=y_pred))
# OPTIMIZER
optimizer=tf.train.AdamOptimizer(learning_rate=learning_rate)
train=optimizer.minimize(cross_entropy)
with tf.Session() as sess:
sess.run(init)
b=0
for i in range(training_iters):
sess.run(train,feed_dict={x_img:train_x, y:train_y,hold_prob:.5})
if i%2 ==0:
print("NO STEP:{}",format(i))
print("ACCURACY: ")
matches=tf.equal(tf.argmax(y_pred,1),tf.argmax(train_y,1))
acc=tf.reduce_mean(tf.cast(matches,tf.float32))
print(sess.run(acc,feed_dict={x_img:test_x, y:test_y, hold_prob:1.0}))
print('n')
and this is the error
InvalidArgumentError: Incompatible shapes: [30] vs. [237]
[[{{node Equal_1}} = Equal[T=DT_INT64, _device="/job:localhost/replica:0/task:0/device:CPU:0"](ArgMax_2, ArgMax_3)]]
thank you so much
python tensorflow
add a comment |
up vote
0
down vote
favorite
I am trying to build a CNN network with tensorflow package. My train data sets are 237 images with 100X100 in 6 classes and my test sets are 30 images with same size and classes.
Everything is going well except last part that I want to measure accuracy with
acc=tf.reduce_mean(tf.cast(matches,tf.float32))
I cannot understand why it make error while I am testing with test sets (both data and label) that it is compatible “(30,100,100,1) vs (30,6)”.
Can anyone explain why and what is possible solution.
Note: when I apply batch size 30 (equal to number my test set row) on train data it works.i assume the model expect that the train and test set should be equal number of row that it doesn't make set (usually 70% train vs 30% test) i checked some post with same error title but i couldn’t get it, in face, i think although the error title was same but their problem was different. mostly they had issue with flatten layer.
screenshot from data set info
enter image description here
here is the simple code
…
convo_1=…(x_img,shape=[5,5,1,32])
convo_1_pooling=…(convo_1)
convo_2=…(x_img,shape=[5,5,32,64])
convo_2_pooling=…(convo_2)
convo_3=…(x_img,shape=[5,5,64,128])
convo_3_pooling=…(convo_3)
convo_3_flat=tf.reshape(convo_3_pooling,[-1,13*13*128])
full_layer_one=tf.nn.relu(sp.normal_full_layer(convo_3_flat,21632))
# DROPOUT
hold_prob=tf.placeholder(tf.float32)
full_one_dropout=tf.nn.dropout(full_layer_one,keep_prob=hold_prob)
y_pred=sp.normal_full_layer(full_one_dropout,6)
# LOOS FUNCTION
cross_entropy=tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y,logits=y_pred))
# OPTIMIZER
optimizer=tf.train.AdamOptimizer(learning_rate=learning_rate)
train=optimizer.minimize(cross_entropy)
with tf.Session() as sess:
sess.run(init)
b=0
for i in range(training_iters):
sess.run(train,feed_dict={x_img:train_x, y:train_y,hold_prob:.5})
if i%2 ==0:
print("NO STEP:{}",format(i))
print("ACCURACY: ")
matches=tf.equal(tf.argmax(y_pred,1),tf.argmax(train_y,1))
acc=tf.reduce_mean(tf.cast(matches,tf.float32))
print(sess.run(acc,feed_dict={x_img:test_x, y:test_y, hold_prob:1.0}))
print('n')
and this is the error
InvalidArgumentError: Incompatible shapes: [30] vs. [237]
[[{{node Equal_1}} = Equal[T=DT_INT64, _device="/job:localhost/replica:0/task:0/device:CPU:0"](ArgMax_2, ArgMax_3)]]
thank you so much
python tensorflow
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to build a CNN network with tensorflow package. My train data sets are 237 images with 100X100 in 6 classes and my test sets are 30 images with same size and classes.
Everything is going well except last part that I want to measure accuracy with
acc=tf.reduce_mean(tf.cast(matches,tf.float32))
I cannot understand why it make error while I am testing with test sets (both data and label) that it is compatible “(30,100,100,1) vs (30,6)”.
Can anyone explain why and what is possible solution.
Note: when I apply batch size 30 (equal to number my test set row) on train data it works.i assume the model expect that the train and test set should be equal number of row that it doesn't make set (usually 70% train vs 30% test) i checked some post with same error title but i couldn’t get it, in face, i think although the error title was same but their problem was different. mostly they had issue with flatten layer.
screenshot from data set info
enter image description here
here is the simple code
…
convo_1=…(x_img,shape=[5,5,1,32])
convo_1_pooling=…(convo_1)
convo_2=…(x_img,shape=[5,5,32,64])
convo_2_pooling=…(convo_2)
convo_3=…(x_img,shape=[5,5,64,128])
convo_3_pooling=…(convo_3)
convo_3_flat=tf.reshape(convo_3_pooling,[-1,13*13*128])
full_layer_one=tf.nn.relu(sp.normal_full_layer(convo_3_flat,21632))
# DROPOUT
hold_prob=tf.placeholder(tf.float32)
full_one_dropout=tf.nn.dropout(full_layer_one,keep_prob=hold_prob)
y_pred=sp.normal_full_layer(full_one_dropout,6)
# LOOS FUNCTION
cross_entropy=tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y,logits=y_pred))
# OPTIMIZER
optimizer=tf.train.AdamOptimizer(learning_rate=learning_rate)
train=optimizer.minimize(cross_entropy)
with tf.Session() as sess:
sess.run(init)
b=0
for i in range(training_iters):
sess.run(train,feed_dict={x_img:train_x, y:train_y,hold_prob:.5})
if i%2 ==0:
print("NO STEP:{}",format(i))
print("ACCURACY: ")
matches=tf.equal(tf.argmax(y_pred,1),tf.argmax(train_y,1))
acc=tf.reduce_mean(tf.cast(matches,tf.float32))
print(sess.run(acc,feed_dict={x_img:test_x, y:test_y, hold_prob:1.0}))
print('n')
and this is the error
InvalidArgumentError: Incompatible shapes: [30] vs. [237]
[[{{node Equal_1}} = Equal[T=DT_INT64, _device="/job:localhost/replica:0/task:0/device:CPU:0"](ArgMax_2, ArgMax_3)]]
thank you so much
python tensorflow
I am trying to build a CNN network with tensorflow package. My train data sets are 237 images with 100X100 in 6 classes and my test sets are 30 images with same size and classes.
Everything is going well except last part that I want to measure accuracy with
acc=tf.reduce_mean(tf.cast(matches,tf.float32))
I cannot understand why it make error while I am testing with test sets (both data and label) that it is compatible “(30,100,100,1) vs (30,6)”.
Can anyone explain why and what is possible solution.
Note: when I apply batch size 30 (equal to number my test set row) on train data it works.i assume the model expect that the train and test set should be equal number of row that it doesn't make set (usually 70% train vs 30% test) i checked some post with same error title but i couldn’t get it, in face, i think although the error title was same but their problem was different. mostly they had issue with flatten layer.
screenshot from data set info
enter image description here
here is the simple code
…
convo_1=…(x_img,shape=[5,5,1,32])
convo_1_pooling=…(convo_1)
convo_2=…(x_img,shape=[5,5,32,64])
convo_2_pooling=…(convo_2)
convo_3=…(x_img,shape=[5,5,64,128])
convo_3_pooling=…(convo_3)
convo_3_flat=tf.reshape(convo_3_pooling,[-1,13*13*128])
full_layer_one=tf.nn.relu(sp.normal_full_layer(convo_3_flat,21632))
# DROPOUT
hold_prob=tf.placeholder(tf.float32)
full_one_dropout=tf.nn.dropout(full_layer_one,keep_prob=hold_prob)
y_pred=sp.normal_full_layer(full_one_dropout,6)
# LOOS FUNCTION
cross_entropy=tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y,logits=y_pred))
# OPTIMIZER
optimizer=tf.train.AdamOptimizer(learning_rate=learning_rate)
train=optimizer.minimize(cross_entropy)
with tf.Session() as sess:
sess.run(init)
b=0
for i in range(training_iters):
sess.run(train,feed_dict={x_img:train_x, y:train_y,hold_prob:.5})
if i%2 ==0:
print("NO STEP:{}",format(i))
print("ACCURACY: ")
matches=tf.equal(tf.argmax(y_pred,1),tf.argmax(train_y,1))
acc=tf.reduce_mean(tf.cast(matches,tf.float32))
print(sess.run(acc,feed_dict={x_img:test_x, y:test_y, hold_prob:1.0}))
print('n')
and this is the error
InvalidArgumentError: Incompatible shapes: [30] vs. [237]
[[{{node Equal_1}} = Equal[T=DT_INT64, _device="/job:localhost/replica:0/task:0/device:CPU:0"](ArgMax_2, ArgMax_3)]]
thank you so much
python tensorflow
python tensorflow
asked Nov 7 at 12:24
Muhammad
12
12
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53189435%2fincompatible-shapes-of-test-and-train-set-in-tensorflow%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown