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










share|improve this question


























    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










    share|improve this question
























      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










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 7 at 12:24









      Muhammad

      12




      12





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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





















































          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







          這個網誌中的熱門文章

          Academy of Television Arts & Sciences

          L'Équipe

          1995 France bombings