lsc-cnn icon indicating copy to clipboard operation
lsc-cnn copied to clipboard

How do I predict with a picture of myself?

Open yds5817 opened this issue 4 years ago • 15 comments

yds5817 avatar Jul 09 '19 05:07 yds5817

There is no. Mat file in my own picture, so I removed the second path in 'paths', but there was an error next! ‘’‘ Traceback (most recent call last): File "main.py", line 1098, in train() File "main.py", line 1019, in train test_batch_size=4) File "/data/shareJ/YDS/lsc-cnn-master/data_reader.py", line 200, in create_dataset_files self._dump_all_test_images(set_name) File "/data/shareJ/YDS/lsc-cnn-master/data_reader.py", line 837, in _dump_all_test_images crops = self._get_one_image_test_crops(data) File "/data/shareJ/YDS/lsc-cnn-master/data_reader.py", line 555, in _get_one_image_test_crops <= data[0].shape[WIDTH_IDX] and IndexError: tuple index out of range ’‘’

yds5817 avatar Jul 09 '19 06:07 yds5817

I think that there is not a dedicated script for the prediction task. Can the authors provide us a script that accomplishes this task or at least give us some instructions to create it and contribute to the project ?

MounirB avatar Jul 09 '19 14:07 MounirB

Hello, I'm in the process of adding this feature, but for the time being, you can keep the .mat file as is and put your image in the images folder and dump the dataset and then test according to the instructions given in the README.md. Let me know if you run into problems with this hack.

pvskand avatar Jul 12 '19 14:07 pvskand

You can try to use my fork : https://github.com/vlad3996/lsc-cnn

vlad3996 avatar Jul 20 '19 04:07 vlad3996

@vlad3996 not working.can you tell me what weights and what needs to be done,i get fllowing error -

RuntimeError: Error(s) in loading state_dict for LSCCNN: Missing key(s) in state_dict: "conv1_1.weight", "conv1_1.bias", "conv1_2.weight", "conv1_2.bias", "conv2_1.weight", "conv2_1.bias", "conv2_2.weight", "conv2_2.bias", "conv3_1.weight", "conv3_1.bias", "conv3_2.weight", "conv3_2.bias", "conv3_3.weight", "conv3_3.bias", "conv4_1.weight", "conv4_1.bias", "conv4_2.weight", "conv4_2.bias", "conv4_3.weight", "conv4_3.bias", "conv5_1.weight", "conv5_1.bias", "conv5_2.weight", "conv5_2.bias", "conv5_3.weight", "conv5_3.bias", "convA_1.weight", "convA_1.bias", "convA_2.weight", "convA_2.bias", "convA_3.weight", "convA_3.bias", "convA_4.weight", "convA_4.bias", "convA_5.weight", "convA_5.bias", "convB_1.weight", "convB_1.bias", "convB_2.weight", "convB_2.bias", "convB_3.weight", "convB_3.bias", "convB_4.weight", "convB_4.bias", "convB_5.weight", "convB_5.bias", "convC_1.weight", "convC_1.bias", "convC_2.weight", "convC_2.bias", "convC_3.weight", "convC_3.bias", "convC_4.weight", "convC_4.bias", "convC_5.weight", "convC_5.bias", "convD_1.weight", "convD_1.bias", "convD_2.weight", "convD_2.bias", "convD_3.weight", "convD_3.bias", "convD_4.weight", "convD_4.bias", "convD_5.weight", "convD_5.bias", "conv_before_transpose_1.weight", "conv_before_transpose_1.bias", "transpose_1.weight", "transpose_1.bias", "conv_after_transpose_1_1.weight", "conv_after_transpose_1_1.bias", "transpose_2.weight", "transpose_2.bias", "conv_after_transpose_2_1.weight", "conv_after_transpose_2_1.bias", "transpose_3.weight", "transpose_3.bias", "conv_after_transpose_3_1.weight", "conv_after_transpose_3_1.bias", "transpose_4_1_a.weight", "transpose_4_1_a.bias", "transpose_4_1_b.weight", "transpose_4_1_b.bias", "conv_after_transpose_4_1.weight", "conv_after_transpose_4_1.bias", "transpose_4_2.weight", "transpose_4_2.bias", "conv_after_transpose_4_2.weight", "conv_after_transpose_4_2.bias", "transpose_4_3.weight", "transpose_4_3.bias", "conv_after_transpose_4_3.weight", "conv_after_transpose_4_3.bias", "conv_middle_1.weight", "conv_middle_1.bias", "conv_middle_2.weight", "conv_middle_2.bias", "conv_middle_3.weight", "conv_middle_3.bias", "conv_mid_4.weight", "conv_mid_4.bias", "conv_lowest_1.weight", "conv_lowest_1.bias", "conv_lowest_2.weight", "conv_lowest_2.bias", "conv_lowest_3.weight", "conv_lowest_3.bias", "conv_lowest_4.weight", "conv_lowest_4.bias", "conv_scale1_1.weight", "conv_scale1_1.bias", "conv_scale1_2.weight", "conv_scale1_2.bias", "conv_scale1_3.weight", "conv_scale1_3.bias". Unexpected key(s) in state_dict: "epoch", "state_dict", "optimizer".

