如何解决如何解决 ValueError:样本大于总体或为负?
我正在尝试学习如何使用带有 GPU 的 kaggle 内核。我从这个 kaggle 教程开始,用于“asl 字母表”数据集分类:
https://www.kaggle.com/dansbecker/running-kaggle-kernels-with-a-gpu?scriptVersionId=3558833
但是在第一行代码中(在实现模型之前,当我们只想在训练数据集中显示一些样本时),我得到了这个错误:
ValueError: Sample larger than population or is negative.
这是代码的那部分:
import cv2
from glob import glob
from matplotlib import pyplot as plt
from numpy import floor
import random
def plot_three_samples(letter):
print("Samples images for letter " + letter)
base_path = '../input/asl_alphabet_train/asl_alphabet_train/'
img_path = base_path + letter + '/**'
path_contents = glob(img_path)
plt.figure(figsize=(16,16))
imgs = random.sample(path_contents,3)
plt.subplot(131)
plt.imshow(cv2.imread(imgs[0]))
plt.subplot(132)
plt.imshow(cv2.imread(imgs[1]))
plt.subplot(133)
plt.imshow(cv2.imread(imgs[2]))
return
plot_three_samples('A')
这是错误:
ValueError Traceback (most recent call last)
<ipython-input-1-bcd03e4a0bce> in <module>
35 return
36
---> 37 plot_three_samples('A')
<ipython-input-1-bcd03e4a0bce> in plot_three_samples(letter)
26
27 plt.figure(figsize=(16,16))
---> 28 imgs = random.sample(path_contents,3)
29 plt.subplot(131)
30 plt.imshow(cv2.imread(imgs[0]))
/opt/conda/lib/python3.7/random.py in sample(self,population,k)
319 n = len(population)
320 if not 0 <= k <= n:
--> 321 raise ValueError("Sample larger than population or is negative")
322 result = [None] * k
323 setsize = 21 # size of a small set minus size of an empty list
ValueError: Sample larger than population or is negative
kaggle 内核已经有了数据,我只是按照他们的教程规则来使用数据以及如何使用 glob 等来处理它。
有什么建议吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。