ACSCP_cGAN icon indicating copy to clipboard operation
ACSCP_cGAN copied to clipboard

输入图像尺寸大小问题

Open wangyuanyuan0 opened this issue 6 years ago • 7 comments

您好,看了您的一系列回答,代码中使用padding将图像尺寸固定,请问 1)怎样使用padding固定尺寸, 2)固定尺寸的同时,需要对密度图进行处理吗?

wangyuanyuan0 avatar Jan 08 '19 08:01 wangyuanyuan0

可以有几种不同的处理方法: (1)将原始图像resize到720x720,然后在生成人群密度图;但这种方法会改变人头对象的形状,感觉不是特别好; (2)保证原始图像短边大于720,然后生成人群密度图;使用的时候,在原始图像上随机crop 720x720的图像用于训练;我在训练的时候采用的是这种方法,可以保证不改变人头对象形状的条件下,对数据样本进行增广; (3)其它处理方法。

Ling-Bao avatar Jan 11 '19 09:01 Ling-Bao

谢谢您的回复,还有一个问题,图像大小720和240的问题。 请问720是程序最初输入,而240是在大小为720的图像上进行数据扩增而来的吗?所以generator的输入图像大小为240?

wangyuanyuan0 avatar Jan 11 '19 09:01 wangyuanyuan0

ACSCP模型包括两个生成器:一个是G_large模型,输入为720x720;另一个是G_small,输入为240x240,由720x720图像等分为4块得到。论文作者认为4个小块的人群密度与整图的人群密度应该相等,设计了一个一致性损失,用于保证估计的人群密度图具有一致性。

也就是说G_large生成器输入为720x720;G_small生成器输入为240x240。

备注: 在进行预测时,仅使用G_large生成器模型进行人群密度的估计;同时,整个ACSCP模型为全卷积模型,所以训练完成后,G_large生成器模型的输入图像可以是任意大小(目前项目里的模型被我设置为了固定值)。

Ling-Bao avatar Jan 11 '19 09:01 Ling-Bao

抱歉,我的训练数据集采用的是将图像resize为720x720, 然后再制作密度标签。

如果你需要自己制作密度标签,可以参考以下代码: https://github.com/Ling-Bao/ACSCP_cGAN/blob/master/data_maker/step3/acscp.m

或者这位作者的代码 https://github.com/leeyeehoo/CSRNet-pytorch/blob/master/make_dataset.ipynb

% 读取图片/密度预标签  Line 66
image = imread(img_path);
image_out = imresize(image, [720,720]);

% Line 97
I = imresize(I, [720,720]);
gt(:,1) = ceil(gt(:,1) * j_scale);
gt(:,2) = ceil(gt(:,2) * i_scale); % 坐标依次缩放

Ling-Bao avatar Jan 11 '19 09:01 Ling-Bao

您好,非常感谢您的细心回复,论文中 有这么一句话‘The input sizes are 240 × 240 and 120×120 respectively, and the output sizes are the same as the input ones.’而且论文所给的结构图中也是这么标识的,所以我对这个720的尺寸还是有点不大理解。

wangyuanyuan0 avatar Jan 11 '19 10:01 wangyuanyuan0

被我记混了,训练时的输入是从720x720原始图像中crop 240 × 240的图像作为输入(可以看做增广);测试的时候我将模型输入尺寸进行了修改,可以估计720x720原始图像的密度图(修改为其它尺寸也是可以的)

训练代码: https://github.com/Ling-Bao/ACSCP_cGAN/blob/master/model.py

# Line 42
def __init__(self, sess, image_size=240, batch_size=16, sample_size=1, output_size=240, df_dim=48, input_c_dim=3, output_c_dim=3, data_set_name='facades', checkpoint_dir=None, lambda_e=150, ambda_p=150, lambda_c=10):

测试代码: https://github.com/Ling-Bao/ACSCP_cGAN/blob/master/product.py

# 输入图像  Line 44
self.x = tf.placeholder(tf.float32, [1, 720, 720, 3])

Ling-Bao avatar Jan 11 '19 10:01 Ling-Bao

Hi, you may be interested in my implementation in pytorch. It includes the density map generation. https://github.com/RQuispeC/pytorch-ACSCP

RQuispeC avatar Apr 06 '19 21:04 RQuispeC