learnermaxRL avatar Jul 20 '19 09:07 learnermaxRL

after downlaoding wieghts mentioned in your readme -

out = self.forward(torch.from_numpy(image.transpose((2, 0, 1)).astype(np.float32)).unsqueeze(0).cuda()) File "/home/jbasmsdsdai/Downloads/lsc-cnn-master/model.py", line 140, in forward sub1_concat = torch.cat((sub1_out_conv1, sub1_after_transpose_1), dim=1) RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. Got 74 and 75 in dimension 2 at /opt/conda/conda-bld/pytorch_1556653215914/work/aten/src/THC/generic/THCTensorMath.cu:71

learnermaxRL avatar Jul 20 '19 10:07 learnermaxRL

@learnermaxRL the problem is with input image shape : it must be divisible by 16 because author concatenate feature maps from 3rd pooling layer and upsampled by nn.ConvTranspose2d maps from 4th pooling layer, which can not match by shape.

vlad3996 avatar Jul 20 '19 21:07 vlad3996

If people are interested, i wrote some code to port the existing .pth weights into a keras version of the model, although it doesnt support batch predictions for now, only one, and i used the same NMS approach used in this repository, but if your goal is to just do prediction, it can be used

Example of using the detection from the model is also supplied

usamahjundia avatar Jul 31 '19 03:07 usamahjundia

@learnermaxRL the problem is with input image shape : it must be divisible by 16 because author concatenate feature maps from 3rd pooling layer and upsampled by nn.ConvTranspose2d maps from 4th pooling layer, which can not match by shape.

You can try to use my fork : https://github.com/vlad3996/lsc-cnn

How to train other dataset in you fork?

zhoujoey avatar Sep 16 '19 08:09 zhoujoey

You can try to use my fork : https://github.com/vlad3996/lsc-cnn

How do I get the count of people ? Does it return somewhere ?

AniketVelhankar avatar May 14 '20 14:05 AniketVelhankar

You can try to use my fork : https://github.com/vlad3996/lsc-cnn

How do I get the count of people ? Does it return somewhere ?

it is easily achievable by getting the length of the resulting array of detections

usamahjundia avatar May 15 '20 06:05 usamahjundia

You can try to use my fork : https://github.com/vlad3996/lsc-cnn

image this is my test result ,why

knightyxp avatar Sep 29 '20 15:09 knightyxp

@vlad3996 not working.can you tell me what weights and what needs to be done,i get fllowing error -

