Cannot add tensor to the batch: number of elements does not matchnoisy validation loss (versus epoch) when using batch normalizationparameters value in tensorflowCombining 2D CNN with GRU in KerasObject center detection using Convnet is always returning center of image rather than center of objectTensorflow - ValueError: Rank mismatch:Implementing a generator for keras results in worse resultsEpoch's steps taking too long on GPUThe output NN is image an image with values 0 or 1, but the expected are a range of integers between 0 and 255Is it possible to train a CNN starting at an intermediate layer (in general and in Keras)?'Sequential' object has no attribute 'loss' - When I used GridSearchCV to tuning my Keras model

How should I write this passage to make it the most readable?

Why aren't rockets built with truss structures inside their fuel & oxidizer tanks to increase structural strength?

Is this n-speak?

Graphs for which a calculus student can reasonably compute the arclength

How do I call a 6-digit Australian phone number with a US-based mobile phone?

Why is there a large performance impact when looping over an array over 240 elements?

Luggage Storage at Szechenyi Baths

Creating some gif with tikz: Any idea to get better result?

Does fossil fuels use since 1990 account for half of all the fossil fuels used in history?

Are there any lower-level means of travelling between planes of existence?

Causal Diagrams using Wolfram?

Why aren't rainbows blurred-out into nothing after they are produced?

How far did Gandalf and the Balrog drop from the bridge in Moria?

Are there any cons in using rounded corners for bar graphs?

What is the safest way to leave my MacBook on 24/7 with macOS Mojave?

Escape Velocity - Won't the orbital path just become larger with higher initial velocity?

Why command hierarchy, if the chain of command is standing next to each other?

How much can I judge a company based on a phone screening?

A trip to the library

What kind of liquid can be seen 'leaking' from the upper surface of the wing of a Boeing 737-800?

How was the murder committed?

"Mouth-breathing" as slang for stupidity

Pokemon Go: Gym Badge Over-completed?

Help, I cannot decide when to start the story



Cannot add tensor to the batch: number of elements does not match


noisy validation loss (versus epoch) when using batch normalizationparameters value in tensorflowCombining 2D CNN with GRU in KerasObject center detection using Convnet is always returning center of image rather than center of objectTensorflow - ValueError: Rank mismatch:Implementing a generator for keras results in worse resultsEpoch's steps taking too long on GPUThe output NN is image an image with values 0 or 1, but the expected are a range of integers between 0 and 255Is it possible to train a CNN starting at an intermediate layer (in general and in Keras)?'Sequential' object has no attribute 'loss' - When I used GridSearchCV to tuning my Keras model






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I am experiencing a problem while training a neuronal network consisting of two convolution layers. I have a bunch of images that I normalize and resize to shape (28,28,3) within an "make iterator" function.



The training phase runs then normally till I encounter this error :



"InvalidArgumentError: Cannot add tensor to the batch: number of elements does not match. Shapes are: [tensor]: [28,28,4], [batch]: [28,28,3]
[[node IteratorGetNext_31]]"



I first tried to load some images and resize them using opencv and it then worked. However given the size of my dataset I need to use iterators and dataset objects provided by keras util to train my network on all the images I have.



Here is the code for the iterator:



def make_iterator(filenames, labels, batch_size):
dataset = tf.data.Dataset.from_tensor_slices((filenames, labels))

def parse(filename, label):
image = tf.read_file(filename)
image = tf.image.decode_jpeg(image)
image = tf.cast(image, tf.float32)
image = tf.image.resize(image, (28,28))
image = tf.reshape(image, [28,28,3])
image = image / 256
return 'image': image, 'label': label

dataset = dataset.apply(tf.data.experimental.map_and_batch(
map_func=parse, batch_size=batch_size, num_parallel_batches=8))

return dataset.make_one_shot_iterator()


Here are the details of my Convnet:



model = keras.Sequential()
model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=(28, 28, 3)))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(2, activation='softmax'))


And last here are the parameters for the fit phase:



history = model.fit(images
, labels
, epochs=200
, steps_per_epoch= len(train_image_labels) // batch_size
)


Thanks in advance :)










