1

here is the code:

import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from os import listdir

from pathlib import Path

jpeg_images = list(Path(r'D:/ncfm/train').glob('**/*.jpg'))
np.array([np.array(cv2.imread(str(file))).flatten() for file in 
jpeg_images])
folder = ['ALB', 'BET', 'DOL', 'LAG', 'NoF', 'OTHER', 'SHARK', 'YFT','test 
images']
Path = r'D:\ncfm\train'


for i in range(9):
    listing = os.listdir(Path+'/'+folder[i])
    folder[i] = np.array([np.array(cv2.imread(Path+'/'+folder[i]+'/'+file)).flatten()for file in listing])
L.append(len(listing))

next I have tried to concatenate this.

M = np.concatenate((folders[1], folders[2], folders[3], folders[4], 
folders[5], folders[6], folders[7], folders[8]))

next i have done the labelling

label = np.ones((3777), dtype=int)

label[0:1720]=1
label[1720:1920]=2
label[1920:2038]=3
label[2038:2104]=4
label[2104:2568]=5
label[2568:2868]=6
label[2868:3044]=7
label[3044:3777]=8



from sklearn.utils import shuffle

data,Label = shuffle(M, label, random_state = 2)

here comes the error;

ValueError                                Traceback (most recent call last)
<ipython-input-148-f7cec68b48c6> in <module>
      1 from sklearn.utils import shuffle
      2 
----> 3 data,Label = shuffle(M, label, random_state = 2)

~\Anaconda3\lib\site-packages\sklearn\utils\__init__.py in 
shuffle(*arrays, **options)
    447     """
    448     options['replace'] = False
--> 449     return resample(*arrays, **options)
    450 
    451 

~\Anaconda3\lib\site-packages\sklearn\utils\__init__.py in 
resample(*arrays, **options)
    330                                                     n_samples))
    331 
--> 332     check_consistent_length(*arrays)
    333 
    334     if stratify is None:

~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in 
check_consistent_length(*arrays)
    203     if len(uniques) > 1:
    204         raise ValueError("Found input variables with inconsistent 
numbers of"
--> 205                          " samples: %r" % [int(l) for l in 
lengths])
    206 
    207 

ValueError: Found input variables with inconsistent numbers of samples: 
[3058, 3777]

At first i got the length as [8, 3777]. After converting RGB to gray scale and resizing it i got the length as [3058,3777]. i want to shuffle the rows in the matrix M and rows of the label simultaneously.

2
  • shuffle permute same length arrays in a consistent way. Here M has length 8 and label has length 3777. What do you want to happen?
    – Aguy
    Commented Sep 29, 2019 at 14:45
  • Still not very clear. May I suggest you try and ask another question. The problem here, however, is explained in the comment above.
    – Aguy
    Commented Sep 29, 2019 at 19:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.