Skip to content

Commit

Permalink
Merge pull request #16421 from sayakpaul:feat/convnext
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 447824881
  • Loading branch information
tensorflower-gardener committed May 10, 2022
2 parents 874557a + c9e5b0d commit 3ff21f8
Show file tree
Hide file tree
Showing 11 changed files with 839 additions and 1 deletion.
1 change: 1 addition & 0 deletions keras/api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ exports_files(
keras_packages = [
"keras",
"keras.activations",
"keras.applications.convnext",
"keras.applications.densenet",
"keras.applications.efficientnet",
"keras.applications.efficientnet_v2",
Expand Down
2 changes: 2 additions & 0 deletions keras/api/api_init_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ KERAS_API_INIT_FILES = [
"keras/__internal__/utils/__init__.py",
"keras/activations/__init__.py",
"keras/applications/__init__.py",
"keras/applications/convnext/__init__.py",
"keras/applications/densenet/__init__.py",
"keras/applications/efficientnet/__init__.py",
"keras/applications/efficientnet_v2/__init__.py",
Expand Down Expand Up @@ -85,6 +86,7 @@ KERAS_API_INIT_FILES_V1 = [
"keras/__internal__/legacy/rnn_cell/__init__.py",
"keras/activations/__init__.py",
"keras/applications/__init__.py",
"keras/applications/convnext/__init__.py",
"keras/applications/densenet/__init__.py",
"keras/applications/efficientnet/__init__.py",
"keras/applications/efficientnet_v2/__init__.py",
Expand Down
31 changes: 31 additions & 0 deletions keras/api/golden/v1/tensorflow.keras.applications.convnext.pbtxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
path: "tensorflow.keras.applications.convnext"
tf_module {
member_method {
name: "ConvNeXtBase"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_base\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "ConvNeXtLarge"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_large\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "ConvNeXtSmall"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_small\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "ConvNeXtTiny"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_tiny\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "ConvNeXtXLarge"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_xlarge\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "decode_predictions"
argspec: "args=[\'preds\', \'top\'], varargs=None, keywords=None, defaults=[\'5\'], "
}
member_method {
name: "preprocess_input"
argspec: "args=[\'x\', \'data_format\'], varargs=None, keywords=None, defaults=[\'None\'], "
}
}
24 changes: 24 additions & 0 deletions keras/api/golden/v1/tensorflow.keras.applications.pbtxt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
path: "tensorflow.keras.applications"
tf_module {
member {
name: "convnext"
mtype: "<type \'module\'>"
}
member {
name: "densenet"
mtype: "<type \'module\'>"
Expand Down Expand Up @@ -72,6 +76,26 @@ tf_module {
name: "xception"
mtype: "<type \'module\'>"
}
member_method {
name: "ConvNeXtBase"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_base\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "ConvNeXtLarge"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_large\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "ConvNeXtSmall"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_small\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "ConvNeXtTiny"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_tiny\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "ConvNeXtXLarge"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_xlarge\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "DenseNet121"
argspec: "args=[\'include_top\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
Expand Down
31 changes: 31 additions & 0 deletions keras/api/golden/v2/tensorflow.keras.applications.convnext.pbtxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
path: "tensorflow.keras.applications.convnext"
tf_module {
member_method {
name: "ConvNeXtBase"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_base\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "ConvNeXtLarge"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_large\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "ConvNeXtSmall"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_small\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "ConvNeXtTiny"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_tiny\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "ConvNeXtXLarge"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_xlarge\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "decode_predictions"
argspec: "args=[\'preds\', \'top\'], varargs=None, keywords=None, defaults=[\'5\'], "
}
member_method {
name: "preprocess_input"
argspec: "args=[\'x\', \'data_format\'], varargs=None, keywords=None, defaults=[\'None\'], "
}
}
24 changes: 24 additions & 0 deletions keras/api/golden/v2/tensorflow.keras.applications.pbtxt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
path: "tensorflow.keras.applications"
tf_module {
member {
name: "convnext"
mtype: "<type \'module\'>"
}
member {
name: "densenet"
mtype: "<type \'module\'>"
Expand Down Expand Up @@ -72,6 +76,26 @@ tf_module {
name: "xception"
mtype: "<type \'module\'>"
}
member_method {
name: "ConvNeXtBase"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_base\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "ConvNeXtLarge"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_large\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "ConvNeXtSmall"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_small\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "ConvNeXtTiny"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_tiny\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "ConvNeXtXLarge"
argspec: "args=[\'model_name\', \'include_top\', \'include_preprocessing\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'convnext_xlarge\', \'True\', \'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
}
member_method {
name: "DenseNet121"
argspec: "args=[\'include_top\', \'weights\', \'input_tensor\', \'input_shape\', \'pooling\', \'classes\', \'classifier_activation\'], varargs=None, keywords=None, defaults=[\'True\', \'imagenet\', \'None\', \'None\', \'None\', \'1000\', \'softmax\'], "
Expand Down
19 changes: 19 additions & 0 deletions keras/applications/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ py_library(
name = "applications",
srcs = [
"__init__.py",
"convnext.py",
"densenet.py",
"efficientnet.py",
"efficientnet_v2.py",
Expand Down Expand Up @@ -270,6 +271,24 @@ tf_py_test(
],
)

tf_py_test(
name = "applications_load_weight_test_convnext",
size = "large",
srcs = ["applications_load_weight_test.py"],
args = ["--module=convnext"],
main = "applications_load_weight_test.py",
tags = [
"no_oss",
"no_pip",
],
deps = [
":applications",
"//:expect_absl_installed",
"//:expect_tensorflow_installed",
"//keras/preprocessing",
],
)

tf_py_test(
name = "applications_load_weight_test_densenet",
size = "large",
Expand Down
6 changes: 6 additions & 0 deletions keras/applications/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
"""Keras Applications are premade architectures with pre-trained weights."""
# pylint: disable=g-bad-import-order

from keras.applications.convnext import ConvNeXtTiny
from keras.applications.convnext import ConvNeXtSmall
from keras.applications.convnext import ConvNeXtBase
from keras.applications.convnext import ConvNeXtLarge
from keras.applications.convnext import ConvNeXtXLarge

from keras.applications.densenet import DenseNet121
from keras.applications.densenet import DenseNet169
from keras.applications.densenet import DenseNet201
Expand Down
5 changes: 5 additions & 0 deletions keras/applications/applications_load_weight_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from absl.testing import parameterized
import numpy as np

from keras.applications import convnext
from keras.applications import densenet
from keras.applications import efficientnet
from keras.applications import efficientnet_v2
Expand Down Expand Up @@ -55,6 +56,10 @@
'mobilenet_v2': (mobilenet_v2, [mobilenet_v2.MobileNetV2]),
'mobilenet_v3_small': (mobilenet_v3, [mobilenet_v3.MobileNetV3Small]),
'mobilenet_v3_large': (mobilenet_v3, [mobilenet_v3.MobileNetV3Large]),
'convnext':
(convnext,
[convnext.ConvNeXtTiny, convnext.ConvNeXtSmall, convnext.ConvNeXtBase,
convnext.ConvNeXtLarge, convnext.ConvNeXtXLarge]),
'densenet':
(densenet,
[densenet.DenseNet121, densenet.DenseNet169, densenet.DenseNet201]),
Expand Down
14 changes: 13 additions & 1 deletion keras/applications/applications_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from absl.testing import parameterized
from keras import backend
from keras.applications import convnext
from keras.applications import densenet
from keras.applications import efficientnet
from keras.applications import efficientnet_v2
Expand All @@ -32,6 +33,7 @@
from keras.applications import vgg16
from keras.applications import vgg19
from keras.applications import xception
from keras import utils
import tensorflow.compat.v2 as tf

MODEL_LIST_NO_NASNET = [(resnet.ResNet50, 2048), (resnet.ResNet101, 2048),
Expand All @@ -45,6 +47,11 @@
(mobilenet_v2.MobileNetV2, 1280),
(mobilenet_v3.MobileNetV3Small, 576),
(mobilenet_v3.MobileNetV3Large, 960),
(convnext.ConvNeXtTiny, 768),
(convnext.ConvNeXtSmall, 768),
(convnext.ConvNeXtBase, 1024),
(convnext.ConvNeXtLarge, 1536),
(convnext.ConvNeXtXLarge, 2048),
(densenet.DenseNet121, 1024),
(densenet.DenseNet169, 1664),
(densenet.DenseNet201, 1920),
Expand Down Expand Up @@ -124,7 +131,12 @@ def test_application_base(self, app, _):
model = app(weights=None)
# Can be serialized and deserialized
config = model.get_config()
reconstructed_model = model.__class__.from_config(config)
if "ConvNeXt" in app.__name__:
custom_objects = {"LayerScale": convnext.LayerScale}
with utils.custom_object_scope(custom_objects):
reconstructed_model = model.__class__.from_config(config)
else:
reconstructed_model = model.__class__.from_config(config)
self.assertEqual(len(model.weights), len(reconstructed_model.weights))
backend.clear_session()

Expand Down
Loading

0 comments on commit 3ff21f8

Please sign in to comment.