'Multiclass RGB image dataset ValueError: a must be greater than 0 unless no samples are taken
I am working an image dataset that consist of 2410 RGB image data and belongs to two classes, i.e., crops_class and another is grass_class. Crops class data contains 1210 and grass class contains 1200 image data. When I run the code I have faced an error that is
grass
(0, 2)
However when I run the data shape
df_data.shape
I find output
(2410, 2)
mtrand.pyx in numpy.random.mtrand.RandomState.choice()
ValueError: a must be greater than 0 unless no samples are taken
My code:
df_data is not None and isinstance(df_data, pd.DataFrame) and not df_data.empty
>True
df_data.isnull().any()
>image_id False
target False
dtype: bool
SAMPLE_SIZE = (1200)
# Get a list of classes
target_list = os.listdir('/content/PlantDataset/')
for target in target_list:
print(target)
# Filter out a target and take a random sample
temp = df_data[df_data['target'] == target]
print(temp.shape)
df=temp.sample(SAMPLE_SIZE, random_state=101)
# if it's the first item in the list
if target == target_list[0]:
df_sample = df
else:
# Concat the dataframes
df_sample = pd.concat([df_sample, df], axis=0).reset_index(drop=True)
Error:
grass
(0, 2)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-26-7918c4242404> in <module>()
8 temp = df_data[df_data['target'] == target]
9 print(temp.shape)
---> 10 df=temp.sample(SAMPLE_SIZE, random_state=101)
11 # if it's the first item in the list
12 if target == target_list[0]:
/usr/local/lib/python3.7/dist-packages/pandas/core/generic.py in sample(self, n, frac, replace, weights, random_state, axis, ignore_index)
5363 )
5364
-> 5365 locs = rs.choice(axis_length, size=n, replace=replace, p=weights)
5366 result = self.take(locs, axis=axis)
5367 if ignore_index:
mtrand.pyx in numpy.random.mtrand.RandomState.choice()
ValueError: a must be greater than 0 unless no samples are taken
How may I solve this error ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
