Advertisement
qtinio

datasetalak

Mar 12th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.94 KB | None | 0 0
  1. import tensorflow as tf
  2. import cv2
  3. import glob
  4. import os
  5. import numpy as np
  6. import imageio
  7.  
  8. def parsowalak(im):
  9.     im = cv2.resize(im, (28, 28))
  10.     im = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
  11.     im = (im / 255.)
  12.     im_vector = np.reshape(im, 28 * 28)
  13.     return im_vector
  14.  
  15. def naduszanie():
  16.     labels = []
  17.     data = []
  18.     labels_v = []
  19.     labels_t = []
  20.     data_t = []
  21.     data_v = []
  22.  
  23.     # CYK PYK
  24.     katalog = 0
  25.     for root, dirnames, _ in os.walk('sroda//hand'):
  26.         for dir in dirnames:
  27.             inc = 0
  28.             print(root, dir, katalog)
  29.             for filename in glob.glob(os.path.join(root, dir, '*.png')):
  30.                 # print(filename)
  31.                 im = cv2.imread(filename)
  32.                 im_vector = parsowalak(im)
  33.                 if inc < 50:
  34.                     data.append(im_vector)
  35.                     labels.append(katalog)
  36.                 else:
  37.                     data_v.append(im_vector)
  38.                     labels_v.append(katalog)
  39.                 inc += 1
  40.             katalog += 1
  41.  
  42.     katalog = 0
  43.     for root, dirnames, _ in os.walk('sroda//img'):
  44.         for dir in dirnames:
  45.             inc = 0
  46.             print(root, dir, katalog)
  47.             for filename in glob.glob(os.path.join(root, dir, '*.png')):
  48.                 im = cv2.imread(filename)
  49.                 im_vector = parsowalak(im)
  50.                 if inc < 50:
  51.                     data_t.append(im_vector)
  52.                     labels_t.append(katalog)
  53.                 inc += 1
  54.             katalog += 1
  55.     print("Myk zapisanee")
  56.  
  57.     labels = np.asarray(labels)
  58.     labels_v = np.asarray(labels_v)
  59.     labels_t = np.asarray(labels_v)
  60.  
  61.     data_t = np.asarray(data_v).astype(np.float64)
  62.     data_v = np.asarray(data_v).astype(np.float64)
  63.     data = np.asarray(data).astype(np.float64)
  64.  
  65.     return labels, data, labels_v, data_v, labels_t, data_t
  66.  
  67.  
  68. if __name__ == "__main__":
  69.     print("Pach ")
  70.     naduszanie()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement