image_output_1.png
from tensorflow.keras.utils import to_categorical

import h5py

import matplotlib.pyplot as plt

import numpy as np

import numpy as np

INPUTS_DB = '../input/ukbench100-patches-for-sr-hdf5/output/inputs.hdf5'
OUTPUTS_DB = '../input/ukbench100-patches-for-sr-hdf5/output/outputs.hdf5'
MODEL_PATH = 'output/srcnn.model'
PLOT_PATH = 'output/plot.png'
BATCH_SIZE = 128
NUM_EPOCHS = 10
SCALE = 2.0
INPUT_DIM = 33
LABEL_SIZE = 21
PAD = int((INPUT_DIM - LABEL_SIZE) / 2.0)
STRIDE = 14

from tensorflow.keras.utils import to_categorical
import numpy as np
import h5py
class HDF5DatasetGenerator:
    def __init__(self, db_path, batch_size, preprocessors=None, aug=None, binarize=True, classes=2):
        self.batch_size = batch_size
        self.preprocessors = preprocessors
        self.aug = aug
        self.binarize = binarize
        self.classes = classes
        self.db = h5py.File(db_path, 'r')
        self.num_images = self.db['labels'].shape[0]
    def generator(self, passes=np.inf):
        epochs = 0
        while epochs < passes:
            for i in np.arange(0, self.num_images, self.batch_size):
                images = self.db['images'][i:i + self.batch_size]
                labels = self.db['labels'][i:i + self.batch_size]
                if self.binarize:
                    labels = to_categorical(labels, self.classes)
                if self.preprocessors is not None:
                    proc_images = []
                    for image in images:
                        for p in self.preprocessors:
                            image = p.preprocess(image)
                        proc_images.append(image)
                    images = np.array(proc_images)
                if self.aug is not None:
                    images, labels = next(self.aug.flow(images, labels, batch_size=self.batch_size))
                yield (images, labels)
            epochs += 1
    def close(self):
        self.db.close()

plt.style.use('ggplot')
plt.figure(figsize=(16, 10))
plt.plot(np.arange(0, NUM_EPOCHS), H.history['loss'], label='loss')
plt.title('Loss on super resolution training')
plt.xlabel('Epoch #')
plt.ylabel('Loss')
plt.legend()
plt.show()