tensorboard icon indicating copy to clipboard operation
tensorboard copied to clipboard

Connection bettewn Loss and Optimizer

Open andrewjavao opened this issue 9 years ago • 8 comments

If the graph has a total loss that is added up by two scalars: like loss = cross_entropy + regulizer, or like in GAN discriminater_loss = loss_real + loss_fake And when I add that total loss to a name scope "loss", I found there's no connection bettewn "loss" and the optimizer. Sometimes it can be confusing, is there any reason not to do that? Or I'm just doing wrong?

andrewjavao avatar Oct 19 '17 16:10 andrewjavao

Could you please provide a screenshot of the graph explorer visualization? Often, there should be a dataflow edge from the loss op to the gradient op within the optimizer.

chihuahua avatar Oct 20 '17 18:10 chihuahua

Sure 1

It's GAN, and I'was adding up those two losses, and optimizing the total loss

andrewjavao avatar Oct 21 '17 02:10 andrewjavao

Hmm, you noted placing the 2 ops in the same scope, in which case they should be in the same metanode ... but they're 2 distinct nodes here.

Is there any way I could view the code?

chihuahua avatar Oct 23 '17 14:10 chihuahua

Sure,my pleasure I'll post part of the code defining these losses and the optimizer, I need to study the real loss and fake loss apart, so here

def define_optimize(self, real_output, fake_output):  # real_output and fake_output are batched 1-Dim labels
            with tf.name_scope(self.namescope() + "_real_loss"):
                real_loss = cross_entropy(real_output, tf.ones_like(real_output))

            with tf.name_scope(self.namescope() + "_fake_loss"):
                fake_loss = cross_entropy(fake_output, tf.zeros_like(fake_output))

            # D loss
            with tf.name_scope(self.namescope() + "_loss") as ns:
                loss = real_loss + fake_loss
            
            # find trainable variables
            trainable = [var for var in tf.trainable_variables() if self.varscope() in var.name]
            print "Training variables in {}:".format(self.varscope())
            for var in trainable:
                print var
                
            with tf.name_scope(self.namescope() + "_optimizer") as ns:
                optim = tf.train.AdamOptimizer(
                    VanillaGAN.D_LEARNING_RATE
                ).minimize(
                    loss, var_list=trainable
                )
            
            # summary
            with tf.name_scope(self.namescope()):
                self.add_summary( tf.summary.scalar("loss_real_discriminater", real_loss) )
                self.add_summary( tf.summary.scalar("loss_fake_discriminater", fake_loss) )
                self.add_summary( tf.summary.scalar("loss_discriminater", loss) )
            
            self.loss = loss
            
            return optim, self.loss, real_loss, fake_loss

It's a part of a class abstracting GAN Model, so self.namescope() and self.varscope() are just strings, self.add_summary() just helps to merge those summaries up.

The whole program is here : https://github.com/andrewjavao/GAN/, I'm not expert, so the code maybe looks ugly, apologize.

The scalar summary look like this:

3

andrewjavao avatar Oct 24 '17 03:10 andrewjavao

Hmm, could I please see the entire graph visualization? Sorry for the late reply.

chihuahua avatar Oct 25 '17 22:10 chihuahua

Sorry for the late reply. I just launched tensorboard on a server so that you can access it via internet, I'll keep the service up, but I ran into another problem that tensorboard failed to render all edges, so you can only see name scopes now. The training process goes well, so, I have no idea. Server Addr: 101.201.223.213:6006 Packed pdtxt file if you need: tensorboard_data.tar.gz New issue screenshot: 4

andrewjavao avatar Nov 06 '17 07:11 andrewjavao

@andrewjavao it looks like you're running into a missing getPathSegAtLength() issue, which was fixed in #434 and should be out in 0.4.0+. Could you try with a more recent version of TensorBoard?

nfelt avatar Dec 06 '17 23:12 nfelt

marking this older support issue as closed. Please re-open if this is still an issue for you. Thanks.

bileschi avatar Jan 02 '20 15:01 bileschi