bhainary

Untitled

Jan 28th, 2022
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. from skimage.io import imread, imshow
  5. from skimage.filters import prewitt_h,prewitt_v
  6.  
  7. from skimage.transform import resize
  8. from skimage.feature import hog
  9. from skimage import exposure
  10.  
  11. import os
  12. import pickle
  13.  
  14.  
  15. path = '/home/zzz/Desktop/DS250 - Data Analytics/Assignment1b/fruits-360_dataset/fruits-360/Training'
  16. classes = os.listdir(path)
  17.  
  18. prototypes = []
  19.  
  20. class_count = 0
  21. for clas in classes:
  22.     prototype = np.zeros((12996))
  23.     count = 0
  24.     for image in os.listdir(f'{path}/{clas}'):
  25.         fruit_img = imread(f'{path}/{clas}/{image}')
  26.         fv = hog(fruit_img, orientations=9, pixels_per_cell=(5, 5), cells_per_block=(2, 2), multichannel=True)
  27.         prototype += fv
  28.         count += 1
  29.    
  30.     prototype = prototype / count
  31.     prototypes.append(prototypes)
  32.     class_count += 1
  33.     print(f'Class #{class_count} {clas} is complete')
  34.  
  35. pickle.dump(prototypes, open('prototypes.pkl', 'wb'))
Advertisement
Add Comment
Please, Sign In to add comment