Getting error when calculating entropy for each images in the batch in the input tensor in a custom layer in tensorflow/Keras.
@DeveshS215,
I tried to execute the mentioned code and it was failing due to `SyntaxError: invalid syntax`. Kindly find the gist of it [here](https://colab.research.google.com/gist/tilakrayal/3aa1a8e614f036fa0e5dba1798617a1c/untitled1013.ipynb) and provide the complete code or the colab gist you are using. Thank you! @tilakrayal,

Thank you.

I have provided the full code and remove that syntax error. The collab gist is [here](https://colab.research.google.com/gist/DeveshS215/cf9ede0d4bc127749a1b01a120eb961a/untitled1013.ipynb). @DeveshS215,

Apologies for the delay.Thank you for opening this issue. Development of keras moved to another [repository](https://github.com/keras-team/keras/issues). 

Could you please post this issue on keras-team/keras [repo](https://github.com/keras-team/keras/issues).
To know more please refer:
https://discuss.tensorflow.org/t/keras-project-moved-to-new-repository-in-https-github-com-keras-team-keras/1999
Thank you!
 @tilakrayal 
I have posted on keras repo. @DeveshS215,
Could you please feel free to move this issue to closed status, so that we can track the issue there. Thank you! Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/59899">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/59899">No</a>

I am working on a problem in which I have to create a custom layer in keras, which takes, output of a conv layer of a pre-trained model as an input. This custom layer work is to select K best feature maps based on shannon entropy for each images in that input tensor and then outputs the final tensor with k feature maps or each images. So that this output tensor is passed to other conv layer in the model.

Let input tensor from a conv layer has shape = (None, 224,224, 128) and I want to take 64 best feature maps out of 128 based on shannon entropy . So the output tensor shape should be = (None, 224,224, 64).

----------------------------------
System Informations:
python version = '3.9.12'
tensorflow version = `'2.10.0'`
Platform = Windows 11
Running on CPU
---------------------------------

Below is the code snippet :

`               

              class select_k_fmap(tf.keras.layers.Layer):
                    def __init__(self):
                        super(select_k_fmap, self).__init__()

                    def build(self, input_shape):
                        pass

                    def call(self, inputs):
                        """
                        tensor shape = (batch_size, img_height, img_width, no. of filters)
                        """    
                        shape = tf.shape(inputs)
                        batch_size = shape[0]
                        print('batch size **** ', batch_size)
                        num_filters = shape[-1]
                        img_height = shape[1]
                        img_width = shape[2]

                        k = 4 # no. of best feature maps to select

                        def k_best_fmap(image):
                            """
                            returns k best feature maps of an image having n feature maps
                            """    
                            def shannon_entropy(feature_map):
                                """
                                returns entropy of a image in a input batch
                                """
                                value_ranges = [0.0, 1.0] 
                                nbins = 256 
                                histogram_bin_indexes = tf.histogram_fixed_width_bins(image, value_ranges, nbins)
                                _, _, count = tf.unique_with_counts(histogram_bin_indexes) 
                                prob = count/tf.reduce_sum(count)
                                prob = tf.cast(prob, tf.float32)
                                entropy = (-tf.reduce_sum(prob * tf.math.log(prob)))/(tf.math.log(2.0)) 
                                return entropy

                            final_image = tf.zeros_like(image) #shape = (img_height, img_width, no. of filters)
                            entropy = []
                            num_featuremaps = tf.shape(image)[-1]
                            for j in range(int(num_featuremaps)):
                                image_ith_filter = image[:,:,j]
                                image_ith_filter_entropy = shannon_entropy(image_ith_filter)
                                entropy.append(tf.get_static_value(image_ith_filter_entropy).item()) 


                            entropy_array = tf.argsort(entropy, direction='DESCENDING')
                            k_best_entropy_sort_index = tf.get_static_value(entropy_sort_index[:k]).tolist()

                            for index, element in enumerate(k_best_entropy_sort_index):
                                final_image[:,:,index] = image[:,:,element]


                        output_tensor = tf.map_fn(fn=k_best_fmap, elems=inputs)

                        return output_tensor`

But when I ran this code I got error :

![Screenshot (890)](https://user-images.githubusercontent.com/127013167/222950090-be802ac6-26c4-4a33-8f5d-106d3f800fb4.png)


I have tried many solutions available on the internet. But nothing worked.
I think this error is due to the shape of input tensor having None as first value in its shape (None, 224,224, 128). But I am unable to resolve this error. I want to wok on dynamic batch tensor as input .

It would be a great help for me if anyone of you could assist me. Thanks in advance.