Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tensorflow as tf
- import cv2
- import glob
- import os
- import numpy as np
- import imageio
- def parsowalak(im):
- im = cv2.resize(im, (28, 28))
- im = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
- im = (im / 255.)
- im_vector = np.reshape(im, 28 * 28)
- return im_vector
- def naduszanie():
- labels = []
- data = []
- labels_v = []
- labels_t = []
- data_t = []
- data_v = []
- # CYK PYK
- katalog = 0
- for root, dirnames, _ in os.walk('sroda//hand'):
- for dir in dirnames:
- inc = 0
- print(root, dir, katalog)
- for filename in glob.glob(os.path.join(root, dir, '*.png')):
- # print(filename)
- im = cv2.imread(filename)
- im_vector = parsowalak(im)
- if inc < 50:
- data.append(im_vector)
- labels.append(katalog)
- else:
- data_v.append(im_vector)
- labels_v.append(katalog)
- inc += 1
- katalog += 1
- katalog = 0
- for root, dirnames, _ in os.walk('sroda//img'):
- for dir in dirnames:
- inc = 0
- print(root, dir, katalog)
- for filename in glob.glob(os.path.join(root, dir, '*.png')):
- im = cv2.imread(filename)
- im_vector = parsowalak(im)
- if inc < 50:
- data_t.append(im_vector)
- labels_t.append(katalog)
- inc += 1
- katalog += 1
- print("Myk zapisanee")
- labels = np.asarray(labels)
- labels_v = np.asarray(labels_v)
- labels_t = np.asarray(labels_v)
- data_t = np.asarray(data_v).astype(np.float64)
- data_v = np.asarray(data_v).astype(np.float64)
- data = np.asarray(data).astype(np.float64)
- return labels, data, labels_v, data_v, labels_t, data_t
- if __name__ == "__main__":
- print("Pach ")
- naduszanie()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement