ValueError: With n_samples=0, test_size=0.2 and train_size=None, the resulting train set will be emp

在将labelme标注转换为VOC格式时遇到ValueError,提示训练集将为空。解决方案不是降级scikit-learn版本,而是调整参数设置,确保train或test样本数量为整数。提供了解决问题的代码修改建议和操作步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天写代码labelmetovoc,即将labelme标注的转化为voc标准格式参考的这篇文章时遇到了如下问题:
ValueError: With n_samples=0, test_size=0.2 and train_size=None, the resulting train set will be empty. Adjust any of the aforementioned parameters.
在网上查了一下,大部分博客都认为是scikit-learn版本较高时出现的问题,需要换到0.20.0以下版本,但是换的话numpy,scipy等库均要重新下载兼容的版本,所以建议不要轻易尝试,我请教了一下师兄,他说是因为参数上面参数设置出现了问题,train或test的数量必须为整数,改好的代码如下所示:

# -*- coding: utf-8 -*-
"""
Created on Fri Apr 10 13:39:17 2020

@author: nihao
"""
import os
import numpy as np
import codecs
import json
import glob
import cv2
import shutil
from sklearn.model_selection import train_test_split

# 1.标签路径
labelme_path = "D:\\PinInspection\\jpgretanglelabel"  # 原始labelme标注数据路径
saved_path = "D:\\PinInspection\\improveto300\\VOC2007"  # 保存路径

# 2.创建要求文件夹
dst_annotation_dir = os.path.join(saved_path, 'Annotations')
if not os.path.exists(dst_annotation_dir):
    os.makedirs(dst_annotation_dir)
dst_image_dir = os.path.join(saved_path, "JPEGImages")
if not os.path.exists(dst_image_dir):
    os.makedirs(dst_image_dir)
dst_main_dir = os.path.join(saved_path, "ImageSets", "Main")
if not os.path.exi
评论 20
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值