-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15d9064
commit 559448c
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"title": "The \"input_shape\" parameter should not be specified for \"tf.keras.Model\" subclasses", | ||
"type": "CODE_SMELL", | ||
"status": "ready", | ||
"remediation": { | ||
"func": "Constant\/Issue", | ||
"constantCost": "5min" | ||
}, | ||
"tags": [ | ||
], | ||
"defaultSeverity": "Major", | ||
"ruleSpecification": "RSPEC-6919", | ||
"sqKey": "S6919", | ||
"scope": "All", | ||
"defaultQualityProfiles": ["Sonar way"], | ||
"quickfix": "unknown", | ||
"code": { | ||
"impacts": { | ||
"MAINTAINABILITY": "HIGH", | ||
"RELIABILITY": "MEDIUM" | ||
}, | ||
"attribute": "CONVENTIONAL" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
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 | ||
|
||
[source,python,diff-id=1,diff-type=noncompliant] | ||
---- | ||
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 | ||
|
||
[source,python,diff-id=1,diff-type=compliant] | ||
---- | ||
import tensorflow as tf | ||
class MyModel(tf.keras.Model): | ||
def __init__(self): | ||
super(MyModel, self).__init__() # OK | ||
---- | ||
|
||
== Resources | ||
=== Documentation | ||
* Tensorflow documentation - https://www.tensorflow.org/guide/intro_to_modules#keras_models[Keras models] |