image_output_1.png
from tensorflow.keras.utils import to_categorical

from typing import List

import cv2

import h5py

import matplotlib.image as img

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import numpy as np

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')

args = {'image': '../input/sample-images/jemma.png', 'baseline': 'output/baseline.png', 'output': 'output/output.png'}

image = cv2.imread(args['image'])
h, w = image.shape[:2]
w -= int(w % SCALE)
h -= int(h % SCALE)
image = image[0:h, 0:w]

from typing import List
import matplotlib.pyplot as plt
import matplotlib.image as img
images = {'origin': args['image'], 'baseline': args['baseline'], 'output': args['output']}
f: plt.Figure
axes: List[plt.Axes]
f, axes = plt.subplots(1, len(images))
f.set_size_inches((16, 9))
for i, (name, path) in enumerate(images.items()):
    image = img.imread(path)
    axes[i].axis('off')
    axes[i].set_title(name)
    axes[i].imshow(image)
plt.show()