I have a set of feature files in numpy format in a folder and would like to vstack them so i can add input_shape in my neural network, input_shape=(21,2048) . The numpy files as as in picture;
The size of the np files are different, example: (16, 2048) , (8, 2048) , (5, 2048) . The maximum size is (21, 2048). I would like to pad them with zero to get size 21 and vstack them. How can i do this?
i tried:
#create a function and iterate files in folder
max_pad_len = 21
def padding(file):
pad_features = np.pad(file_name, pad_width=([(max_pad_len - file_name.shape[0]),0],[0,0]), mode='constant', constant_values=0)
return pad_features
visual_path = ("C:/Users/Data/9. Visual Feature/Input/")
visual_all = []
for file in os.listdir(visual_path):
if file.endswith('.npy'):
file_name = np.load(open(visual_path+file,"rb"))
data = padding(file_name)
visual_all.append(data)
vid_ft = np.vstack(visual_all)
vid_ft.shape
(23016, 2048)
it should be (6,21,2048). Where did it wrong?