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.
问题描述:
在使用Unet++训练自己的数据集时出现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.
原因分析:
原数据集训练图片使用的是png格式,自己的数据集图片为jpg格式。
解决方案:
将训练图片从jpg格式转成png格式。
import os
import cv2
def transform(input_path, output_path):
for root, dirs, files in os.walk(input_path):
for name in files:
file = os.path.join(root, name)
print('transform' + name)
im = cv2.imread(file)
if output_path:
cv2.imwrite(os.path.join(output_path, name.replace('jpg', 'png')), im)
else:
cv2.imwrite(file.replace('jpg', 'png'), im)
if __name__ == '__main__':
input_path = input("请输入目标文件夹: ")
output_path = input("请输入输出文件夹: (回车则输出到原地址)")
if not os.path.exists(input_path):
print("文件夹不存在!")
else:
print("Start to transform!")
transform(input_path, output_path)
print("Transform end!")