Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===================================================== Snippet 1 =======================================
- %matplotlib inline
- import os
- import random
- import imageio
- import pandas as pd
- from scipy.misc import imread
- import numpy as np
- import matplotlib.pyplot as plt
- import matplotlib.image as mpimg
- #===================================================== Snippet 2 =======================================
- # Then I loaded the csv files, so that it would be easier to locate the files
- root_dir = os.path.abspath('.')
- data_dir = '/Users/renedena/Documents/Machine_Learning_Project_II/all'
- #print(root_dir)
- train = pd.read_csv(os.path.join(data_dir, 'train.csv'))
- test = pd.read_csv(os.path.join(data_dir, 'test.csv'))
- #===================================================== Snippet 3(issue found here) ======================
- # I first load all the images and "TRY" to resize them into a single numpy array
- #from scipy.misc import imresize
- import skimage.transform
- # Code to resizing all Train images first
- temp = []
- for img_name in train.Id:
- img_path = os.path.join(data_dir, 'train', img_name)
- img = imageio.imread(img_path)
- img = skimage.transform.resize(img, (32, 32), mode='constant') # mode='reflect'
- img = img.astype('float32') # this will help us in later stage
- temp.append(img)
- train_x = np.stack(temp)
- #____________________________________________________________________________________________________________
- #++++++++++++++++++++^^^^^^^Like i mentioned, this is where im getting my error ^^^^^^+++++++++++++++++++++++
- ##++++++++++++++++++++++++++++ The output im getting is as follows: +++++++++++++++++++++++++++++++++++++++++
- #____________________________________________________________________________________________________________
- #Output below:
- ---------------------------------------------------------------------------
- ValueError Traceback (most recent call last)
- <ipython-input-7-60df81a21aae> in <module>()
- 21 temp.append(img)
- 22 print(len(temp))
- ---> 23 train_x = np.stack(temp)
- 24 print(len(train_x))
- ~/anaconda3/lib/python3.6/site-packages/numpy/core/shape_base.py in stack(arrays, axis, out)
- 351 shapes = set(arr.shape for arr in arrays)
- 352 if len(shapes) != 1:
- --> 353 raise ValueError('all input arrays must have the same shape')
- 354
- 355 result_ndim = arrays[0].ndim + 1
- ValueError: all input arrays must have the same shape
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement