Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 在model.fit()、model.train_on_batch()、model.fit_generator()中,哪种方法最适合进行培训_Python 3.x_Tensorflow_Keras_Deep Learning_Computer Vision - Fatal编程技术网

Python 3.x 在model.fit()、model.train_on_batch()、model.fit_generator()中,哪种方法最适合进行培训

Python 3.x 在model.fit()、model.train_on_batch()、model.fit_generator()中,哪种方法最适合进行培训,python-3.x,tensorflow,keras,deep-learning,computer-vision,Python 3.x,Tensorflow,Keras,Deep Learning,Computer Vision,我有一个600张(512*512*1)分辨率图像的训练数据集,分为两类(每类300张图像)。使用一些增强技术,我将数据集增加到10000张图像。经过以下预处理步骤 all_images=np.array(all_images)/255.0 all_images=all_images.astype('float16') all_images=all_images.reshape(-1,512,512,1) saved these images to H5 file. 我使用AlexNet体系结构

我有一个600张(512*512*1)分辨率图像的训练数据集,分为两类(每类300张图像)。使用一些增强技术,我将数据集增加到10000张图像。经过以下预处理步骤

all_images=np.array(all_images)/255.0
all_images=all_images.astype('float16')
all_images=all_images.reshape(-1,512,512,1)
saved these images to H5 file.
我使用AlexNet体系结构进行分类,其中包含3个卷积、3个重叠的最大池层。 我想知道以下哪种情况最适合使用内存大小限制为12GB的Google Colab进行培训

1. model.fit(x,y,validation_split=0.2)
# For this I have to load all data into memory and then applying an AlexNet to data will simply cause Resource-Exhaust error.

2. model.train_on_batch(x,y)
# For this I have written a script which randomly loads the data batch-wise from H5 file into the memory and train on that data. I am confused by the property of train_on_batch() i.e single gradient update. Do this will affect my training procedure or will it be same as model.fit().

3. model.fit_generator() 
# giving the original directory of images to its data_generator function which automatically augments the data and then train using model.fit_generator(). I haven't tried this yet. 

请指导我,在我的案例中,哪种方法是最好的。我已经阅读了很多答案,关于model.fit()、model.train\u on\u batch()和model.fit\u generator(),但我仍然感到困惑。

model.fit-如果您将数据作为numpy数组加载,并且在不进行扩展的情况下进行训练,则适用。 model.fit_generator-如果您的数据集太大,无法放入内存或\并且您希望动态应用扩充。
model.train\u on\u batch-不太常见,通常在一次培训多个模型时使用(例如GAN)

哦,是的,我明白了。非常感谢您的时间和帮助。请指导我最后一件事,我可以使用model.fit_generator()来保存我保存的增强数据,即我已增强并保存在numpy数组中的数据到H5文件。将该H5文件中的随机批处理数据加载到内存让我们假设batchsize为64,然后使用fit_generator()进行训练