【问题标题】:what is this error for reshaping in python?在 python 中重塑这个错误是什么?
【发布时间】:2021-08-27 21:10:01
【问题描述】:

我有 torch.Size([1, 64, 32, 32]) 的 act['a'] 和 torch.Size([1, 128, 16, 16]) 的 act['b'] 和 act torch.Size([1, 256, 8, 8]) 的 ['c']。 我有:

target = {'a': [], 'b': [], 'c': []}
for i in range(800):
                target['a'].append(act['a'])
                target['b'].append(act['b'])
                target['c'].append(act['c'])

所以现在 target['a'] 的大小是 [800, 1, 64, 32, 32]。如何将其重塑为 [1, 64, 800, 32, 32]?

我试过了

tf.reshape(target['a'], [1, 64, 800,32,32])

它给了我这个错误,我截图了:

【问题讨论】:

    标签: python list reshape tensor


    【解决方案1】:

    这是你所期望的吗?

    a = tf.zeros([1, 64, 32, 32])
    target = {'a': [a] * 800}
    m = tf.convert_to_tensor(target['a'])
    n = tf.reshape(m, [1, 64, 800, 32, 32])
    
    >>> m.shape
    TensorShape([800, 1, 64, 32, 32])
    
    >>> n.shape
    TensorShape([1, 64, 800, 32, 32])
    

    【讨论】:

    • 我写道:target.reshape([3, 1, 64, 800, 32, 32]) 它给了我这个错误:'dict' 对象没有属性'reshape'。正如您在我的代码中看到的那样,目标是一个字典
    • 忘记之前写的,没看懂
    • target['a'] 是一个列表。我该如何重塑它?
    • @Ghost。我更新了我的答案。我想我应该为你工作。
    • 感谢您的宝贵时间
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-14
    • 2021-07-26
    • 1970-01-01
    • 2015-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多