Reshape in keras
keras comes with
from import Reshape layer_1 = Reshape((height, width, chns))( layer1)
The reshape function in tensorflow
from keras import backend as K ( layer1,(-1,2,4,8) )
The keras arrogant Reshape layer doesn't need to write the dimensions of the batch, but tensorflow's reshape needs the full dimensions.
methodologies
from import Sequential from import Reshape model = Sequential() # Change data shape to 3 rows and 4 columns # Layer 1 of the model must specify the dimensions of the inputs, note that the size of the batch does not need to be specified (Reshape((3, 4), input_shape=(12, ))) # Change data shape to 6 rows and 2 columns (Reshape((6, 2))) # Change the shape of the data to (2,2) in the 2nd and 3rd dimensions, automatically determining the size of the 1st dimension to be 3 based on the number of data elements. (Reshape((-1, 2, 2))) # Change the shape of the data to (2,2) for the 1st and 2nd dimensions and automatically determine the size of the 3rd dimension to be 3 based on the number of data elements. (Reshape((2, 2, -1))) ()
context_shape = K.int_shape(context) #(None, 7, 7, 32) #Change the second dimension to be 32 and automatically size the 1st dimension to none based on the number of data elements? context = ((-1, context_shape[-1]))(context) #Tensor shape=(None, None, 32), dtype=float32
The above is a personal experience, I hope it can give you a reference, and I hope you can support me more.