【问题标题】:ValueError: high <= 0 , LTSMValueError: 高 <= 0 , LTSM
【发布时间】:2022-12-17 16:42:51
【问题描述】:

运行以下命令时:


def batch_generator(batch_size, sequence_length):

'''Generator function for creating random batches of training-data.'''


# Infinite loop.
while True:
    # Allocate a new array for the batch of input-signals.
    x_shape = (batch_size, sequence_length, num_x_signals)
    x_batch = np.zeros(shape=x_shape, dtype=np.float16)

    # Allocate a new array for the batch of output-signals.
    y_shape = (batch_size, sequence_length, num_y_signals)
    y_batch = np.zeros(shape=y_shape, dtype=np.float16)

    # Fill the batch with random sequences of data.
    for i in range(batch_size):
        # Get a random start-index.
        # This points somewhere into the training-data.
        idx = np.random.randint(num_train - sequence_length)
        
        # Copy the sequences of data starting at this index.
        x_batch[i] = x_train_scaled[idx:idx+sequence_length]
        y_batch[i] = y_train_scaled[idx:idx+sequence_length]
    
    yield (x_batch, y_batch)
batch_size = 256
sequence_length = 2 * 7 * 8

generator = batch_generator(batch_size=batch_size,
                            sequence_length=2 * 7 * 8)

x_batch, y_batch = next(generator)

此代码块返回 ValueError:high <= 0

这是我收到的错误:


ValueError Traceback(最近的调用 最后) ~\AppData\Local\Temp/ipykernel_11424/2071659211.py 中 ----> 1 x_batch, y_batch = next(generator)

~\AppData\Local\Temp/ipykernel_11424/1112051746.py 中 batch_generator(batch_size,sequence_length) 18 # 获取一个随机的起始索引。 19 # 这指向训练数据的某处。 ---> 20 idx = np.random.randint(num_train - sequence_length) 21 22 # 复制从该索引开始的数据序列。

numpy.random.mtrand.RandomState.randint() 中的 mtrand.pyx

_bounded_integers.pyx 在 numpy.random._bounded_integers._rand_int32()

值错误:高 <= 0

【问题讨论】:

  • 如果遇到异常,请提供异常的traceback。
  • edit您的问题以显示整个错误消息。
  • Please don't post pictures of text。相反,将文本本身复制到您的帖子中,edit,并使用格式工具,如code formatting
  • 如需调试帮助,您需要创建一个minimal reproducible example,包括完整但最少的代码和预期输出。在这里,256 sequence_length 是无效语法,yield (x_batch, y_batch) 之后的所有内容看起来都缩进了一级。同样,这些名称未定义:num_x_signals, num_y_signals, num_train, x_train_scaled, y_train_scaled,加上import numpy as np。顺便说一句,欢迎来到 Stack Overflow!如果您需要更多提示,请查看tourHow to Ask
  • 请使用代码格式化错误。块引用格式打乱了对齐方式。

标签: python generator


【解决方案1】:

我想我迟到了,但尽管如此

值错误:高 <= 0

它发生是因为这里:

idx = np.random.randint(num_train - sequence_length)

您输入一个参数而不是两个。

我认为它可能有用:https://numpy.org/doc/stable/reference/random/generated/numpy.random.randint.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-08
    • 2021-08-07
    • 1970-01-01
    • 1970-01-01
    • 2020-04-01
    • 2020-01-23
    • 2020-12-30
    • 2013-12-25
    相关资源
    最近更新 更多