Code Monkey home page Code Monkey logo

vktr274 / every-resnet-tensorflow Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 1.0 30 KB

Tensorflow 2 implementations of ResNet-18, ResNet-34, ResNet-50, ResNet-101, and ResNet-152 from Deep Residual Learning for Image Recognition by Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun (2015)

License: MIT License

Python 100.00%
convolutional-neural-networks keras neural-networks resnet resnet-101 resnet-152 resnet-18 resnet-34 resnet-50 tensorflow

every-resnet-tensorflow's Introduction

Every ResNet in TensorFlow 2

This repository contains implementations of every ResNet model descibed in the Deep Residual Learning for Image Recognition paper by Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun (2015). The models are implemented in the resnets.py file. The only requirement is TensorFlow 2 or higher (tested with TensorFlow 2.11.0).

The implemented models are:

  • ResNet-18
  • ResNet-34
  • ResNet-50
  • ResNet-101
  • ResNet-152

Each model is implemented as a function that follows this signature:

def ResNetN(
    input_shape: Tuple[int, int, int],
    output_units: int = 1000,
    include_top: bool = True,
    after_input: Optional[Union[Sequential, Layer]] = None,
    normalize: bool = False,
    kernel_regularizer: Optional[Union[Regularizer, str]] = None,
    kernel_initializer: Union[Initializer, str] = "he_uniform",
    flatten: bool = False,
    dropout_rate: float = 0.0,
) -> Model

where N in the function name is the number of layers in the model that should be replaced with 18, 34, 50, 101, or 152. The function takes the following parameters:

  • input_shape - Shape of the input images
  • output_units - Number of output units used in the last layer if include_top is True (default: 1000)
  • include_top - Whether to include the network top after global average pooling or the flatten layer (default: True)
  • after_input - Custom layers to add after the input like preprocessing layers as a Keras model of class tf.keras.Sequential or as a single layer of class tf.keras.layers.Layer (default: None - no custom layers)
  • normalize - Whether to normalize the input images to the range [0, 1] (default: False)
  • kernel_regularizer - Kernel regularizer of class tf.keras.regularizers.Regularizer or as a string (default: None)
  • kernel_initializer - Kernel initializer of class tf.keras.initializers.Initializer or as a string (default: "he_uniform")
  • flatten - Whether to use a flatten layer instead of a global average pooling layer after the last block (default: False - use global average pooling)
  • dropout_rate - Dropout rate used after global average pooling or flattening (default: 0.0)

Models use the Functional API of Keras under the hood which defines the model's structure as a directed acyclic graph of layers. The function returns a tf.keras.Model instance that needs to be compiled and trained.

The implementation was tested by successfully creating each model and printing its summary to text files. A helper function to print model summaries to text files was used:

def write_summary(model: Model, file_path: str) -> None:
    with open(file_path, "w") as f:
        model.summary(print_fn=lambda x: f.write(x + "\n"))

The text files are included in the repository and are named resnet18.txt, resnet34.txt, resnet50.txt, resnet101.txt, and resnet152.txt.

every-resnet-tensorflow's People

Contributors

vktr274 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

rajaeelouazzani

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.