Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. OSError Traceback (most recent call last)
  2. <ipython-input-5-d55609bb9b39> in <module>()
  3. ----> 1 images, labels = dataset_preprocessing('/content/gdrive/My Drive/Data/cifar/train', '/content/gdrive/My Drive/Data/cifar/labels.txt', (32,32),'/content/gdrive/My Driv]/training_image_pickle')
  4.  
  5. <ipython-input-4-79e4d13e78a2> in dataset_preprocessing(dataset_path, labels_file_path, image_size, image_paths_pickle)
  6. 14 image_paths = []
  7. 15
  8. ---> 16 for image_name in os.listdir(dataset_path):
  9. 17 try:
  10. 18 image_path = os.path.join(dataset_path, image_name)
  11.  
  12. OSError: [Errno 5] Input/output error: '/content/gdrive/Data/cifar/train'
  13.  
  14. def dataset_preprocessing(dataset_path, labels_file_path, image_size, image_paths_pickle):
  15. '''
  16. Load Images and labels from dataset folder.
  17.  
  18. :param dataset_path:String, path to the train/test dataset folder
  19. :param image_size: Tuple, single image size
  20. :param image_path_pickle: String, name of a pickle file whre all imag paths will be saved
  21. '''
  22. with open(labels_file_path, 'r') as f:
  23. classes = f.read().split('n')[:-1]
  24.  
  25. images = []
  26. labels = []
  27. image_paths = []
  28.  
  29. for image_name in os.listdir(dataset_path):
  30. try:
  31. image_path = os.path.join(dataset_path, image_name)
  32. images.append(image_loader(image_path, image_size))
  33. image_paths.append(image_path)
  34. for idx in range(len(classes)):
  35. if classes[idx] in image_name: #Example: 0_frog.png
  36. labels.append(idx)
  37. except:
  38. pass
  39. with open(image_paths_pickle + '.pickle','wb') as f:
  40. pickle.dump(image_paths, f)
  41.  
  42. assert len(images) == len(labels)
  43. return np.array(images), np.array(labels)
  44.  
  45. from google.colab import drive
  46. drive.mount('/content/gdrive')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement