Skip to content

Commit b3b27ff

Browse files
authored
Merge pull request #285 from matchms/fix_load_validation
Fix load validation
2 parents 834ca1b + e97649f commit b3b27ff

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## 2.7.1
9+
### Fixed
10+
- In 2.7.0 a bug was introduced, failing the loading of models. Here this is fixed.
11+
- Added a check that a model file exists, for clearer error handling.
12+
813
## 2.7.0
914
### Added
1015
- The training pair sampling for both ionmodes is now balanced over the different ionmode pairs.

ms2deepscore/SettingsMS2Deepscore.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ class SettingsMS2Deepscore:
9393
If True the model will do separate pair sampling for training for each ionmode.
9494
This gives better balance over the ionmodes. Initial results showed a decrease in pos-pos prediction
9595
accuracy. Which you can find in the notebook model_benchmarking/Compare balanced cross ion moe sampling.ipynb
96-
additional_metadata:
97-
Additional metadata that should be used in training the model. e.g. precursor_mz
9896
dropout_rate:
9997
The dropout rate that should be used during training
10098
learning_rate:
@@ -272,8 +270,6 @@ def __init__(self, validate_settings=True, **settings):
272270
np.random.seed(self.random_seed)
273271

274272
if self.spectrum_file_path is not None:
275-
if not os.path.isfile(self.spectrum_file_path):
276-
raise ValueError("The spectrum file specified is not an existing file")
277273
root_dir = os.path.dirname(self.spectrum_file_path)
278274
spectrum_file_name = os.path.basename(self.spectrum_file_path)
279275

@@ -304,7 +300,10 @@ def validate_settings(self):
304300
validate_bin_order(self.same_prob_bins)
305301
if self.balanced_sampling_across_ionmodes and self.ionisation_mode != "both":
306302
raise ValueError("Balanced sampling across ionmodes only works if you train on both ionmodes")
307-
303+
if self.spectrum_file_path is not None:
304+
if not os.path.isfile(self.spectrum_file_path):
305+
raise ValueError("The spectrum file specified is not an existing file")
306+
308307
def create_model_directory_name(self):
309308
"""Creates a directory name using metadata, it will contain the metadata, the binned spectra and final model"""
310309
binning_file_label = ""

ms2deepscore/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.7.0'
1+
__version__ = '2.7.1'

ms2deepscore/models/load_model.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from typing import Union, Dict, Optional, Any, Callable
23
import json
34
from pathlib import Path
@@ -130,6 +131,8 @@ def _load_model_generic(
130131
3) Instantiate model via model_factory(settings), then load state_dict.
131132
4) If safe path fails and allow_legacy=True, attempt unsafe legacy path.
132133
"""
134+
if not os.path.isfile(filename):
135+
raise ValueError(f"The file given does not exist: {filename}")
133136
# --- preferred safe path
134137
try:
135138
ckpt = _load_ckpt_safe(filename)

tests/test_load_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
def _dummy_siamese_model():
1212
"""Helper function to create a dummy SiameseSpectralModel."""
13-
settings = SettingsMS2Deepscore(base_dims=(100, 100), embedding_dim=10)
13+
settings = SettingsMS2Deepscore(base_dims=(100, 100), embedding_dim=10, spectrum_file_path="./nonexisting_path.mgf", validate_settings=False)
1414
model = SiameseSpectralModel(settings=settings)
1515
return model
1616

0 commit comments

Comments
 (0)