1、基于h5py批量保存特征,并使用全局平均池化缩减特征尺寸,减小对内存的需求
?
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras import applications,Model
from tensorflow.keras.layers import Dense,Dropout,Input,GlobalAveragePooling2D
import numpy as np
import os,gc
batch_size=100#ResNet50,VGG16,InceptionV3
shape=(240, 480)
models=["VGG16","VGG19","InceptionV3","ResNet50"]
models=["EfficientNetB0"]
import h5py
import numpy as np
import math,gc
file_name='data_EfficientNetB0_240.h5'
h5f=h5py.File(file_name)
def save_h5(h5f,data,target):
shape_list=list(data.shape)
if not h5f.__contains__(target):
shape_list[0]=None #设置数组的第一个维度是0
dataset = h5f.create_dataset(target, data=data,maxshape=tuple(shape_list), chunks=True)
return
else:
dataset = h5f[target]
len_old=dataset.shape[0
|