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
Run the command without specifying a model weight file:
python start.py -l2 -m predict
The program sets weight=None and attempts to execute torch.load(weight).
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()
Resolves #23
Why the bug occurs
When no training model is loaded, the
weight
parameter is set toNone
. The code attempts to load the model usingtorch.load(weight)
, which results in aFileNotFoundError
because'None'
is treated as a string path that does not exist.How to reproduce
weight=None
and attempts to executetorch.load(weight)
.FileNotFoundError
is raised:How to fix
Implement a check to ensure that the
weight
parameter is notNone
before attempting to load the model. Ifweight
isNone
, 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
:Test these changes locally