How to submit 3 images to ConvLSTM2D?

Viewed 30

I've been tormented all day, I've searched through the whole stackoverflow and haven't found an answer. When I send one image to the input and output of convlstm2d, I change the structure of the array with images as follows

input_d = np.array(input_d, dtype=np.float32)[None,:,:,:,np.newaxes]
output_d = np.array(output_d, dtype=np.float32)[None,:,:,:,np.newaxes]

That's the model I'm applying it all to.

modele.add(k.layers.ConvLSTM2D(filters=64, kernel_size=(3, 3), padding="same", return_sequences=True, activation="relu", input_shape=(None, 64, 64, 1)))
modele.add(k.layers.BatchNormalization())
modele.add(k.layers.ConvLSTM2D(filters=64, kernel_size=(3, 3), padding="same", return_sequences=True, activation="relu"))
modele.add(k.layers.BatchNormalization())
modele.add(k.layers.ConvLSTM2D(filters=64, kernel_size=(1, 1), padding="same", return_sequences=True, activation="relu"))
modele.add(k.layers.Conv3D(filters=1, kernel_size=(3, 3, 3), activation="sigmoid", padding="same"))

But when I add more than one image to the input (for example 3 images) I stupidly don't understand how to change the array structure (and possibly input_shape)!

This is how I add these 3 images to the input and 1 to the output.

input_d = []
output_d = []

files = listdir("timages/")
files.sort(key=lambda xx: int(xx.split(".")[0]))

for i in range(0, len(files)-3):
    s_a = nrmlz_i(files[i:i+4])

    si = s_a[0:3]
    so = s_a[-1]

    input_d.append(si)
    output_d.append([so])

A function that normalizes images

def nrmlz_i(pths):
    for li in range(0, len(pths)):
        img = cv2.imread("timages/"+pths[li], cv2.IMREAD_GRAYSCALE)
        img_n = np.array(img)/255
        pths[li] = img_n

    return pths

Thank you in advance for any help. Maybe the answer was on stackoverflow, and yes, maybe I was looking badly, so I'm sorry in advance.

0 Answers
Related