<jupyter_start><jupyter_text>Configs:<jupyter_code>img_width, img_height = 28, 28
train_data_dir = "../input/fruits/fruits-360_dataset/fruits-360/Training"
validation_data_dir = "../input/fruits/fruits-360_dataset/fruits-360/Test"
batch_size = 64
nb_epoch = 5
nb_channels= 3<jupyter_output><empty_output><jupyter_text>see data<jupyter_code>img = plt.imread('../input/fruits/fruits-360_dataset/fruits-360/Training/Banana/66_100.jpg')
plt.imshow(img)<jupyter_output><empty_output><jupyter_text>ModelFC.Configs<jupyter_code>encoding_dim = 256
def flattened_generator(generator):
    for batch in generator:
        yield (batch.reshape(-1,img_width*img_height*nb_channels), batch.reshape(-1,img_width*img_height*nb_channels))<jupyter_output><empty_output><jupyter_text>data loader<jupyter_code>train_datagen = ImageDataGenerator(
        rescale=1./255,
        shear_range=0.2,
        zoom_range=0.2,
        horizontal_flip=True)

test_datagen = ImageDataGenerator(rescale=1./255)
train_generator = train_datagen.flow_from_directory(
        train_data_dir,
        target_size=(img_width, img_height),
        batch_size=batch_size,
        class_mode=None, shuffle=True)

validation_generator = test_datagen.flow_from_directory(
        validation_data_dir,
        target_size=(img_width, img_height),
        batch_size=batch_size,
        class_mode=None, shuffle=True)<jupyter_output><empty_output><jupyter_text>Model<jupyter_code>def AE_FC():

    # this is our input layer
    input_img = Input(shape=(img_height*img_width*nb_channels,))
    
    # this is the bottleneck vector
    encoded = Dense(encoding_dim, activation='relu')(input_img)
    
    # this is the decoded layer, with the same shape as the input
    decoded = Dense(img_height*img_width*nb_channels, activation='sigmoid')(encoded)
    
    return Model(input_img, decoded)
autoencoder = AE_FC()
autoencoder.summary()
autoencoder.compile(optimizer='adam', loss='binary_crossentropy')<jupyter_output><empty_output><jupyter_text>Train the model<jupyter_code>checkpoint = ModelCheckpoint(filepath = "model_weights_ae_fc.h5", save_best_only=True,monitor="val_loss", mode="min" )
history = History()
autoencoder.fit_generator(
    flattened_generator(train_generator),
    samples_per_epoch=math.floor(41322  / batch_size),
    nb_epoch=nb_epoch,
    validation_data=flattened_generator(validation_generator),
    nb_val_samples=math.floor(13877  / batch_size),
    verbose=0,
    callbacks=[history, checkpoint, TQDMNotebookCallback(leave_inner=True, leave_outer=True)])
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11192873741285825, 'fraction_numerical': 0.023237800154918668, 'mean_word_length': 5.906417112299465, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '466475', 'license': 'Apache-2.0', 'n_tokens_mistral': 962, 'n_tokens_neox': 906, 'n_words': 112, 'path': 'VAE_keras.ipynb', 'repo_name': 'soran-ghadri/VAE_notebooks', 'size': '2582'}