PaddlePaddle / Paddle

PArallel Distributed Deep LEarning: Machine Learning Framework from Industrial Practice (『飞桨』核心框架,深度学习&机器学习高性能单机、分布式训练和跨平台部署)
http://www.paddlepaddle.org/
Apache License 2.0
22.23k stars 5.58k forks source link

torch.tensor.view用什么替换 #39491

Closed ZiJINII closed 2 years ago

ZiJINII commented 2 years ago

image ### 在全连接层需要用到view函数,在paddle中找不到对应函数###

paddle-bot-old[bot] commented 2 years ago

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档常见问题历史IssueAI社区来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

huangjun12 commented 2 years ago

可以使用 paddle.reshape,文档参考 https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/reshape_cn.html#reshape

ZiJINII commented 2 years ago

可以使用 paddle.reshape,文档参考 https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/reshape_cn.html#reshape

image 出现了‘numpy.int64’ object is not callable 的错误,无法解决

huangjun12 commented 2 years ago

能定位到具体报错在哪行嘛

ZiJINII commented 2 years ago

能定位到具体报错在哪行嘛 在最后的全连接层 def forward(self, x):

ResConv

x = x.numpy() x = x.astype("float32") x =paddle.to_tensor(x) x = self.preprocessing(x) x = self.norm1(x) x = self.TLU(x)

    # Conv1 
    x = self.block2(x)

    # Conv2 
    x = self.block3(x)

    # Multiscale residual convolution block
    x = self.block_netB(x)

    # Conv3
    x = self.block4(x)
    # AvgPool1
    x = self.pool1(x)

    # Steganalysis residual block
    x = self.block5(x)
    # AvgPool2
    x = self.pool2(x)

    # Conv4
    x = self.block6(x)
    # AvgPool3
    x = self.pool3(x)

    # Conv5 
    x = self.block7(x)
    print(x.size)

    # Full Connection
    x = x.reshape(x,shape=[x.size(0), -1])
    x = self.ip1(x)
    return x
ZiJINII commented 2 years ago

问题已经解决了,发现是x.size的问题,感谢