Module deepposekit.models.layers.util

Expand source code
# -*- coding: utf-8 -*-
# Copyright 2018-2019 Jacob M. Graving <jgraving@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

#    http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from tensorflow.python.keras.engine import Layer
import tensorflow.keras.backend as K

__all__ = ["ImageNormalization"]


class ImageNormalization(Layer):
    """Image normalization layer.
    Normalize the value range of image arrays from [0,255] to [-1,1],
    # Input shape
        Arbitrary. Use the keyword argument `input_shape`
        (tuple of integers, does not include the samples axis)
        when using this layer as the first layer in a model.
    # Output shape
        Same shape as input.
    """

    def __init__(self, **kwargs):
        super(ImageNormalization, self).__init__(**kwargs)

    def call(self, inputs):
        return inputs * (2.0 / 255.0) - 1.0

    def compute_output_shape(self, input_shape):
        return input_shape

Classes

class ImageNormalization (**kwargs)

Image normalization layer. Normalize the value range of image arrays from [0,255] to [-1,1],

Input shape

Arbitrary. Use the keyword argument `input_shape`
(tuple of integers, does not include the samples axis)
when using this layer as the first layer in a model.

Output shape

Same shape as input.
Expand source code
class ImageNormalization(Layer):
    """Image normalization layer.
    Normalize the value range of image arrays from [0,255] to [-1,1],
    # Input shape
        Arbitrary. Use the keyword argument `input_shape`
        (tuple of integers, does not include the samples axis)
        when using this layer as the first layer in a model.
    # Output shape
        Same shape as input.
    """

    def __init__(self, **kwargs):
        super(ImageNormalization, self).__init__(**kwargs)

    def call(self, inputs):
        return inputs * (2.0 / 255.0) - 1.0

    def compute_output_shape(self, input_shape):
        return input_shape

Ancestors

  • tensorflow.python.keras.engine.base_layer.Layer
  • tensorflow.python.module.module.Module
  • tensorflow.python.training.tracking.tracking.AutoTrackable
  • tensorflow.python.training.tracking.base.Trackable

Methods

def call(self, inputs)

This is where the layer's logic lives.

Arguments

inputs
Input tensor, or list/tuple of input tensors.
**kwargs
Additional keyword arguments.

Returns

A tensor or list/tuple of tensors.

Expand source code
def call(self, inputs):
    return inputs * (2.0 / 255.0) - 1.0
def compute_output_shape(self, input_shape)

Computes the output shape of the layer.

Assumes that the layer will be built to match that input shape provided.

Arguments

input_shape
Shape tuple (tuple of integers) or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.

Returns

An input shape tuple.

Expand source code
def compute_output_shape(self, input_shape):
    return input_shape