Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reason of the question"StopIteration" #68

Open
GrayPaul opened this issue Nov 21, 2019 · 6 comments
Open

Reason of the question"StopIteration" #68

GrayPaul opened this issue Nov 21, 2019 · 6 comments

Comments

@GrayPaul
Copy link

In the founction "generate_train_batch" belong to dara_processor.py.
i = 0
while i < (self.len_train - seq_len):
x_batch = []
y_batch = []
for b in range(batch_size):
if i >= (self.len_train - seq_len):
# stop-condition for a smaller final batch if data doesn't divide evenly
yield np.array(x_batch), np.array(y_batch)
i = 0
x, y = self._next_window(i, seq_len, normalise)
x_batch.append(x)
y_batch.append(y)
i += 1
yield np.array(x_batch), np.array(y_batch)

sometimes, i==self.len_train-seq_len. So it cannot satisfy the while loop .

@lizhogn
Copy link

lizhogn commented Dec 2, 2019

Is this the intent of the author or a bug in the program

@lizhogn
Copy link

lizhogn commented Dec 2, 2019

If I want to iterate more times to better train the model, how can I improve the problem

@shenjian5
Copy link

Maybe this is a small mistake. Perhaps you can refer to the following modification code:

def generate_train_batch(self, seq_len, batch_size, normalise):
    '''Yield a generator of training data from filename on given list of cols split for train/test'''
    i = 0
    x_batch = []
    y_batch = []
    # while i < (self.len_train - seq_len):
    while True:
        for b in range(batch_size):
            x, y = self._next_window(i, seq_len, normalise)
            x_batch.append(x)
            y_batch.append(y)
            i += 1
            if i == (self.len_train - seq_len):
                # stop-condition for a smaller final batch if data doesn't divide evenly
                i = 0
                yield np.array(x_batch), np.array(y_batch)
                x_batch = []
                y_batch = []

@lizhogn
Copy link

lizhogn commented May 3, 2020 via email

@lizhogn
Copy link

lizhogn commented Jun 1, 2020 via email

@Catheriana
Copy link

@shenjian5 It works for me.Thanks~!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants