Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 2.7.1
### Fixed
- In 2.7.0 a bug was introduced, failing the loading of models. Here this is fixed.
- Added a check that a model file exists, for clearer error handling.

## 2.7.0
### Added
- The training pair sampling for both ionmodes is now balanced over the different ionmode pairs.
Expand Down
9 changes: 4 additions & 5 deletions ms2deepscore/SettingsMS2Deepscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ class SettingsMS2Deepscore:
If True the model will do separate pair sampling for training for each ionmode.
This gives better balance over the ionmodes. Initial results showed a decrease in pos-pos prediction
accuracy. Which you can find in the notebook model_benchmarking/Compare balanced cross ion moe sampling.ipynb
additional_metadata:
Additional metadata that should be used in training the model. e.g. precursor_mz
dropout_rate:
The dropout rate that should be used during training
learning_rate:
Expand Down Expand Up @@ -272,8 +270,6 @@ def __init__(self, validate_settings=True, **settings):
np.random.seed(self.random_seed)

if self.spectrum_file_path is not None:
if not os.path.isfile(self.spectrum_file_path):
raise ValueError("The spectrum file specified is not an existing file")
root_dir = os.path.dirname(self.spectrum_file_path)
spectrum_file_name = os.path.basename(self.spectrum_file_path)

Expand Down Expand Up @@ -304,7 +300,10 @@ def validate_settings(self):
validate_bin_order(self.same_prob_bins)
if self.balanced_sampling_across_ionmodes and self.ionisation_mode != "both":
raise ValueError("Balanced sampling across ionmodes only works if you train on both ionmodes")

if self.spectrum_file_path is not None:
if not os.path.isfile(self.spectrum_file_path):
raise ValueError("The spectrum file specified is not an existing file")

def create_model_directory_name(self):
"""Creates a directory name using metadata, it will contain the metadata, the binned spectra and final model"""
binning_file_label = ""
Expand Down
2 changes: 1 addition & 1 deletion ms2deepscore/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.7.0'
__version__ = '2.7.1'
3 changes: 3 additions & 0 deletions ms2deepscore/models/load_model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from typing import Union, Dict, Optional, Any, Callable
import json
from pathlib import Path
Expand Down Expand Up @@ -130,6 +131,8 @@ def _load_model_generic(
3) Instantiate model via model_factory(settings), then load state_dict.
4) If safe path fails and allow_legacy=True, attempt unsafe legacy path.
"""
if not os.path.isfile(filename):
raise ValueError(f"The file given does not exist: {filename}")
# --- preferred safe path
try:
ckpt = _load_ckpt_safe(filename)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_load_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def _dummy_siamese_model():
"""Helper function to create a dummy SiameseSpectralModel."""
settings = SettingsMS2Deepscore(base_dims=(100, 100), embedding_dim=10)
settings = SettingsMS2Deepscore(base_dims=(100, 100), embedding_dim=10, spectrum_file_path="./nonexisting_path.mgf", validate_settings=False)
model = SiameseSpectralModel(settings=settings)
return model

Expand Down