VILA-Lab / SRe2L

(NeurIPS 2023 spotlight) Large-scale Dataset Distillation/Condensation, 50 IPC (Images Per Class) achieves the highest 60.8% on original ImageNet-1K val set.
119 stars 16 forks source link

How to modify source code for _MapDatasetFetcher #2

Closed xingyifei2016 closed 1 year ago

xingyifei2016 commented 1 year ago

When I run the train code (as in train_FKD.py) as provided, it errors on the getitem method of ImageFolder_FKD_MIX not having the corresponding batch_config. I understand that this config is loaded via load_batch_config, which is the reason why _MapDatasetFetcher is modified in the first place. However, the docs do not provide an actual procedure except some code. How do I actually overwrite the original pytorch source code to become the new code provided? Do I need to run a locally compiled version of pytorch for this to work? Are there solutions that only requires a few additional lines for it to work? Thank you.

zeyuanyin commented 1 year ago

Thanks for your interest in this project!

It is not difficult to modify the PyTorch source code. Here are some quick tips,

Kindly note that the modification operation will not have any adverse effects on other PyTorch workflows, and you can continue to run other codes as usual.

xingyifei2016 commented 1 year ago

Thank you for the reply! However, if I cannot access VS code, as I am using an online server and only have access to jupyter notebook, how would I modify the source code?

zeyuanyin commented 1 year ago

If you are not using VSCode or PyCharm, you cannot quickly navigate to the source file fetch.py by using Ctrl+Click.

To retrieve the location of fetch.py and proceed with modifications, you can utilize the following code. Once the location is obtained, you can navigate to the file for editing.

import torch.utils.data._utils.fetch as fetch
print(fetch.__file__)

# my output: /home/zeyuan.yin/.conda/envs/py38/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py 
# `py38` is my current conda environment name.
xingyifei2016 commented 1 year ago

Thank you so much zeyuan! That answers my question. :)