share|improve this question






























    1















    I am experiencing a problem while training a neuronal network consisting of two convolution layers. I have a bunch of images that I normalize and resize to shape (28,28,3) within an "make iterator" function.



    The training phase runs then normally till I encounter this error :



    "InvalidArgumentError: Cannot add tensor to the batch: number of elements does not match. Shapes are: [tensor]: [28,28,4], [batch]: [28,28,3]
    [[node IteratorGetNext_31]]"



    I first tried to load some images and resize them using opencv and it then worked. However given the size of my dataset I need to use iterators and dataset objects provided by keras util to train my network on all the images I have.



    Here is the code for the iterator:



    def make_iterator(filenames, labels, batch_size):
    dataset = tf.data.Dataset.from_tensor_slices((filenames, labels))

    def parse(filename, label):
    image = tf.read_file(filename)
    image = tf.image.decode_jpeg(image)
    image = tf.cast(image, tf.float32)
    image = tf.image.resize(image, (28,28))
    image = tf.reshape(image, [28,28,3])
    image = image / 256
    return 'image': image, 'label': label

    dataset = dataset.apply(tf.data.experimental.map_and_batch(
    map_func=parse, batch_size=batch_size, num_parallel_batches=8))

    return dataset.make_one_shot_iterator()


    Here are the details of my Convnet:



    model = keras.Sequential()
    model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=(28, 28, 3)))
    model.add(Conv2D(64, (3, 3), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Dropout(0.25))
    model.add(Flatten())
    model.add(Dense(128, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(2, activation='softmax'))


    And last here are the parameters for the fit phase:



    history = model.fit(images
    , labels
    , epochs=200
    , steps_per_epoch= len(train_image_labels) // batch_size
    )


    Thanks in advance :)










    share|improve this question


























      1












      1








      1








      I am experiencing a problem while training a neuronal network consisting of two convolution layers. I have a bunch of images that I normalize and resize to shape (28,28,3) within an "make iterator" function.



      The training phase runs then normally till I encounter this error :



      "InvalidArgumentError: Cannot add tensor to the batch: number of elements does not match. Shapes are: [tensor]: [28,28,4], [batch]: [28,28,3]
      [[node IteratorGetNext_31]]"



      I first tried to load some images and resize them using opencv and it then worked. However given the size of my dataset I need to use iterators and dataset objects provided by keras util to train my network on all the images I have.



      Here is the code for the iterator:



      def make_iterator(filenames, labels, batch_size):
      dataset = tf.data.Dataset.from_tensor_slices((filenames, labels))

      def parse(filename, label):
      image = tf.read_file(filename)
      image = tf.image.decode_jpeg(image)
      image = tf.cast(image, tf.float32)
      image = tf.image.resize(image, (28,28))
      image = tf.reshape(image, [28,28,3])
      image = image / 256
      return 'image': image, 'label': label

      dataset = dataset.apply(tf.data.experimental.map_and_batch(
      map_func=parse, batch_size=batch_size, num_parallel_batches=8))

      return dataset.make_one_shot_iterator()


      Here are the details of my Convnet:



      model = keras.Sequential()
      model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=(28, 28, 3)))
      model.add(Conv2D(64, (3, 3), activation='relu'))
      model.add(MaxPooling2D(pool_size=(2, 2)))
      model.add(Dropout(0.25))
      model.add(Flatten())
      model.add(Dense(128, activation='relu'))
      model.add(Dropout(0.5))
      model.add(Dense(2, activation='softmax'))


      And last here are the parameters for the fit phase:



      history = model.fit(images
      , labels
      , epochs=200
      , steps_per_epoch= len(train_image_labels) // batch_size
      )


      Thanks in advance :)










      share|improve this question














      I am experiencing a problem while training a neuronal network consisting of two convolution layers. I have a bunch of images that I normalize and resize to shape (28,28,3) within an "make iterator" function.



      The training phase runs then normally till I encounter this error :



      "InvalidArgumentError: Cannot add tensor to the batch: number of elements does not match. Shapes are: [tensor]: [28,28,4], [batch]: [28,28,3]
      [[node IteratorGetNext_31]]"



      I first tried to load some images and resize them using opencv and it then worked. However given the size of my dataset I need to use iterators and dataset objects provided by keras util to train my network on all the images I have.



      Here is the code for the iterator:



      def make_iterator(filenames, labels, batch_size):
      dataset = tf.data.Dataset.from_tensor_slices((filenames, labels))

      def parse(filename, label):
      image = tf.read_file(filename)
      image = tf.image.decode_jpeg(image)
      image = tf.cast(image, tf.float32)
      image = tf.image.resize(image, (28,28))
      image = tf.reshape(image, [28,28,3])
      image = image / 256
      return 'image': image, 'label': label

      dataset = dataset.apply(tf.data.experimental.map_and_batch(
      map_func=parse, batch_size=batch_size, num_parallel_batches=8))

      return dataset.make_one_shot_iterator()


      Here are the details of my Convnet:



      model = keras.Sequential()
      model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=(28, 28, 3)))
      model.add(Conv2D(64, (3, 3), activation='relu'))
      model.add(MaxPooling2D(pool_size=(2, 2)))
      model.add(Dropout(0.25))
      model.add(Flatten())
      model.add(Dense(128, activation='relu'))
      model.add(Dropout(0.5))
      model.add(Dense(2, activation='softmax'))


      And last here are the parameters for the fit phase:



      history = model.fit(images
      , labels
      , epochs=200
      , steps_per_epoch= len(train_image_labels) // batch_size
      )


      Thanks in advance :)







      keras deep-learning iterator batch-processing






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 10:52









      mthanmthan

      63 bronze badges




      63 bronze badges

























          0






          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',
          autoActivateHeartbeat: false,
          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%2f55375435%2fcannot-add-tensor-to-the-batch-number-of-elements-does-not-match%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes




          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55375435%2fcannot-add-tensor-to-the-batch-number-of-elements-does-not-match%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







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현