Why can't I manipulate keras batch shape in call method of the custom layer?

12 views
Skip to first unread message

Sagar Chavda

unread,
Jul 6, 2022, 12:35:25 AM7/6/22
to keras...@googlegroups.com
Hello everyone,

In the call method of the custom layer, I have shape of the input into which first dimension is batch. I am dividing the images into the 'g' groups to get subfeatures. 

Let's say image is (1, 7, 7, 1024) and g=4. So, shape will be =(1,7,7,4,256). Now, I want to use these shape as (1*4,7,7,256). This causes the graph execution earror with baseline model as batches are nonetype. Further, it works completely with any shape image with 4 dimensions.

I have checked few solutions in the stack overflow. But, not working as batch shape is NoneType and g is integer.


Thank you, any help will be appreciated.

Lance Norskog

unread,
Jul 6, 2022, 1:13:54 PM7/6/22
to Sagar Chavda, Keras-users
You can only change the number of samples in the dataset generator, not during the model.

To do what (I think) you want to do:

1) Use the "slice" feature to separate a sample into 4 separate pieces
2) Create a separate processing chain for each of the 4 pieces.

In the separate processing chains, you can re-use the same layers and this will cause all processing chains to have matching weights.

You might need to use a Permute layer to separate each quarter into its own sample:

I do not know of any Keras examples that demonstrate how to do this.

Cheers,

Lance Norskog

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/CACKTO9Dax5rnPGjU2uCxFOVnK1qrLx%2BZ3SHBO9X1qHOocZ29EA%40mail.gmail.com.


--
Lance Norskog
lance....@gmail.com
Redwood City, CA
Reply all
Reply to author
Forward
0 new messages