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

How to estimate other images #1

Open
nomurakeiya opened this issue Apr 12, 2021 · 4 comments
Open

How to estimate other images #1

nomurakeiya opened this issue Apr 12, 2021 · 4 comments

Comments

@nomurakeiya
Copy link

Hello!
Thanks for good code!

I want to know How to estimate other images.

The part to train the model and verify it is done↓
{"mae": 8.784251246271253, "mse": 14.054188578956241, "ssim": 0.9816682679202778}

As a next step I would like to estimate the density map from the images not included in the Shanghai dataset.

@tempdata73
Copy link
Owner

tempdata73 commented Apr 12, 2021

Hey there!

By estimate do you mean that you want to put the model in production? If so, then you're gonna have to create your own function for loading and preprocessing the images. You might want to take a look into the create_dataloader function in the utils/augmentation.py file; in line 73 I define the preprocessing pipeline that images must get through in order to be a valid input for the model. Everything else is dedicated to loading and processing the targets which you won't need if the model will be put in production. Finally, you'll just need to load the model:

model = CSRNet(training=False)
model.load_state_dict(torch.load(PATH))
model.eval()

If you mean that you want to retrain the model using other datasets then in utils/dataset.py you'll have to define a subclass of Base and define the load_groundtruth and generate_density_map methods. However I'm not 100% sure if that will work as that part of the code is ugly. Probably this weekend I'll try and fix it so that it can work for other datasets.

@nomurakeiya
Copy link
Author

Thank you so much for your polite answer!!

By estimate do you mean that you want to put the model in production?

That's right. I want to estimate the density map from the image I took and measure the number of people!!

file; in line 73 I define the preprocessing pipeline that images must get through in order to be a valid input for the model. Everything else is dedicated to loading and processing the targets which you won't need if the model will be put in production. Finally, you'll just need to load the model:

I'm sorry, I couldn't understand...
Do you mean to add these three lines of code somewhere?
I want to know how to create my own function for loading and preprocessing the images!!

If you mean that you want to retrain the model using other datasets then in utils/dataset.py you'll have to define a subclass of Base and define the load_groundtruth and generate_density_map methods. However I'm not 100% sure if that will work as that part of the code is ugly. Probably this weekend I'll try and fix it so that it can work for other datasets.

I would like to do this as well if possible.
Thanks for rewriting the code.

And I have a question,
Is data (.mat, .h5) required in addition to the image when estimating the density map with the trained model?
If possible, I would like to enter only the image to estimate the density map.

Thank you so much for your answer!!

@tempdata73
Copy link
Owner

tempdata73 commented Apr 13, 2021

Do you mean to add these three lines of code somewhere?

Yes, you'll have to create your own file where the images are loaded and processed using the preprocessing transformer defined in line 73. Then the model will have to be loaded and the images fed into it. I haven't used PyTorch in a while so I don't remember if you'll need a DataLoader or something of the sort in order to pass the images into the model. Since I created this repo for specifically training the model, I didn't create a "test with your own images" file, but it would be a nice add-on for the next update.

I would like to do this as well if possible.

I will try and update the code this weekend so that it accepts the other datasets mentioned in the README, however I can't promise anything.

Is data (.mat, .h5) required in addition to the image when estimating the density map with the trained model?

No, the .h5 files are the targets used for training the model; as I recall that's how the Shanghai dataset came so I had to transform them into images and postprocess them. You'll just need your own images.

@nomurakeiya
Copy link
Author

I didn't create a "test with your own images" file, but it would be a nice add-on for the next update.

I will try and update the code this weekend so that it accepts the other datasets mentioned in the README, however I can't promise anything.

I understand everything.
Your technical skills are amazing, so I'm looking forward to the next update!!

You'll just need your own images.

I see, thank you!

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

2 participants