profile
viewpoint

MegaCreater/Navarambhah 1

The repository is a diverse collection of object detection and classification projects, offering various implementations and models for identifying and categorizing objects in images or videos. It serves as a valuable resource for learning, experimentation, and benchmarking in the field of computer vision.

issue openedkeras-team/tf-keras

keras.layers.Activation needs to have activation kwargs (parameters)

I want keras.layers.Activation must have kwargs for activation function like ->

    >>> layer = tf.keras.layers.Activation('relu')
    >>> output = layer([-3.0, -1.0, 0.0, 2.0])
    >>> list(output.numpy())
    [0.0, 0.0, 0.0, 2.0]
    >>> layer = tf.keras.layers.Activation('relu',dict(alpha=0.2))
    >>> output = layer([-3.0, -1.0, 0.0, 2.0])
    >>> list(output.numpy())
    [-0.6, -0.2, 0.0, 2.0]

I have updated the code at https://github.com/keras-team/keras/blob/v2.11.0/keras/layers/core/activation.py to achieve this, I want to contribute this to official keras. Code is below ->

# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# 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.
# ==============================================================================
"""Contains the Activation layer."""

import inspect                                                      # check arguments of function (activation)
from keras import activations
from keras.engine.base_layer import Layer

# isort: off
from tensorflow.python.util.tf_export import keras_export


@keras_export("keras.layers.Activation")
class Activation(Layer):
    """Applies an activation function to an output.
    Args:
      activation: Activation function, such as `tf.nn.relu`, or string name of
        built-in activation function, such as "relu".
    Usage:
    >>> layer = tf.keras.layers.Activation('relu')
    >>> output = layer([-3.0, -1.0, 0.0, 2.0])
    >>> list(output.numpy())
    [0.0, 0.0, 0.0, 2.0]
    >>> layer = tf.keras.layers.Activation('relu',dict(alpha=0.2))
    >>> output = layer([-3.0, -1.0, 0.0, 2.0])
    >>> list(output.numpy())
    [-0.6, -0.2, 0.0, 2.0]
    >>> layer = tf.keras.layers.Activation(tf.nn.relu)
    >>> output = layer([-3.0, -1.0, 0.0, 2.0])
    >>> list(output.numpy())
    [0.0, 0.0, 0.0, 2.0]
    Input shape:
      Arbitrary. Use the keyword argument `input_shape`
      (tuple of integers, does not include the batch axis)
      when using this layer as the first layer in a model.
    Output shape:
      Same shape as input.
    """

    def __init__(self, activation, activation_kwargs:dict=dict(), **kwargs):
        super().__init__(**kwargs)
        self.supports_masking = True
        self.activation = activations.get(activation)
        # check activation_kwargs must be a dictionary 
        assert isinstance(activation_kwargs,dict),'`activation_kwargs` must be dictionay, but got '\
               f'-> {type(activation_kwargs)}'
        # check all keyword arguments (must be in function)
        assert all([key in inspect.signature(self.activation).parameters.keys() for key in activation_kwargs]),\
               'Invalid `activation_kwargs`, the valid `activation_kwargs` are '\
               f'{list(inspect.signature(self.activation).parameters.keys())[1:]}.'
        self.activation_kwargs = activation_kwargs                  # activation function kwargs 

    def call(self, inputs):
        return self.activation(inputs,**self.activation_kwargs)     # pass activation function kwargs

    def compute_output_shape(self, input_shape):
        return input_shape

    def get_config(self):
        config = {"activation": activations.serialize(self.activation), }
        config.update(self.activation_kwargs)                       # activation function kwargs
        base_config = super().get_config()
        return dict(list(base_config.items()) + list(config.items()))

created time in 6 months

MemberEvent

push eventMegaCreater/MakingMachineSmarter

MegaCreater

commit sha 0472e24fcfa4a248241f2a1052e38582f72f60a6

Add files via upload

view details

push time in 17 days

push eventMegaCreater/Navarambhah

MegaCreater

commit sha 0804326e789e29ecacc8afb3591071894ed3fff3

Update README.md

view details

push time in 2 months

push eventMegaCreater/Navarambhah

utsavmahajan

commit sha 70c33df1eb74ff188b500499d22fff7889468988

deleted.py

view details

MegaCreater

commit sha f4799b9848db2b717d5cd5d776cc04e75d274e50

Merge pull request #3 from utsavmahajan/patch-1 deleted.py

view details

push time in 2 months

PR merged MegaCreater/Navarambhah

deleted.py
+0 -82

0 comment

1 changed file

utsavmahajan

pr closed time in 2 months

push eventMegaCreater/Navarambhah

MegaCreater

commit sha d65b791dd47f7df1a2a47430139d6872a4634278

Update README.md

view details

push time in 2 months

push eventMegaCreater/Navarambhah

MegaCreater

commit sha c9da0e6ee1802c47f3df3a2ba9a005e1a43abd40

Update README.md

view details

push time in 2 months

MemberEvent

push eventMegaCreater/Navarambhah

Ajinkya Bhoite

commit sha 0ec424d0338f35bed2fdb572f9a555d2595e6bad

Update README.md

view details

MegaCreater

commit sha 7d536db2d69f688f48287d333e55f838b44763d3

Merge pull request #1 from Ajinkya2217/patch-1 Update README.md

view details

push time in 2 months

PR merged MegaCreater/Navarambhah

Update README.md

Images uploaded for preview.

+3 -3

0 comment

1 changed file

Ajinkya2217

pr closed time in 2 months

push eventMegaCreater/Navarambhah

MegaCreater

commit sha af780f60f95d90254079450c8fd1ba56fe689e7d

Add files via upload

view details

push time in 2 months

push eventMegaCreater/Navarambhah

MegaCreater

commit sha ea1b67a8fd8ec6b24119f66498357ae54250ccce

Update README.md

view details

push time in 2 months

create barnchMegaCreater/Navarambhah

branch : main

created branch time in 2 months

created repositoryMegaCreater/Navarambhah

IITk

created time in 2 months

push eventMegaCreater/Navarambhah

MegaCreater

commit sha 9022b627d8763f34c9f50ee0eb26b757dcdb8c0a

Initial commit

view details

push time in 2 months

create barnchMegaCreater/Navarambhah

branch : main

created branch time in 2 months

created repositoryMegaCreater/Navarambhah

created time in 2 months

issue commentkeras-team/keras

Using Middle Layer of Keras Application MobileNetv2

@tanakataiki


# load pre-trained mobile net model 
mobilev2_core=tf.keras.applications.MobileNetV2(input_shape=(256,256,3),include_top=False)# load mobileNetV2 base 
# inputs : <KerasTensor: shape=(None, 128, 128, 32) dtype=float32 (created by layer 'Conv1_relu')>
mobilev2_core=tf.keras.Model(inputs=[mobilev2_core.layers[4].input],outputs=mobilev2_core.outputs)# setup model for custom layer as inputs
# inputs must be of same shape as required by layer 4, i.e. `expanded_conv_depthwise` : (None, 128, 128, 32)

# bulid custom model using customized mobileNetV2 
# define extractor model layers (inputs)
input_A=tf.keras.Input(shape=input_shape,batch_size=None,name='input_A',dtype=None)# cover image input
input_B=tf.keras.Input(shape=input_shape,batch_size=None,name='input_B',dtype=None)# watermarked image input
model_x=tf.keras.layers.Concatenate(axis=-1,name='concatinate_features_01')([input_A,input_B])# concatenate inputs
model_x=tf.keras.layers.Conv2D(32,kernel_size=(3,3),strides=(2,2))(model_x)
model_x=tf.keras.layers.BatchNormalization()(model_x)
model_x=tf.keras.layers.ReLU()(model_x)# add activation layer - outputs shape - (None, 128, 128, 32) (same required for mobileNetV2 custom
extractor_x=mobilev2_core(extractor_x)
extractor_x=tf.kears.....# what ever you want ....
tanakataiki

comment created time in 2 months

delete branch MegaCreater/Navarambhah

delete branch : team-alien

delete time in 3 months

create barnchMegaCreater/Navarambhah

branch : team-alien

created branch time in 3 months

create barnchMegaCreater/Navarambhah

branch : e85bd525cafb42ac86d3408e373f5dac

created branch time in 3 months

delete branch MegaCreater/Navarambhah

delete branch : 9d053ea2-c920-4154-9540-679ac863bc57

delete time in 3 months

MemberEvent

create barnchMegaCreater/Navarambhah

branch : 9d053ea2-c920-4154-9540-679ac863bc57

created branch time in 3 months

delete branch MegaCreater/Navarambhah

delete branch : test-branch

delete time in 3 months

create barnchMegaCreater/Navarambhah

branch : test-branch

created branch time in 3 months

delete branch MegaCreater/Navarambhah

delete branch : test-branch

delete time in 3 months

create barnchMegaCreater/Navarambhah

branch : test-branch

created branch time in 3 months

MemberEvent
more