저는 현재 간단한 분류 작업을 위해 CNN (Keras/Tensorflow)을 교육하기 위해 큰 이미지 데이터 세트 (~ 60GB)로 작업 중입니다. 이미지는 비디오 프레임이므로 시간에 상관 관계가 높습니다. 그래서 거대한 .hdf5 파일을 생성 할 때 이미 데이터를 섞어서 ... 전체 세트를 메모리에 한 번에로드하지 않고도 CNN에 데이터를 제공하려면 간단한 배치 생성기 (아래 코드 참조)를 작성했습니다. 내 질문 : 일반적으로 각 교육 기간 이후에 데이터를 임의로 섞는 것이 좋습니다. (SGD 수렴의 이유가 무엇입니까?)하지만 그렇게하려면 각 신기원 이후에 전체 데이터 세트를로드하고 셔플해야합니다. 정확하게 배치 생성기를 사용하지 않으려는 것입니다 ... So : 정말 중요합니다. 각 시대 이후에 데이터 세트를 섞어 놓으십시오. 그렇다면 가능한 한 효율적으로 어떻게 할 수 있습니까?큰 HDF5 데이터 세트, 각 신기원 이후 효율적으로 셔플하는 방법
def generate_batches_from_hdf5_file(hdf5_file, batch_size, dimensions, num_classes):
"""
Generator that returns batches of images ('xs') and labels ('ys') from a h5 file.
"""
filesize = len(hdf5_file['labels'])
while 1:
# count how many entries we have read
n_entries = 0
# as long as we haven't read all entries from the file: keep reading
while n_entries < (filesize - batch_size):
# start the next batch at index 0
# create numpy arrays of input data (features)
xs = hdf5_file['images'][n_entries: n_entries + batch_size]
xs = np.reshape(xs, dimensions).astype('float32')
# and label info. Contains more than one label in my case, e.g. is_dog, is_cat, fur_color,...
y_values = hdf5_file['labels'][n_entries:n_entries + batch_size]
#ys = keras.utils.to_categorical(y_values, num_classes)
ys = to_categorical(y_values, num_classes)
# we have read one more batch from this file
n_entries += batch_size
yield (xs, ys)
속도면에서 중요한 부분은 hdf5 파일의 chuck_size를 이미지의 크기로 설정하는 것입니다. 이렇게하면 hdf5에서 개별 이미지를 가져 오는 동안 효율성이 향상됩니다. –