RuntimeError: Error(s) in loading state_dict for LSCCNN: Missing key(s) in state_dict: "conv1_1.weight", "conv1_1.bias", "conv1_2.weight", "conv1_2.bias", "conv2_1.weight", "conv2_1.bias", "conv2_2.weight", "conv2_2.bias", "conv3_1.weight", "conv3_1.bias", "conv3_2.weight", "conv3_2.bias", "conv3_3.weight", "conv3_3.bias", "conv4_1.weight", "conv4_1.bias", "conv4_2.weight", "conv4_2.bias", "conv4_3.weight", "conv4_3.bias", "conv5_1.weight", "conv5_1.bias", "conv5_2.weight", "conv5_2.bias", "conv5_3.weight", "conv5_3.bias", "convA_1.weight", "convA_1.bias", "convA_2.weight", "convA_2.bias", "convA_3.weight", "convA_3.bias", "convA_4.weight", "convA_4.bias", "convA_5.weight", "convA_5.bias", "convB_1.weight", "convB_1.bias", "convB_2.weight", "convB_2.bias", "convB_3.weight", "convB_3.bias", "convB_4.weight", "convB_4.bias", "convB_5.weight", "convB_5.bias", "convC_1.weight", "convC_1.bias", "convC_2.weight", "convC_2.bias", "convC_3.weight", "convC_3.bias", "convC_4.weight", "convC_4.bias", "convC_5.weight", "convC_5.bias", "convD_1.weight", "convD_1.bias", "convD_2.weight", "convD_2.bias", "convD_3.weight", "convD_3.bias", "convD_4.weight", "convD_4.bias", "convD_5.weight", "convD_5.bias", "conv_before_transpose_1.weight", "conv_before_transpose_1.bias", "transpose_1.weight", "transpose_1.bias", "conv_after_transpose_1_1.weight", "conv_after_transpose_1_1.bias", "transpose_2.weight", "transpose_2.bias", "conv_after_transpose_2_1.weight", "conv_after_transpose_2_1.bias", "transpose_3.weight", "transpose_3.bias", "conv_after_transpose_3_1.weight", "conv_after_transpose_3_1.bias", "transpose_4_1_a.weight", "transpose_4_1_a.bias", "transpose_4_1_b.weight", "transpose_4_1_b.bias", "conv_after_transpose_4_1.weight", "conv_after_transpose_4_1.bias", "transpose_4_2.weight", "transpose_4_2.bias", "conv_after_transpose_4_2.weight", "conv_after_transpose_4_2.bias", "transpose_4_3.weight", "transpose_4_3.bias", "conv_after_transpose_4_3.weight", "conv_after_transpose_4_3.bias", "conv_middle_1.weight", "conv_middle_1.bias", "conv_middle_2.weight", "conv_middle_2.bias", "conv_middle_3.weight", "conv_middle_3.bias", "conv_mid_4.weight", "conv_mid_4.bias", "conv_lowest_1.weight", "conv_lowest_1.bias", "conv_lowest_2.weight", "conv_lowest_2.bias", "conv_lowest_3.weight", "conv_lowest_3.bias", "conv_lowest_4.weight", "conv_lowest_4.bias", "conv_scale1_1.weight", "conv_scale1_1.bias", "conv_scale1_2.weight", "conv_scale1_2.bias", "conv_scale1_3.weight", "conv_scale1_3.bias". Unexpected key(s) in state_dict: "epoch", "state_dict", "optimizer".

@learnermaxRL how did you fix the error you were experiencing?

kaamlaS avatar Aug 16 '22 13:08 kaamlaS

@kaamlaS add model.load_state_dict(checkpoint['state_dict'], strict=False) to line 107 in model.py

mic2112 avatar Aug 17 '22 07:08 mic2112

You can try to use my fork : https://github.com/vlad3996/lsc-cnn

image this is my test result ,why

@knightyxp Did you manage to get better results from this?

mic2112 avatar Aug 17 '22 08:08 mic2112