Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

输入尺寸和预测框大小 #9

Open
Hongzhehao opened this issue May 6, 2020 · 10 comments
Open

输入尺寸和预测框大小 #9

Hongzhehao opened this issue May 6, 2020 · 10 comments

Comments

@Hongzhehao
Copy link

谢谢提供这个模型,由于我修改了FPN的结构,在训练的时候(8G的显存),输入尺寸为600时,总是出现CUDA out of memory,我想减小到输入尺寸为300,特征图(5层)应该变成 38、19、10、5、3,那么对应的预测框大小该如何设置?

@i4yyds
Copy link

i4yyds commented May 6, 2020

您好,我尝试将输入尺寸从600修改为800,然后计算loss的代码报错
loss[pos_mask] = -math.inf # 无穷
IndexError: The shape of the mask [1, 67995] at index 1 does not match the shape of the indexed tensor [1, 120087] at index 1
请问如何解决呢?

@Hongzhehao
Copy link
Author

@SoulCoderCN 目前看来应该是需要手动调整的,只是我还没有找到相关联的地方在哪里

@i4yyds
Copy link

i4yyds commented May 6, 2020

@SoulCoderCN 目前看来应该是需要手动调整的,只是我还没有找到相关联的地方在哪里

好像不需要手动调整,我刚刚用这个代码成功跑了VOC2007,而VOC2007中的图片尺寸并不是统一的。
目前训练自己的数据集还是不行,不知道出了什么问题。

@Hongzhehao
Copy link
Author

@SoulCoderCN 请问下你的显存是多少呀,我之前运行的时候,600尺度的图片 一直是 cuda out of memory

@i4yyds
Copy link

i4yyds commented May 6, 2020

@SoulCoderCN 请问下你的显存是多少呀,我之前运行的时候,600尺度的图片 一直是 cuda out of memory

在config.py文件中设置 _C.TRAIN.BATCH_SIZE = 1,就不会溢出了

@yatengLG
Copy link
Owner

yatengLG commented May 7, 2020

@SoulCoderCN 输入大小改变,会导致特征图大小发生改变,你需要对 fpn的输入特征图大小进行更改,也就是_C.MODEL.ANCHORS.FEATURE_MAPS 项, 其值为 第一项为 IMAGE_SIZE/ (2**3)向上取整,其后每项均/2 向上取整;你的报错 IndexError: The shape of the mask [1, 67995] at index 1 does not match the shape of the indexed tensor [1, 120087] at index 1 是因为,特征图大小发生改变,导致最终输出发生改变:原先(75^2+38^2+19^2+10^2+5^2x9 = 67995, 改为800后: (100^2+50^2+25^2+13^2+7^2x9 = 120087 俩者完全不匹配了

@i4yyds
Copy link

i4yyds commented May 7, 2020

@SoulCoderCN 输入大小改变,会导致特征图大小发生改变,你需要对 fpn的输入特征图大小进行更改,也就是_C.MODEL.ANCHORS.FEATURE_MAPS 项, 其值为 第一项为 IMAGE_SIZE/ (2**3)向上取整,其后每项均/2 向上取整;你的报错 IndexError: The shape of the mask [1, 67995] at index 1 does not match the shape of the indexed tensor [1, 120087] at index 1 是因为,特征图大小发生改变,导致最终输出发生改变:原先(75^2+38^2+19^2+10^2+5^2x9 = 67995, 改为800后: (100^2+50^2+25^2+13^2+7^2x9 = 120087 俩者完全不匹配了

@yatengLG 感谢您的回复,我使用您的方法成功解决了这个问题!

@yatengLG
Copy link
Owner

yatengLG commented May 7, 2020

谢谢提供这个模型,由于我修改了FPN的结构,在训练的时候(8G的显存),输入尺寸为600时,总是出现CUDA out of memory,我想减小到输入尺寸为300,特征图(5层)应该变成 38、19、10、5、3,那么对应的预测框大小该如何设置?

如果只是改变了输入尺寸的话,可以直接了当的 都/2。因为输入图片小了,目标尺寸也相应的缩小了同样的倍数。

@yatengLG
Copy link
Owner

yatengLG commented May 7, 2020

@SoulCoderCN 输入大小改变,会导致特征图大小发生改变,你需要对 fpn的输入特征图大小进行更改,也就是_C.MODEL.ANCHORS.FEATURE_MAPS 项, 其值为 第一项为 IMAGE_SIZE/ (2**3)向上取整,其后每项均/2 向上取整;你的报错 IndexError: The shape of the mask [1, 67995] at index 1 does not match the shape of the indexed tensor [1, 120087] at index 1 是因为,特征图大小发生改变,导致最终输出发生改变:原先(75^2+38^2+19^2+10^2+5^2x9 = 67995, 改为800后: (100^2+50^2+25^2+13^2+7^2x9 = 120087 俩者完全不匹配了

@yatengLG 感谢您的回复,我使用您的方法成功解决了这个问题!

@SoulCoderCN 这个项目由于不是论文复现,很多地方会有我自己代码的习惯,因此与原论文会有些许的差异。如果遇到什么问题,你可以继续问我

@ZhanJunxiang
Copy link

ZhanJunxiang commented May 30, 2020

谢谢提供这个模型,由于我修改了FPN的结构,在训练的时候(8G的显存),输入尺寸为600时,总是出现CUDA out of memory,我想减小到输入尺寸为300,特征图(5层)应该变成 38、19、10、5、3,那么对应的预测框大小该如何设置?

如果只是改变了输入尺寸的话,可以直接了当的 都/2。因为输入图片小了,目标尺寸也相应的缩小了同样的倍数。

您好,你说的检测框尺寸/2,那就是将anchor_sizes都/2吗?像这样调整将图片尺寸/2,除了调整feature_map和anchor_size外,还有需要调整的吗?需不需要调整anchor.nums或anchor.radios?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants