All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.py.rules.python.S6919.html Maven / Gradle / Ivy

There is a newer version: 4.23.0.17664
Show newest version

This rule raises an issue when the input_shape is specified in a tensorflow.keras.Model subclass.

Why is this an issue?

Keras provides a full-featured model class called tensorflow.keras.Model. It inherits from tensorflow.keras.layers.Layer, so a Keras model can be used and nested in the same way as Keras layers. Keras models come with extra functionality that makes them easy to train, evaluate, load, save, and even train on multiple machines.

As the tensorflow.keras.Model class inherits from the 'tensorflow.keras.layers' you do not need to specify input_shape in a subclassed model; this argument will be ignored.

How to fix it

Do not specify input_shape in a tf.keras.Model subclasses

Code examples

Noncompliant code example

import tensorflow as tf

class MyModel(tf.keras.Model):
    def __init__(self):
        super(MyModel, self).__init__(input_shape=...)  # Noncompliant: this parameter will be ignored

Compliant solution

import tensorflow as tf

class MyModel(tf.keras.Model):
    def __init__(self):
        super(MyModel, self).__init__()  # OK

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy