Issue 1:
Hi all,

I want to include trainable weights in loss function. As I dont know how to, I use a layer that contains weight only. This layer only output weights to loss function.

However, there are too many weights variables, I dont want to output all of them for the whole batch. So I decide to select some of related weights variables as an output.

I will use input class info to select weights variables.

For example. My layer has a kernel of size (10, 1024). Then if input is 0, it outputs kernel[0, :]. If input is 1, kernel[1,:]

However, when I implement following model, the input always has a shape of (?, 1). ? is the undefined batch number. So, I use this line to select output for these inputs.

proxy_of_class = self.kernel[x[:,0], :]

But I always encounter this error:

File "proxyModel.py", line 18, in call
proxy_of_class = self.kernel[x[:,0], :]
ValueError: Shapes must be equal rank, but are 1 and 0
From merging shape 0 with other shapes. for 'proxy/strided_slice_1/stack_1' (op: 'Pack') with input shapes: [?], [].

How can I solve this problem?

Below is my code based on tensorflow1.6

from __future__ import division
import tensorflow as tf
from tensorflow.python.keras.models import Model
from tensorflow.python.keras.layers import Input, Conv2D, MaxPooling2D, Flatten, Dense, Layer

class Proxy(Layer):
def __init__(self,num_class=2, **kwargs):
self.num_class = num_class
super(Proxy, self).__init__(**kwargs)
def build(self, input_shape):
self.kernel = self.add_weight(name='kernel',
shape=(self.num_class, 1024),
initializer='uniform',
trainable=True,
constraint=None)
super(Proxy, self).build(input_shape)
def call(self, x, mask=None):
proxy_of_class = self.kernel[x[:,0], :]
return proxy_of_class
def compute_output_shape(self, input_shape):
return (input_shape[0], 1024)

def build_model(image_size, n_classes):
input1 = Input(shape=image_size) # for image encode
flat = Flatten()(input1)
dense = Dense(1024,activation='relu')(flat)
input2 = Input(shape=(1,)) # for class index
output = Proxy()(input2)
model = Model(inputs=[input1, input2], outputs=[dense, output])
model.summary()
return model

build_model((224,224,3),2)

Issue 2:
If you open a GitHub issue, here is our policy:

It must be a bug, a feature request, or a significant problem with the documentation (for small docs fixes please send a PR instead).

The form below must be filled out.

Here's why we have that policy:.

Keras developers respond to issues. We want to focus on work that benefits the whole community, e.g., fixing bugs and adding features. Support only helps individuals. GitHub also notifies thousands of people when issues are filed. We want them to see you communicating an interesting problem, rather than being redirected to Stack Overflow.

System information.

TensorFlow version (you are using): 2.7.0

Are you willing to contribute it (Yes/No) : Currently no

Describe the feature and the current behavior/state.

ResNets are arguably one of the most influential architectures in deep learning. Today, they are used in different capacities. For example, sometimes they act as strong baselines, sometimes they are used as backbones. Since their inception, their performance on ImageNet-1k, in particular, has improved quite a lot. I think it's time the ResNets under tf.keras.applications were updated to facilitate these changes.

Will this change the current api? How?

ResNet-RS (https://arxiv.org/abs/2103.07579) introduces slight architectural changes to the vanilla ResNet architecture (https://arxiv.org/abs/1512.03385). So, yes, there will be changes to the current implementation of ResNets (among other things) we have under tf.keras.applications. We could call it tf.keras.applications.ResNet50RS, for example. Following summarizes the performance benefits that ResNet-RS introduces to the final ImageNet-1k performance (measured on the val set):

Source

Who will benefit from this feature?

Keras users that use ResNets from tf.keras.applications for building downstream applications.

Contributing

Do you want to contribute a PR? (yes/no): Currently no

If yes, please read this page for instructions

Briefly describe your candidate solution(if contributing):