0
$\begingroup$

I used following custom loss function.

def custom_loss(epo):

  def loss(y_true,y_pred):
      m=K.binary_crossentropy(y_true, y_pred)
      x=math.log10(epo)
      y=x*x
      y=(math.sqrt(y)/100)
      l=(m*(y))

      return K.mean(l, axis=-1)
  return loss

and this is my discriminator model

def Discriminator():


  inputs = Input(shape=img_shape)


  x=Conv2D(32, kernel_size=3, strides=2, padding="same")(inputs)
  x=LeakyReLU(alpha=0.2)(x)
  x=Dropout(0.25)(x, training=True)

  x=Conv2D(64, kernel_size=3, strides=2, padding="same")(x)
  x=ZeroPadding2D(padding=((0, 1), (0, 1)))(x)
  x=BatchNormalization(momentum=0.8)(x)
  x=LeakyReLU(alpha=0.2)(x)

  x=Dropout(0.25)(x, training=True)
  x=Conv2D(128, kernel_size=3, strides=2, padding="same")(x)
  x=BatchNormalization(momentum=0.8)(x)
  x=LeakyReLU(alpha=0.2)(x)

  x=Dropout(0.25)(x, training=True)
  x=Conv2D(256, kernel_size=3, strides=1, padding="same")(x)
  x=BatchNormalization(momentum=0.8)(x)
  x=LeakyReLU(alpha=0.2)(x)

  x=Dropout(0.25)(x, training=True)
  x=Flatten()(x)
  outputs=Dense(1, activation='sigmoid')(x)
  model = Model(inputs, outputs)
  #model.summary()
  img = Input(shape=img_shape)
  validity = model(img)
  return Model(img, validity)

and initialize discriminator here

D = Discriminator()
epoch=0
D.compile(loss=custom_loss(epoch), optimizer=optimizer, metrics= 
['accuracy'])
G = Generator()
z = Input(shape=(100,))
img = G(z)
D.trainable = False
valid = D(img)

i want to update epo value of loss function after each epoch in the following code

for epoch in range(epochs):

  for batch in range(batches):
      ............
     d_loss_real = D.train_on_batch(imgs, valid)
     d_loss_fake = D.train_on_batch(gen_batch, fake)
     d_loss = 0.5 * np.add(d_loss_real, d_loss_fake)
     g_loss = combined.train_on_batch(noise_batch, valid)

Are there any way for updating loss function without effecting training after compiling the model?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.