Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. def get_training_data(self,datafolder):
  2. print("Loading training data...")
  3.  
  4. training_data = []
  5. #Finds all files in datafolder
  6. filenames = os.listdir(datafolder)
  7. for filename in tqdm(filenames):
  8. #Combines folder name and file name.
  9. path = os.path.join(datafolder,filename)
  10. #Opens an image as an Image object.
  11. image = Image.open(path)
  12. #Resizes to a desired size.
  13. image = image.resize((self.image_width,self.image_height),Image.ANTIALIAS)
  14. #Creates an array of pixel values from the image.
  15. pixel_array = np.asarray(image)
  16.  
  17. training_data.append(pixel_array)
  18.  
  19. #training_data is converted to a numpy array
  20. training_data = np.reshape(training_data,(-1,self.image_width,self.image_height,self.channels))
  21. return training_data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement