python - 由于使用 pyro 和 pytorch 的样本中存在多类分布,因此在 svi 步骤中出现错误
问题描述
我正在研究一个因果变分自动编码器,它使用类分割掩码、类标签和因果关系(0 或 1)作为输入。
由于 svi 步骤,使用大于 1 的批量大小时出现错误。我正在使用伯努林函数,因为我希望它学习图像中多个类的概率分布。我认为分类分布也符合此处的要求,但我也遇到了同样的错误。
当我尝试缩小产生问题的代码行时,我认为它在模型函数中:
one_vec2 = torch.ones([batch_size, self.lbl_shape[0]], **options)
class_labels = pyro.sample('class_labels', dist.Bernoulli(one_vec2*0.5), obs = lbls)
错误:
ValueError Traceback (most recent call last)
<ipython-input-19-8cbc046dd2c1> in <module>()
6 vae = Vae_Model1(lbl_sz, ch, img_sz).to(device)
7 svi = SVI(vae.model, vae.guide, optimizer, loss = Trace_ELBO())
----> 8 train(svi, train_loader, USE_CUDA)
6 frames
/usr/local/lib/python3.6/dist-packages/pyro/util.py in check_site_shape(site, max_plate_nesting)
320 '- enclose the batched tensor in a with plate(...): context',
321 '- .to_event(...) the distribution being sampled',
--> 322 '- .permute() data dimensions']))
323
324 # Check parallel dimensions on the left of max_plate_nesting.
ValueError: at site "class_labels", invalid log_prob shape
Expected [-1], actual [32, 21]
Try one of the following fixes:
- enclose the batched tensor in a with plate(...): context
- .to_event(...) the distribution being sampled
- .permute() data dimensions
目前批量大小为 32,lbl_shape[0] 为 21(VOC 数据集(背景和其他标签))
有人可以帮我解决这个问题吗?将不胜感激。谢谢
解决方案
推荐阅读
- r - R数据框中的混合日期格式
- node.js - OKD 请求 ETIMEDOUT - nodejs @ Production
- java - 登录和注册类中的运行时异常
- php - Woocommerce Checkout 页面显示订单摘要 2 次?
- paypal - 如何在我们的移动应用程序中取回 Payer_id
- php - 如何编写干净的 url 我有两个来自不同文件夹的 url 第一个 url 来自根目录,另一个来自 root/tutorials/htaccess
- apache-spark - Pyspark 从本地访问 Kerberized HDFS 集群
- python-3.x - 从另一个 df 更新多列 df
- php - PHP For 循环 jQuery UI 选项卡
- django - 如何在 Django 中返回 serializer.errors?