2017-02-01 1 views
1

저는 Keras fit_generator 함수에 의해 소비 될 파이썬 생성기를 만들고 있습니다. 내 발전기에서 현재의 에포크 카운트를 사용하여 값을 조정하고 싶습니다. 이 번호를 참조 할 수있는 방법이 있습니까?Keras 생성기 내에서 에포크 번호를 어떻게 참조합니까?

def generate_arrays_from_file(path): 
    while 1: 
    f = open(path) 
    for line in f: 
     x, y = process_line(line) 
     epoch_number = ? 
     x = x + epoch_number 
     yield (x, y) 
    f.close() 

model.fit_generator(generate_arrays_from_file('/my_file.txt'), 
     samples_per_epoch=10000, nb_epoch=10) 
+0

http://stackoverflow.com/questions/4548684/how-to-get-the-seconds-since-epoch-from-the-time-date- output-of-gmtime-in-py –

답변

1

방법에 대해 :

def generate_arrays_from_file(path, samples_per_epoch): 
    samples_produced_in_current_epoch = 0 
    epoch_number = 1 
    while 1: 
    f = open(path) 
    for line in f: 
     x, y = process_line(line) 
     x = x + epoch_number 
     samples_produced += x.shape[0] 
     if samples_produced_in_current_epoch > samples_per_epoch: 
      epoch_number += 1 
      samples_produced_in_current_epoch = 0  
     yield (x, y) 

    f.close() 
+0

그래, 그거야! 직접적으로 참조 할 수있는 방법이 있다면 좋을 것입니다.하지만 이것이 내가 할 일을 성취하는 데 도움이 될 것입니다. 'epoch_number = samples_produced_in_current_epoch/samples_per_epoch + 1'로 좀 더 간결하게 만들 수도 있습니다 – ckirksey3

+0

에포크와 샘플의 수가 많으면 오버플로에 문제가 발생할 수 있습니다 –

관련 문제