ValueError: Найдены входные переменные с непоследовательным количеством выборок: [3058, 3777] - PullRequest
1 голос
/ 29 сентября 2019

вот код:

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))

далее я попытался объединить это.

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

далее я сделал маркировку

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)

здесьприходит ошибка;

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]

Сначала я получил длину как [8, 3777].После преобразования RGB в оттенки серого и изменения его размера я получил длину [3058,3777].я хочу перетасовать строки в матрице M и строки метки одновременно.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...