Skip to content

Conversation

@Ricocotam
Copy link
Collaborator

From issue #17 I created a minimal example of what I had in mind. This is a minimal example and some questions need to be answered.

Path of the new project

We need to create a folder for the project. I propose to use 2 different name : project_path and project_name. We then could have an architecture like :

+ project_path
    + project_name
        - __init__.py
        + models
            + networks
                - __init__.py
                - factory.py
                - mynetwork.py
    + logs

(+ denotes a folder, - a file)

This is an open suggestion. I choose this implementation so logs' folder is also created and is with the rest of the code.

Network as minimal example

I did a minimal example so we can discuss implementation details. Creating files and folders is done with pathlib.Path to use the / operation to join paths. The real question is : how to we fill created files with basic content ? I choose to have raw text written in the new.py I am Pull Requesting but I don't think that's the better option as this is not easily maintainable and it leads to a really long new.py file. My suggestion is to have a basic file we can copy to the project created. This requires to store quite a lot of files in the lib only used to be copied so it has some drawbacks too.

I am also working on a complete project creation with options to create any relevant directory but I didn't want to pollute the discussion with useless lines of code

@Cadene
Copy link
Owner

Cadene commented Mar 28, 2020

Thanks @Ricocotam, it's much needed!

However, we need a way to avoid putting executable code into a string such as this

I would suggest creating template python files in the bootstrap directory, copying them and even replacing some elements in it.

For instance, instead of this, we would have the following file in bootstrap/templates/default/project/models/networks/network.py:

import torch.nn as nn

class MyNetwork(nn.Module):
    def __init__(self, *args, **kwargs):
        super(MyNetwork, self).__init__()
        # Assign args
    def forward(self, x):
        # x is a dictionnary given by Dataset class
        pred = self.net(x)
        return pred  # This is a tensor (or several tensors)

Also, we discussed with @MicaelCarvalho.
In a first time, we would like to create a simple structure with a network, a criterion, a metric and a dataset. Also, these 4 "modules" will take the name of the project.
For instance, python -m bootstrap.new --project_name MyExample will create:

myexample.bootstrap.pytorch/myexample/models/networks/myexample.py
myexample.bootstrap.pytorch/myexample/models/criterions/myexample.py
myexample.bootstrap.pytorch/myexample/models/metrics/myexample.py
myexample.bootstrap.pytorch/myexample/datasets/myexample.py

With the following class names:

class MyExampleNetwork
class MyExampleCriterion
class MyExampleMetric
class MyExampleDataset

As well as other files such as __init__.py, factory.py and:

myexample.bootstrap.pytorch/README.md
myexample.bootstrap.pytorch/.gitignore
myexample.bootstrap.pytorch/setup.cfg
myexample.bootstrap.pytorch/setup.py
myexample.bootstrap.pytorch/LICENSE.txt
myexample.bootstrap.pytorch/myexample/__version__.py

Lastly, files from bootstrap/templates will be parsed and some strings will be replaced such as:

{PROJECT_NAME}, {PROJECT_NAME_LOWER}, {PROJECT_NAME_UPPER}

Do you agree? Is it clear? @Ricocotam

@Cadene Cadene linked an issue Mar 28, 2020 that may be closed by this pull request
@Cadene Cadene changed the title Helper for new bootstrap projects Script to create new projects Mar 28, 2020
@Ricocotam
Copy link
Collaborator Author

Ricocotam commented Mar 29, 2020

Alright, so I did what you said on the latest commit

bootstrap/new.py Outdated


parser = ArgumentParser()
parser.add_argument("project_path", action="store", type=str, help="Path to new project")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to keep project_path.
What do you think @MicaelCarvalho ?

new_dir = path / directory
if directory != "models":
new_dir.mkdir()
files = get_files(new_dir)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As specified here, we would like to follow this path pattern bootstrap/templates/default/project/datasets/dataset.py instead of your current bootstrap/template/datasets/template_dataset.py.

def factory(engine=None, mode="train"):
opt = Options()['model.metric']

if opt['name'] == '{PROJECT_NAME_LOWER}metric':
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'metric' can be removed here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure to understand what you mean ?

Copy link
Owner

@Cadene Cadene Apr 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def factory(engine=None, mode="train"):
    opt = Options()['model.metric']

    if opt['name'] == '{PROJECT_NAME_LOWER}':

opt = Options()['model.metric']

if opt['name'] == '{PROJECT_NAME_LOWER}metric':
metric = {PROJECT_NAME_LOWER}metric()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metric

@Cadene
Copy link
Owner

Cadene commented Mar 29, 2020

Thanks! @Ricocotam
I added some comments

We should probably add a test to verify that everything can work.
It implies to have some default return values (torch.tensor(0)) instead of raise NotImplementedError or pass.
What do you think? @Ricocotam @MicaelCarvalho

@Ricocotam
Copy link
Collaborator Author

I'll fix your different comments soon. Anything to add ?

@Ricocotam
Copy link
Collaborator Author

So we need some tests now

The only thing I didn't do is to name custom dataset after the project name, I kept mydataset.py : myexample.bootstrap.pytorch/myexample/datasets/myexample.py-> myexample.bootstrap.pytorch/myexample/datasets/mydataset.py

I can write some tests (we just have to check files have the right content and that they are created) but I know how it works already. May be, to ensure code is both clear and that agree on what/how it does it, someone else should right the tests

@MicaelCarvalho MicaelCarvalho self-requested a review April 11, 2020 09:19
Ricocotam added a commit that referenced this pull request May 15, 2020
Script to create new projects v2 (old in PR #19)
@Ricocotam
Copy link
Collaborator Author

Solved in #35

@Ricocotam Ricocotam closed this May 15, 2020
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

Successfully merging this pull request may close these issues.

Add script to create new projects

2 participants