Giter Club home page Giter Club logo

Comments (5)

GerrieCrafford avatar GerrieCrafford commented on July 27, 2024 4

Since you are already in control of the training loop, you can directly log the required values for tensorboard as shown in this gist.

The relevant parts are summarized below.

Define the logging function

def write_log(callback, names, logs, batch_no):
    for name, value in zip(names, logs):
        summary = tf.Summary()
        summary_value = summary.value.add()
        summary_value.simple_value = value
        summary_value.tag = name
        callback.writer.add_summary(summary, batch_no)
        callback.writer.flush()

Setup the callback

log_path = './logs'
callback = TensorBoard(log_path)
callback.set_model(model)

Call the log function after training

d_loss = discriminator.train_on_batch...
g_loss = combined.train_on_batch...

write_log(callback, ['g_loss'], [g_loss], batch_no)
write_log(callback, ['d_loss'], [d_loss], batch_no)

from keras-gan.

ShuvenduRoy avatar ShuvenduRoy commented on July 27, 2024

Got this error
g_loss is adding properly but causing problem with d_loss

            d_loss_real = self.discriminator.train_on_batch(imgs, np.ones((half_batch, 1)))
            d_loss_fake = self.discriminator.train_on_batch(gen_imgs, np.zeros((half_batch, 1)))
            d_loss = 0.5 * np.add(d_loss_real, d_loss_fake)
TypeError: only size-1 arrays can be converted to Python scalars

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:/Research/Generative_adversarial_networks/dcgan/keras_degan.py", line 196, in <module>
    dcgan.train(callback, epochs=4000, batch_size=32, save_interval=200)
  File "D:/Research/Generative_adversarial_networks/dcgan/keras_degan.py", line 163, in train
    write_log(callback, ['d_loss'], [d_loss], epoch)
  File "D:/Research/Generative_adversarial_networks/dcgan/keras_degan.py", line 22, in write_log
    summary_value.simple_value = value
  File "C:\Users\bikas\Anaconda3\lib\site-packages\numpy\core\arrayprint.py", line 1379, in array_repr
    if type(arr) is not ndarray:
SystemError: <class 'type'> returned a result with an error set

from keras-gan.

GerrieCrafford avatar GerrieCrafford commented on July 27, 2024

@ShuvenduBikash from the error message it seems that the loss contains multiple values (did you specify metrics in the model.compile function?).

You can change the call to the log function to write_log(callback, ['d_loss'], [d_loss[0]], batch_no) if you only want to log the loss.

You should also be able to log the loss and other metrics by changing it to write_log(callback, ['d_loss', 'other_metric_name', ...], d_loss, batch_no)

from keras-gan.

ShuvenduRoy avatar ShuvenduRoy commented on July 27, 2024

@GerrieCrafford Thanks. I got the problem

Could you please give me some reference to learn details about this in details. I don't quite like the tensorflow's own website.

from keras-gan.

GerrieCrafford avatar GerrieCrafford commented on July 27, 2024

@ShuvenduBikash Glad I could help.

Unfortunately, I don't know of a reference other than TensorFlow's website (or maybe Keras' website).

from keras-gan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.