GithubHelp home page GithubHelp logo

Comments (4)

jungwon-choi avatar jungwon-choi commented on June 15, 2024

plus you have to edit each train.py as below
from

info = {
            'loss': loss,
            'sr_loss': sr_loss,
            'dm_loss': dm_loss,
            'psnr': cur_psnr
       }

to

 info = {
            'loss': loss.item(),
            'sr_loss': sr_loss.item(),
            'dm_loss': dm_loss.item(),
            'psnr': cur_psnr
        }

from tenet.

jungwon-choi avatar jungwon-choi commented on June 15, 2024

However, I found that tensorflow requires a lot of memory just to log the losses.
So, I changed the code with tensorboard for pytorch.

# import tensorflow as tf
from torch.utils.tensorboard import SummaryWriter
import numpy as np

try:
    from StringIO import StringIO  # Python 2.7
except ImportError:
    from io import BytesIO         # Python 3.x


class Tf_Logger(object):

    def __init__(self, log_dir):
        """Create a summary writer logging to log_dir."""
        self.writer = SummaryWriter(log_dir)

    def scalar_summary(self, tag, value, step):
        """Log a scalar variable."""
        self.writer.add_scalar(tag, value, step)

    def image_summary(self, tag, images, step):
        """Log a list of images."""
        for i, img in enumerate(images):
            if len(img.shape) == 2:
                img = img[np.newaxis,:,:,np.newaxis]
            elif len(img.shape) == 3:
                img = img[np.newaxis,:,:,:]
            self.writer.add_image('%s/%d' % (tag, i), img, step)
    
    def histo_summary(self, tag, values, step, bins=1000):
        """Log a histogram of the tensor of values."""

        # Create a histogram using numpy
        counts, bin_edges = np.histogram(values, bins=bins)

        # Fill the fields of the histogram proto
        hist = tf.HistogramProto()
        hist.min = float(np.min(values))
        hist.max = float(np.max(values))
        hist.num = int(np.prod(values.shape))
        hist.sum = float(np.sum(values))
        hist.sum_squares = float(np.sum(values**2))

        # Drop the start of the first bin
        bin_edges = bin_edges[1:]

        # Add bin edges and counts
        for edge in bin_edges:
            hist.bucket_limit.append(edge)
        for c in counts:
            hist.bucket.append(c)

        # Create and write Summary
        self.writer.add_histogram(tag, hist, step)

from tenet.

jungwon-choi avatar jungwon-choi commented on June 15, 2024

In this case, you don't need to transpose RGB images at valid() function.

img = img[0:1, 0:4]
img = torch.clamp(img.cpu()[0, 0], 0, 1).detach().numpy()
gt = torch.clamp(gt.cpu()[0], 0, 1).detach().numpy()
# gt = np.transpose(gt, [1, 2, 0]) 	# permute
output = torch.clamp(output.cpu()[0], 0, 1).detach().numpy()
# output = np.transpose(output, [1, 2, 0])

from tenet.

guochengqian avatar guochengqian commented on June 15, 2024

@jungwon-choi thank you for your updates! Really helpful.

from tenet.

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.