<jupyter_start><jupyter_text>Here prepare training data for vgg case (224,224,3)<jupyter_code>from os import listdir
from os.path import isfile, join
import matplotlib.image as img
from matplotlib import pyplot as plt
import pickle

from keras.models import *
from keras.models import Model
from keras.layers import *

import shutil
import os

import cv2, os
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
# import seaborn as sns

%matplotlib inline
mypath1 = "Q2/Data/"
onlyfiles1 = [f for f in listdir(mypath1) if isfile(join(mypath1, f))]

mypath2 = "Q2/Mask/"
onlyfiles2 = [f for f in listdir(mypath2) if isfile(join(mypath2, f))]

with open('Q2/train.pickle', 'rb') as handle:
    train = pickle.load(handle)
ind = 112

im1 = mypath1+train[ind][0]
im2 = mypath2+train[ind][1]

#print(im1)
#im1 = another_path


image1 = img.imread(im1)
image2 = img.imread(im2)

# image_row = image1.shape[0]
# image_col = image1.shape[1]

# plt.imshow(image1)
# plt.show()

plt.imshow(image2,cmap="gray")
plt.show()

# print(image1.shape)
print(image2.shape)
def resize_data(im,h,w):
    i = np.float32(cv2.resize(im, ( h , w ))) / 128
    return i

def resize_mask(im,h,w):
    i = np.float32(cv2.resize(im, ( h , w )))
    return i
print(len(train))
# itr = 0

# for k in range(0,len(train)):
#     im1 = str(mypath1+train[k][0])
#     im2 = str(mypath2+train[k][1])
    
#     #image1 = img.imread(im1)
#     image1 = cv2.imread(im1)
#     image2 = cv2.imread(im2)
    
# #     plt.imshow(image1)
# #     plt.show()
    
#     im1_re = resize_data(image1,224,224)
#     im2_re = resize_mask(image2,224,224)
#     cv2.imwrite("resized_data/data/"+str(itr)+".tiff",im1_re)
#     cv2.imwrite("resized_data/mask/"+str(itr)+".tiff",im2_re)
# #     plt.imshow(im1_re)
# #     plt.show()
#     itr+=1<jupyter_output><empty_output><jupyter_text>save data for resized image and renamed image<jupyter_code>mypath3 = "resized_data/data/"
onlyfiles3 = [f for f in listdir(mypath3) if isfile(join(mypath3, f))]

mypath4 = "resized_data/mask/"
onlyfiles4 = [f for f in listdir(mypath4) if isfile(join(mypath4, f))]
itr = 0
des = "renamed_data/"

for k in range(0,len(train)):
    im1 = str(mypath1+train[k][0])
    im2 = str(mypath2+train[k][1])
    
    ## copy data from one folder to another
    shutil.copy2(im1,des+"data/")
    shutil.copy2(im2,des+"mask/")

    ## rename the data
    os.rename(des+"data/"+train[k][0],des+"data/"+str(itr)+".tiff")
    os.rename(des+"mask/"+train[k][1],des+"mask/"+str(itr)+".tiff")
    
    itr+=1<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16082554517133957, 'fraction_numerical': 0.044003115264797506, 'mean_word_length': 4.169014084507042, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '231641', 'license': 'MIT', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1083, 'n_words': 213, 'path': 'Assignments/Assignment_3/Q2/Prepare_train.ipynb', 'repo_name': 'Kaustubh1Verma/CS671_Deep-Learning_2019', 'size': '2568'}