简体   繁体   English

RuntimeError:大小不匹配,m1:[5 x 10],m2:[5 x 32] 在 /pytorch/aten/src/TH/generic/THTensorMath.cpp

[英]RuntimeError: size mismatch, m1: [5 x 10], m2: [5 x 32] at /pytorch/aten/src/TH/generic/THTensorMath.cpp

I need your help.我需要你的帮助。 Running the code below throws:运行下面的代码会抛出:

RuntimeError: size mismatch, m1: [5 x 10], m2: [5 x 32] at /pytorch/aten/src/TH/generic/THTensorMath.cpp

I looked at similar questions but they are image related and suggest flattening the input, I tried them with no luck.我查看了类似的问题,但它们与图像相关并建议将输入变平,但我尝试了它们但没有运气。

I'm using Python 3.6.8 and torch 1.1.0我正在使用 Python 3.6.8 和火炬 1.1.0

code sample:代码示例:

state = [[307, 1588204935.0, 1.0869, 1.08708, 1.08659, 1.08662, 1.08708, 1.08724, 1.08674, 1.08677],
          [370, 1588204920.0, 1.08668, 1.08709, 1.08661, 1.08693, 1.08682, 1.08724, 1.08677, 1.08708],
          [243, 1588204905.0, 1.08637, 1.08671, 1.08624, 1.08669, 1.08651, 1.08686, 1.08639, 1.08683],
          [232, 1588204890.0, 1.08614, 1.08656, 1.08609, 1.08636, 1.08628, 1.0867, 1.08626, 1.0865],
          [349, 1588204875.0, 1.086, 1.08623, 1.08585, 1.08614, 1.08614, 1.08638, 1.08597, 1.0863]]

def predict(state, state_dim=5, action_dim=3, hidden_dim=32, lr=0.05):
    """ Compute Q values for all actions using the DQL. """
    criterion = torch.nn.MSELoss()
    model = torch.nn.Sequential(torch.nn.Linear(state_dim, hidden_dim),
                                     torch.nn.LeakyReLU(),
                                     torch.nn.Linear(hidden_dim, hidden_dim*2),
                                     torch.nn.LeakyReLU(),
                                     torch.nn.Linear(hidden_dim*2, action_dim))

    optimizer = torch.optim.Adam(model.parameters(), lr)

    with torch.no_grad():
        return model(torch.Tensor(state)) # Error throw here

predict(state).tolist()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 RuntimeError: size mismatch, m1: [4 x 784], m2: [4 x 784] at /pytorch/aten/src/TH/generic/THTensorMath.cpp:136 - RuntimeError: size mismatch, m1: [4 x 784], m2: [4 x 784] at /pytorch/aten/src/TH/generic/THTensorMath.cpp:136 初学者 PyTorch:运行时错误:大小不匹配,m1:[16 x 2304000],m2:[600 x 120] - Beginner PyTorch : RuntimeError: size mismatch, m1: [16 x 2304000], m2: [600 x 120] RuntimeError:尺寸不匹配,m1:[32 x 1],m2:[32 x 9] - RuntimeError: size mismatch, m1: [32 x 1], m2: [32 x 9] Pytorch RuntimeError:大小不匹配,m1:[1 x 7744],m2:[400 x 120] - Pytorch RuntimeError: size mismatch, m1: [1 x 7744], m2: [400 x 120] Pytorch GRU 错误 RuntimeError:尺寸不匹配,m1:[1600 x 3],m2:[50 x 20] - Pytorch GRU error RuntimeError : size mismatch, m1: [1600 x 3], m2: [50 x 20] RuntimeError:大小不匹配,m1:[28 x 28],m2:[784 x 128] - RuntimeError: size mismatch, m1: [28 x 28], m2: [784 x 128] 如何修复此 RuntimeError:大小不匹配,m1:[64 x 103],m2:[550 x 50] - How do I fix this RuntimeError: size mismatch, m1: [64 x 103], m2: [550 x 50] Pytorch:尺寸不匹配错误,尽管矩阵的尺寸匹配(m1:[256 x 200],m2:[256 x 200]) - Pytorch: size mismatch error although the sizes of the matrices do match (m1: [256 x 200], m2: [256 x 200]) python 中的 CNN 模块给出错误大小不匹配,m1:[12288 x 26],m2:[12288 x 26] - CNN module in python gives error size mismatch, m1: [12288 x 26], m2: [12288 x 26] Pytorch vsion 大小不匹配,m1 - Pytorch vsion size mismatch, m1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM