text_plain_output_1.png
import cv2

import numpy as np

import numpy as np # linear algebra

import os

import os

import random

import re

import tensorflow as tf

import numpy as np
import pandas as pd
import os

def seed_everything(seed):
    random.seed(seed)
    os.environ['PYTHONHASHSEED'] = str(seed)
    np.random.seed(seed)
    tf.random.set_seed(seed)

def load_images(path):
    images = []
    bedroom = []
    bathroom = []
    frontal = []
    kitchen = []
    pattern = re.compile('([0-9]{1,3})_(bathroom|bedroom|frontal|kitchen).jpg$')
    files = os.listdir(path=path)
    files.sort()
    for filename in files:
        if pattern.match(filename) is None:
            continue
        img = cv2.imread(path + filename)
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        img = cv2.resize(img, (IMAGE_SIZE, IMAGE_SIZE))
        if 'bedroom' in filename:
            bedroom.append(img)
        if 'bathroom' in filename:
            bathroom.append(img)
        if 'front' in filename:
            frontal.append(img)
        if 'kitchen' in filename:
            kitchen.append(img)
    for i in range(len(bedroom)):
        tiles = [[bedroom[i], bathroom[i]], [frontal[i], kitchen[i]]]
        image_concat = cv2.vconcat([cv2.hconcat(v_list) for v_list in tiles])
        images.append(image_concat)
    return np.array(images) / 255.0

train_images = load_images(PATH_TO_TRAIN_IMAGE)
test_images = load_images(PATH_TO_TEST_IMAGE)
display(train_images.shape)