seigot / tetris

A Tetris Game for programming education in Japanese
MIT License
30 stars 107 forks source link

GitAuto: `load None` `FileNotFoundError: [Errno 2] No such file or directory: 'None'` #154

Open gitauto-ai[bot] opened 2 weeks ago

gitauto-ai[bot] commented 2 weeks ago

Resolves #23

Why the bug occurs

When no training model is loaded, the weight parameter is set to None. The code attempts to load the model using torch.load(weight), which results in a FileNotFoundError because 'None' is treated as a string path that does not exist.

How to reproduce

  1. Run the command without specifying a model weight file:
    python start.py -l2 -m predict
  2. The program sets weight=None and attempts to execute torch.load(weight).
  3. A FileNotFoundError is raised:
    FileNotFoundError: [Errno 2] No such file or directory: 'None'

How to fix

Implement a check to ensure that the weight parameter is not None before attempting to load the model. If weight is None, either initialize a default model or prompt the user to provide a valid weight file path. This prevents the application from attempting to load a non-existent file and provides a clear pathway for handling scenarios where no model is specified.

Example modification in block_controller_train.py:

def set_parameter(self, weight=None):
    if weight is not None:
        self.model = torch.load(weight)
    else:
        # Initialize a default model or handle the absence of a weight file
        self.model = self.initialize_default_model()

Test these changes locally

git checkout -b gitauto/issue-23-df22e20a-2e6c-4ce2-b859-e272cf403e55
git pull origin gitauto/issue-23-df22e20a-2e6c-4ce2-b859-e272cf403e55