Training loss is available but val_loss = nan












0















I am trying to apply batch normalization on an U-net and I have the following architecture:



inputs = Input((IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS))
s = Lambda(lambda x: x / 255) (inputs)
width = 32
activation = 'sigmoid'
c1 = Conv2D(width, (3, 3), activation='elu', padding='same') (s)
c1 = Conv2D(width, (3, 3), activation='elu', padding='same') (c1)
c1 = BatchNormalization()(c1)
p1 = MaxPooling2D((2, 2)) (c1)
#p1 = Dropout(0.2)(p1)
c2 = Conv2D(width*2, (3, 3), activation='elu', padding='same') (p1)
c2 = Conv2D(width*2, (3, 3), activation='elu', padding='same') (c2)
c2 = BatchNormalization()(c2)
p2 = MaxPooling2D((2, 2)) (c2)
#p2 = Dropout(0.2)(p2)

c3 = Conv2D(width*4, (3, 3), activation='elu', padding='same') (p2)
c3 = Conv2D(width*4, (3, 3), activation='elu', padding='same') (c3)
c3 = BatchNormalization()(c3)
p3 = MaxPooling2D((2, 2)) (c3)
#p3 = Dropout(0.2)(p3)

c4 = Conv2D(width*8, (3, 3), activation='elu', padding='same') (p3)
c4 = Conv2D(width*8, (3, 3), activation='elu', padding='same') (c4)
c4 = BatchNormalization()(c4)
p4 = MaxPooling2D(pool_size=(2, 2)) (c4)
#p4 = Dropout(0.2)(p4)

c5 = Conv2D(width*16, (3, 3), activation='elu', padding='same') (p4)
c5 = Conv2D(width*16, (3, 3), activation='elu', padding='same') (c5)

u6 = Conv2DTranspose(width*8, (2, 2), strides=(2, 2), padding='same') (c5)
u6 = concatenate([u6, c4])
#u6 = Dropout(0.2)(u6)
c6 = Conv2D(width*8, (3, 3), activation='elu', padding='same') (u6)
c6 = Conv2D(width*8, (3, 3), activation='elu', padding='same') (c6)

u7 = Conv2DTranspose(width*4, (2, 2), strides=(2, 2), padding='same') (c6)
u7 = concatenate([u7, c3])
#u7 = Dropout(0.2)(u7)
c7 = Conv2D(width*4, (3, 3), activation='elu', padding='same') (u7)
c7 = Conv2D(width*4, (3, 3), activation='elu', padding='same') (c7)

u8 = Conv2DTranspose(width*2, (2, 2), strides=(2, 2), padding='same') (c7)
u8 = concatenate([u8, c2])
#u8 = Dropout(0.2)(u8)
c8 = Conv2D(width*2, (3, 3), activation='elu', padding='same') (u8)
c8 = Conv2D(width*2, (3, 3), activation='elu', padding='same') (c8)

u9 = Conv2DTranspose(width, (2, 2), strides=(2, 2), padding='same') (c8)
u9 = concatenate([u9, c1], axis=3)
#u9 = Dropout(0.2)(u9)
c9 = Conv2D(width, (3, 3), activation='elu', padding='same') (u9)
c9 = Conv2D(width, (3, 3), activation='elu', padding='same') (c9)

outputs = Conv2D(num_classes, (1, 1), activation=activation) (c9)
model = Model(inputs=[inputs], outputs=[outputs])


What happens is the training loss very quickly approaches a plateau value (within 2 epochs) and the whole time val loss remains nan. I looked at other posts and some say it's because the dimension ordering is wrong. But if this were true, then i shouldn't be getting training loss either. Other reasons are that the value is diminishing due to learning rate. However, this reason too is offset by the fact that I am getting a loss for the training. What am I doing wrong?










share|improve this question



























    0















    I am trying to apply batch normalization on an U-net and I have the following architecture:



    inputs = Input((IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS))
    s = Lambda(lambda x: x / 255) (inputs)
    width = 32
    activation = 'sigmoid'
    c1 = Conv2D(width, (3, 3), activation='elu', padding='same') (s)
    c1 = Conv2D(width, (3, 3), activation='elu', padding='same') (c1)
    c1 = BatchNormalization()(c1)
    p1 = MaxPooling2D((2, 2)) (c1)
    #p1 = Dropout(0.2)(p1)
    c2 = Conv2D(width*2, (3, 3), activation='elu', padding='same') (p1)
    c2 = Conv2D(width*2, (3, 3), activation='elu', padding='same') (c2)
    c2 = BatchNormalization()(c2)
    p2 = MaxPooling2D((2, 2)) (c2)
    #p2 = Dropout(0.2)(p2)

    c3 = Conv2D(width*4, (3, 3), activation='elu', padding='same') (p2)
    c3 = Conv2D(width*4, (3, 3), activation='elu', padding='same') (c3)
    c3 = BatchNormalization()(c3)
    p3 = MaxPooling2D((2, 2)) (c3)
    #p3 = Dropout(0.2)(p3)

    c4 = Conv2D(width*8, (3, 3), activation='elu', padding='same') (p3)
    c4 = Conv2D(width*8, (3, 3), activation='elu', padding='same') (c4)
    c4 = BatchNormalization()(c4)
    p4 = MaxPooling2D(pool_size=(2, 2)) (c4)
    #p4 = Dropout(0.2)(p4)

    c5 = Conv2D(width*16, (3, 3), activation='elu', padding='same') (p4)
    c5 = Conv2D(width*16, (3, 3), activation='elu', padding='same') (c5)

    u6 = Conv2DTranspose(width*8, (2, 2), strides=(2, 2), padding='same') (c5)
    u6 = concatenate([u6, c4])
    #u6 = Dropout(0.2)(u6)
    c6 = Conv2D(width*8, (3, 3), activation='elu', padding='same') (u6)
    c6 = Conv2D(width*8, (3, 3), activation='elu', padding='same') (c6)

    u7 = Conv2DTranspose(width*4, (2, 2), strides=(2, 2), padding='same') (c6)
    u7 = concatenate([u7, c3])
    #u7 = Dropout(0.2)(u7)
    c7 = Conv2D(width*4, (3, 3), activation='elu', padding='same') (u7)
    c7 = Conv2D(width*4, (3, 3), activation='elu', padding='same') (c7)

    u8 = Conv2DTranspose(width*2, (2, 2), strides=(2, 2), padding='same') (c7)
    u8 = concatenate([u8, c2])
    #u8 = Dropout(0.2)(u8)
    c8 = Conv2D(width*2, (3, 3), activation='elu', padding='same') (u8)
    c8 = Conv2D(width*2, (3, 3), activation='elu', padding='same') (c8)

    u9 = Conv2DTranspose(width, (2, 2), strides=(2, 2), padding='same') (c8)
    u9 = concatenate([u9, c1], axis=3)
    #u9 = Dropout(0.2)(u9)
    c9 = Conv2D(width, (3, 3), activation='elu', padding='same') (u9)
    c9 = Conv2D(width, (3, 3), activation='elu', padding='same') (c9)

    outputs = Conv2D(num_classes, (1, 1), activation=activation) (c9)
    model = Model(inputs=[inputs], outputs=[outputs])


    What happens is the training loss very quickly approaches a plateau value (within 2 epochs) and the whole time val loss remains nan. I looked at other posts and some say it's because the dimension ordering is wrong. But if this were true, then i shouldn't be getting training loss either. Other reasons are that the value is diminishing due to learning rate. However, this reason too is offset by the fact that I am getting a loss for the training. What am I doing wrong?










    share|improve this question

























      0












      0








      0








      I am trying to apply batch normalization on an U-net and I have the following architecture:



      inputs = Input((IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS))
      s = Lambda(lambda x: x / 255) (inputs)
      width = 32
      activation = 'sigmoid'
      c1 = Conv2D(width, (3, 3), activation='elu', padding='same') (s)
      c1 = Conv2D(width, (3, 3), activation='elu', padding='same') (c1)
      c1 = BatchNormalization()(c1)
      p1 = MaxPooling2D((2, 2)) (c1)
      #p1 = Dropout(0.2)(p1)
      c2 = Conv2D(width*2, (3, 3), activation='elu', padding='same') (p1)
      c2 = Conv2D(width*2, (3, 3), activation='elu', padding='same') (c2)
      c2 = BatchNormalization()(c2)
      p2 = MaxPooling2D((2, 2)) (c2)
      #p2 = Dropout(0.2)(p2)

      c3 = Conv2D(width*4, (3, 3), activation='elu', padding='same') (p2)
      c3 = Conv2D(width*4, (3, 3), activation='elu', padding='same') (c3)
      c3 = BatchNormalization()(c3)
      p3 = MaxPooling2D((2, 2)) (c3)
      #p3 = Dropout(0.2)(p3)

      c4 = Conv2D(width*8, (3, 3), activation='elu', padding='same') (p3)
      c4 = Conv2D(width*8, (3, 3), activation='elu', padding='same') (c4)
      c4 = BatchNormalization()(c4)
      p4 = MaxPooling2D(pool_size=(2, 2)) (c4)
      #p4 = Dropout(0.2)(p4)

      c5 = Conv2D(width*16, (3, 3), activation='elu', padding='same') (p4)
      c5 = Conv2D(width*16, (3, 3), activation='elu', padding='same') (c5)

      u6 = Conv2DTranspose(width*8, (2, 2), strides=(2, 2), padding='same') (c5)
      u6 = concatenate([u6, c4])
      #u6 = Dropout(0.2)(u6)
      c6 = Conv2D(width*8, (3, 3), activation='elu', padding='same') (u6)
      c6 = Conv2D(width*8, (3, 3), activation='elu', padding='same') (c6)

      u7 = Conv2DTranspose(width*4, (2, 2), strides=(2, 2), padding='same') (c6)
      u7 = concatenate([u7, c3])
      #u7 = Dropout(0.2)(u7)
      c7 = Conv2D(width*4, (3, 3), activation='elu', padding='same') (u7)
      c7 = Conv2D(width*4, (3, 3), activation='elu', padding='same') (c7)

      u8 = Conv2DTranspose(width*2, (2, 2), strides=(2, 2), padding='same') (c7)
      u8 = concatenate([u8, c2])
      #u8 = Dropout(0.2)(u8)
      c8 = Conv2D(width*2, (3, 3), activation='elu', padding='same') (u8)
      c8 = Conv2D(width*2, (3, 3), activation='elu', padding='same') (c8)

      u9 = Conv2DTranspose(width, (2, 2), strides=(2, 2), padding='same') (c8)
      u9 = concatenate([u9, c1], axis=3)
      #u9 = Dropout(0.2)(u9)
      c9 = Conv2D(width, (3, 3), activation='elu', padding='same') (u9)
      c9 = Conv2D(width, (3, 3), activation='elu', padding='same') (c9)

      outputs = Conv2D(num_classes, (1, 1), activation=activation) (c9)
      model = Model(inputs=[inputs], outputs=[outputs])


      What happens is the training loss very quickly approaches a plateau value (within 2 epochs) and the whole time val loss remains nan. I looked at other posts and some say it's because the dimension ordering is wrong. But if this were true, then i shouldn't be getting training loss either. Other reasons are that the value is diminishing due to learning rate. However, this reason too is offset by the fact that I am getting a loss for the training. What am I doing wrong?










      share|improve this question














      I am trying to apply batch normalization on an U-net and I have the following architecture:



      inputs = Input((IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS))
      s = Lambda(lambda x: x / 255) (inputs)
      width = 32
      activation = 'sigmoid'
      c1 = Conv2D(width, (3, 3), activation='elu', padding='same') (s)
      c1 = Conv2D(width, (3, 3), activation='elu', padding='same') (c1)
      c1 = BatchNormalization()(c1)
      p1 = MaxPooling2D((2, 2)) (c1)
      #p1 = Dropout(0.2)(p1)
      c2 = Conv2D(width*2, (3, 3), activation='elu', padding='same') (p1)
      c2 = Conv2D(width*2, (3, 3), activation='elu', padding='same') (c2)
      c2 = BatchNormalization()(c2)
      p2 = MaxPooling2D((2, 2)) (c2)
      #p2 = Dropout(0.2)(p2)

      c3 = Conv2D(width*4, (3, 3), activation='elu', padding='same') (p2)
      c3 = Conv2D(width*4, (3, 3), activation='elu', padding='same') (c3)
      c3 = BatchNormalization()(c3)
      p3 = MaxPooling2D((2, 2)) (c3)
      #p3 = Dropout(0.2)(p3)

      c4 = Conv2D(width*8, (3, 3), activation='elu', padding='same') (p3)
      c4 = Conv2D(width*8, (3, 3), activation='elu', padding='same') (c4)
      c4 = BatchNormalization()(c4)
      p4 = MaxPooling2D(pool_size=(2, 2)) (c4)
      #p4 = Dropout(0.2)(p4)

      c5 = Conv2D(width*16, (3, 3), activation='elu', padding='same') (p4)
      c5 = Conv2D(width*16, (3, 3), activation='elu', padding='same') (c5)

      u6 = Conv2DTranspose(width*8, (2, 2), strides=(2, 2), padding='same') (c5)
      u6 = concatenate([u6, c4])
      #u6 = Dropout(0.2)(u6)
      c6 = Conv2D(width*8, (3, 3), activation='elu', padding='same') (u6)
      c6 = Conv2D(width*8, (3, 3), activation='elu', padding='same') (c6)

      u7 = Conv2DTranspose(width*4, (2, 2), strides=(2, 2), padding='same') (c6)
      u7 = concatenate([u7, c3])
      #u7 = Dropout(0.2)(u7)
      c7 = Conv2D(width*4, (3, 3), activation='elu', padding='same') (u7)
      c7 = Conv2D(width*4, (3, 3), activation='elu', padding='same') (c7)

      u8 = Conv2DTranspose(width*2, (2, 2), strides=(2, 2), padding='same') (c7)
      u8 = concatenate([u8, c2])
      #u8 = Dropout(0.2)(u8)
      c8 = Conv2D(width*2, (3, 3), activation='elu', padding='same') (u8)
      c8 = Conv2D(width*2, (3, 3), activation='elu', padding='same') (c8)

      u9 = Conv2DTranspose(width, (2, 2), strides=(2, 2), padding='same') (c8)
      u9 = concatenate([u9, c1], axis=3)
      #u9 = Dropout(0.2)(u9)
      c9 = Conv2D(width, (3, 3), activation='elu', padding='same') (u9)
      c9 = Conv2D(width, (3, 3), activation='elu', padding='same') (c9)

      outputs = Conv2D(num_classes, (1, 1), activation=activation) (c9)
      model = Model(inputs=[inputs], outputs=[outputs])


      What happens is the training loss very quickly approaches a plateau value (within 2 epochs) and the whole time val loss remains nan. I looked at other posts and some say it's because the dimension ordering is wrong. But if this were true, then i shouldn't be getting training loss either. Other reasons are that the value is diminishing due to learning rate. However, this reason too is offset by the fact that I am getting a loss for the training. What am I doing wrong?







      keras neural-network






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 30 '18 at 9:33









      JonathanJonathan

      422122




      422122
























          1 Answer
          1






          active

          oldest

          votes


















          0














          if num_classes>1 your activation should be "softmax" and not "sigmoid" and then it'll probably work






          share|improve this answer
























          • I changed it to softmax, it still didn't work

            – Jonathan
            Dec 30 '18 at 21:49











          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%2f53976526%2ftraining-loss-is-available-but-val-loss-nan%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          if num_classes>1 your activation should be "softmax" and not "sigmoid" and then it'll probably work






          share|improve this answer
























          • I changed it to softmax, it still didn't work

            – Jonathan
            Dec 30 '18 at 21:49
















          0














          if num_classes>1 your activation should be "softmax" and not "sigmoid" and then it'll probably work






          share|improve this answer
























          • I changed it to softmax, it still didn't work

            – Jonathan
            Dec 30 '18 at 21:49














          0












          0








          0







          if num_classes>1 your activation should be "softmax" and not "sigmoid" and then it'll probably work






          share|improve this answer













          if num_classes>1 your activation should be "softmax" and not "sigmoid" and then it'll probably work







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 30 '18 at 10:08









          Jenia GolbsteinJenia Golbstein

          1187




          1187













          • I changed it to softmax, it still didn't work

            – Jonathan
            Dec 30 '18 at 21:49



















          • I changed it to softmax, it still didn't work

            – Jonathan
            Dec 30 '18 at 21:49

















          I changed it to softmax, it still didn't work

          – Jonathan
          Dec 30 '18 at 21:49





          I changed it to softmax, it still didn't work

          – Jonathan
          Dec 30 '18 at 21:49


















          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%2f53976526%2ftraining-loss-is-available-but-val-loss-nan%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

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas