Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2023-04 Model #22

Merged
merged 11 commits into from
May 2, 2023
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ data/**/*.pkl
*.synctex.gz
*.osr
lightning_logs/
models/
.streamlit/
poetry.lock
.data/
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ It uses Neural Collaborative Filtering to learn associations between user and ma
predict new scores never before seen.

**Performance Error Graph**
![Performance Graph](models/V2_2023_01/error.png)
![Performance Graph](models/V2_2023_04/error.png)

## :hourglass_flowing_sand: Project Status

Expand Down Expand Up @@ -35,7 +35,7 @@ If you want to use this locally, you need Python and the packages listed in [req

Below is a recipe on how to use it.
```py
path_to_model = MODEL_DIR / "V2_2023_01/checkpoints/epoch=5-step=43584.ckpt"
path_to_model = "oath/to/model.ckpt"
net = NeuMF.load_from_checkpoint(path_to_model.as_posix())

# THIS MUST BE RAN TO AVOID TRAINING THE MODEL
Expand Down
17 changes: 9 additions & 8 deletions app/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path

import sys
import torch
from google.cloud import firestore

sys.path.append(Path(__file__).parents[1].as_posix())
Expand Down Expand Up @@ -45,7 +46,7 @@ def add_analytics_count(add: int):


@st.cache_resource
def get_model(model_path=MODEL_DIR / "V2_2023_01/checkpoints/epoch=5-step=43584.ckpt"):
def get_model(model_path=MODEL_DIR / "V2_2023_04/checkpoints/epoch=8-step=55773.ckpt"):
net = NeuMF.load_from_checkpoint(model_path.as_posix(), map_location=torch.device('cpu'))
net.eval()
return net
Expand Down Expand Up @@ -107,17 +108,17 @@ def get_beatmap_metadata(beatmap_id: int):
with st.sidebar:
st.header(":game_die: Metrics")
st.markdown("""
![R2](https://img.shields.io/badge/R%20Squared-81.48%25-blueviolet)
![MAE](https://img.shields.io/badge/MAE-1.18%25-blue)
![RMSE](https://img.shields.io/badge/RMSE-1.71%25-blue)
![R2](https://img.shields.io/badge/R%20Squared-71.88%25-blueviolet)
![MAE](https://img.shields.io/badge/MAE-1.14%25-blue)
![RMSE](https://img.shields.io/badge/RMSE-1.68%25-blue)
![Model Size](https://img.shields.io/github/size/Eve-ning/opal/models/V2_2023_01/checkpoints/epoch%253D5-step%253D43584.ckpt?color=purple&label=Model%20Size&logo=pytorch-lightning)
""")
st.header(":bookmark: Requirements")
st.markdown("""
1) Only osu!mania.

The user must be:
1) ranked <10K in 1st Jan 2023
1) ranked <10K in 1st Apr 2023
2) active in that predicted year

The map must be:
Expand Down Expand Up @@ -199,9 +200,9 @@ def get_beatmap_metadata(beatmap_id: int):
pred_nt = df_pred_last.loc[(df_pred_last['speed'] == 'NT'), 'pred']
pred_dt = df_pred_last.loc[(df_pred_last['speed'] == 'DT'), 'pred']

pred_ht = float(pred_ht) if pred_ht.any() else None
pred_nt = float(pred_nt) if pred_nt.any() else None
pred_dt = float(pred_dt) if pred_dt.any() else None
pred_ht = float(pred_ht.iloc[0]) if pred_ht.any() else None
pred_nt = float(pred_nt.iloc[0]) if pred_nt.any() else None
pred_dt = float(pred_dt.iloc[0]) if pred_dt.any() else None

c1, c2, c3 = st.columns(3)

Expand Down
5 changes: 3 additions & 2 deletions models/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

**See below on how to load the model.**

| Model | R2 | MAE | RMSE | Error Distribution |
|------------|--------|--------|-------|--------------------------------|
| Model | R2 | MAE | RMSE | Error Distribution |
|------------|--------|-------|-------|--------------------------------|
| V2_2023_01 | 81.48% | 1.18% | 1.71% | ![Error](V2_2023_01/error.png) |
| V2_2023_04 | 71.88% | 1.14% | 1.68% | ![Error](V2_2023_04/error.png) |

**Note: V1 is deprecated due to incompatibility with new model signature.**
## Limitations
Expand Down
487 changes: 487 additions & 0 deletions models/V2_2023_04/analysis.ipynb

Large diffs are not rendered by default.

Binary file not shown.
Binary file added models/V2_2023_04/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added models/V2_2023_04/overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions opal/score/datamodule/score_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def prep_metric(df: pd.DataFrame,
Adds Year column
"""

df = df.dropna()
df['enabled_mods'] = df['enabled_mods'].astype(int)
half_score = (
((df['enabled_mods'] & OsuMod.EASY) > 0) |
((df['enabled_mods'] & OsuMod.NO_FAIL) > 0) |
Expand Down
5 changes: 2 additions & 3 deletions opal/train.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytorch_lightning as pl
import torch
from pytorch_lightning.callbacks import LearningRateMonitor, EarlyStopping, ModelCheckpoint, ModelPruning, QuantizationAwareTraining
from pytorch_lightning.callbacks import LearningRateMonitor, EarlyStopping, ModelCheckpoint

from opal.score.collaborative_filtering import NeuMF
from opal.score.datamodule import ScoreDataModule
Expand Down Expand Up @@ -41,12 +41,11 @@ def train(yyyy_mm: str):
LearningRateMonitor(),
ModelCheckpoint(monitor='val_loss', save_top_k=1, mode='min')
],
devices=[3, ],
)

trainer.fit(net, datamodule=dm)


if __name__ == '__main__':
torch.set_float32_matmul_precision('high')
train("2023_01")
train("2023_04")