victoresque / pytorch-template

PyTorch deep learning projects made easy.
MIT License
4.75k stars 1.09k forks source link

Tidying up (grouping, adding some spacing and commenting) the code base #20

Closed borgesa closed 6 years ago

borgesa commented 6 years ago

Hi,

I would propose that we go through the repository and add more comments/documentation inline, as well as giving the overall code some more structure.

This in order to make it easier for new users to understand the mechanics of the template code.

A good example of this need is the 'BaseTrainer' class. I believe that it would benefit from some restructuring (not functional, but as mentioned make it easier to get an overview).

Do you agree?

victoresque commented 6 years ago

@borgesa I agree that more clear comments are needed, especially in the base classes. Like you said the BaseTrainer class has some methods that is not very easy to follow (e.g. the train method), also, the variable initializations in __init__ for many classes can be confusing for newcomers, adding some comments would be helpful.

borgesa commented 6 years ago

Glad you agree. I can try to look a little into it next week.

SunQpark commented 6 years ago

How do you think about the folder structure of project?? This is current state.

  pytorch-template/
  │
  ├── train.py - example main
  ├── config.json - example config file
  │
  ├── base/ - abstract base classes
  │   ├── base_data_loader.py - abstract base class for data loaders
  │   ├── base_model.py - abstract base class for models
  │   └── base_trainer.py - abstract base class for trainers
  │
  ├── data_loader/ - anything about data loading goes here
  │   └── data_loaders.py
  │
  ├── datasets/ - default datasets folder
  │
  ├── logger/ - for training process logging
  │   └── logger.py
  │   └── visualization.py
  │
  ├── model/ - models, losses, and metrics
  │   ├── modules/ - submodules of your model
  │   ├── loss.py
  │   ├── metric.py
  │   └── model.py
  │
  ├── saved/ - default checkpoints folder
  │   └── runs/ - default logdir for tensorboardX
  │
  ├── trainer/ - trainers
  │   └── trainer.py
  │
  └── utils/
      ├── util.py
      └── ...

When I start a new project based on this, I always make some changes.

  1. move data_loader.py, trainer.py to the project root dir
  2. delete subfolders contained it with the __init__.py files.
  3. delete datasets/ and modules/.

I prefer script files to be in the root folder because the importing from other folders sometimes break, especially when I want to run test on a single file(using if __name__ == '__main__':). I also prefer dataset and modules on the data_loader.py and model.py respectively, unless their length becomes too long. Maybe this can be considered just as my personal preference, but I think it will also help people who are new to this template.

borgesa commented 6 years ago

I have also been thinking about the overall setup.

There are some ideas that I have gotten from some other repositories, as well as some ideas about how I would really love the template to look like.

If I have time tomorrow, I can try to draught down some input to the discussion (at least one of the next days).

Speak soon!