microsoft / computervision-recipes

Best Practices, code samples, and documentation for Computer Vision.
MIT License
9.55k stars 1.18k forks source link

[ASK] Question about document cleanup #670

Closed phexic closed 2 years ago

phexic commented 2 years ago

Description

I found that training loss was very large and I didn't understand why input is multiplied by 255 when calculating StyleContentModel. @soumyadeepdey

class StyleContentModel(tf.keras.models.Model):
  def __init__(self, style_layers, content_layers):
    #tf.keras.backend.clear_session()     
    super(StyleContentModel, self).__init__()
    self.vgg =  vgg_layers(style_layers + content_layers)
    self.style_layers = style_layers
    self.content_layers = content_layers
    self.num_style_layers = len(style_layers)
    self.num_content_layers = len(content_layers)
    self.vgg.trainable = False

  def call(self, inputs):
    "Expects float input in [0,1]"
    inputs = inputs*255.0
    preprocessed_input = tf.keras.applications.vgg19.preprocess_input(inputs)
    outputs = self.vgg(preprocessed_input)

Other Comments

soumyadeepdey commented 2 years ago

It was because, the vgg19 preprocess unit expect input to be in range [0-255]

On Thu, May 19, 2022 at 1:15 PM phexic @.***> wrote:

Description

I found that training loss was very large and I didn't understand why input is multiplied by 255 when calculating StyleContentModel. @soumyadeepdey https://github.com/soumyadeepdey

class StyleContentModel(tf.keras.models.Model): def init(self, style_layers, content_layers):

tf.keras.backend.clear_session()

super(StyleContentModel, self).__init__()
self.vgg =  vgg_layers(style_layers + content_layers)
self.style_layers = style_layers
self.content_layers = content_layers
self.num_style_layers = len(style_layers)
self.num_content_layers = len(content_layers)
self.vgg.trainable = False

def call(self, inputs): "Expects float input in [0,1]" inputs = inputs*255.0 preprocessed_input = tf.keras.applications.vgg19.preprocess_input(inputs) outputs = self.vgg(preprocessed_input)

Other Comments

— Reply to this email directly, view it on GitHub https://github.com/microsoft/computervision-recipes/issues/670, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADDWKP573IGJXCK62MVK6CLVKXWSVANCNFSM5WLIS4FQ . You are receiving this because you were mentioned.Message ID: @.***>

--

Thanks and Regards Soumyadeep Dey mob no : +919433715948