train_data1的大小不能小于batch_size32

问题描述

我要训练的结构资产(tflite)

!ls  /root/.keras/datasets/model_test/
!ls  /root/.keras/datasets/model_test/abrasive/
abrasive  adhesive
'abrasive (1).jpg'  'abrasive (2).jpg'  'abrasive (3).jpg'

init ImageClassifierDataLoader

data = ImageClassifierDataLoader.from_folder(image_path)
train_data,test_data = data.split(0.3)
INFO:tensorflow:Load image with size: 6,num_label: 2,labels: abrasive,adhesive.
INFO:tensorflow:Load image with size: 6,adhesive.

当我尝试自定义模型

model = image_classifier.create(train_data)

我有

ValueError: The size of the train_data (1) Couldn't be smaller than batch_size (32). To solve this problem,set the batch_size smaller or increase the size of the train_data.

那是什么意思?数据测试必须> 32 batch_size在哪里?

我发现了相同的东西,但有很大的不同,我没有(不是很简单)Increasing batch_size of dataset for Pytorch neural network

解决方法

不要使用批处理大小,因为当数据集非常大并且您想通过将数据分成批进行训练以改善训练过程时使用批处理大小

,

当您创建模型时,create() 函数提供了定义 batch_size(默认值为 32)的可能性。要重用您的示例,您可以编写:

model = image_classifier.create(train_data,batch_size=1)

另见Change the training hyperparameters