Я пытаюсь скопировать следующий пакетный генератор для проекта. Однако у меня есть проблемы с изменением моих данных. Цель функции - взять массив [6000,3000] и преобразовать его в форму [batch_size, 100,3000,1].
Функциональный код, который я пытаюсь повторить
def gen(dict_files, aug=False):
while True:
record_name = random.choice(list(dict_files.keys()))
batch_data = dict_files[record_name]
all_rows = batch_data['x']
for i in range(batch_size):
start_index = random.choice(range(all_rows.shape[0]-WINDOW_SIZE))
X = all_rows[start_index:start_index+WINDOW_SIZE, ...]
Y = batch_data['y'][start_index:start_index+WINDOW_SIZE]
X = np.expand_dims(X, 0)
Y = np.expand_dims(Y, -1)
Y = np.expand_dims(Y, 0)
yield X, Y
генерация выходов X, Y:
X.shape=(batch_size, 100, 3000, 1)
Y.shape=(batch_size, 100, 1)
Мой код:
Определения параметров:
Особенности = массив [6000,3000] и метки = массив [6000,]
def generator(features, labels, batch_size):
##Define batch shapes
X_train_batch = np.zeros((batch_size,100, 3000, 1))
y_train_batch = np.zeros((batch_size,100, 1))
while True:
sample_index = random.choice(range(features.shape[0]))
sample_data = features[sample_index]
##Generating training batches
for i in range(batch_size):
start_index = random.choice(range(sample_data.shape[0]-100)) #pick random start point in signal (of length 3000timesteps)
X = sample_data[start_index:start_index + 100, ...] #record 100 timesteps in signal from rand start point
Y = labels[start_index:start_index + 100] #Record classification of X
#print(X.shape) #gives arrays of (100,), should be (100,3000)
##reshaping to input shape taken by model
X = np.expand_dims(X, 0)
Y = np.expand_dims(Y, -1)
Y = np.expand_dims(Y, 0)
##Collecting samples into correct batch size
#X_train_batch[i] = X
#y_train_batch[i] = Y
print(y_train_batch.shape) #gives (32,100,1) which is correct!
generator(features, labels, 32)
Может кто-нибудь объяснить функцию многоточия ('...'), найденную здесь X = all_rows[start_index:start_index+WINDOW_SIZE, ...]
? Из моего понимания многоточие помещает 3000 временных шагов sample_data, чтобы выдать результат (100,3000), но я, очевидно, не понимаю что-то, поскольку я не могу получить такое же поведение в своем коде.
Следуя тому, как Могу ли я воспроизвести, какой ген выводит с моим кодом?