Commit 47e75cfc authored by Niklas Bohn's avatar Niklas Bohn
Browse files

Merge branch 'bugfix/Issue#85' into 'master'


See merge request !86
parents 8a5be05b 4a3d5022
......@@ -8,6 +8,7 @@ History
New features:
* 'make lint' now directly prints errors instead of only logging them to logfiles.
* Automatic retraining of S2 novelty detector in case pretrained scikit-learn random forest model is out of date.
* Pinned gdal to version<=3.1.2 to avoid import error.
......@@ -7,6 +7,8 @@ import logging
import numpy as np
import json
import pickle
import gdown
import h5py
class CloudMask(S2cB):
......@@ -53,9 +55,41 @@ class CloudMask(S2cB):
elif file_ext == "pkl":
with open(novelty_detector, "rb") as fl:
nvc = pickle.load(fl)
ncv_clf = pickle.load(fl)
except ModuleNotFoundError:
# download training data base for novelty detector from google drive"Novelty detector has to be updated with a newer version of scikit-learn.")"Download training data base from google drive.")
url = ""
db_nv_fn = "noclear_novelty_detector_channel2_difference9_0_index10_1_channel12_index1_8.h5"
db_nv_path = novelty_detector.split("noclear")[0] + db_nv_fn, db_nv_path, quiet=False)
# retrain novelty detector"Retrain novelty detector with updated version of scikit-learn.")
from sklearn.ensemble import RandomForestClassifier
with h5py.File(db_nv_path, "r") as h5f:
nv = RandomForestClassifier(**dict(h5f["xx"].attrs.items()))["xx"], y=h5f["yy"])
bf = json.loads(h5f.attrs["clf"])
with open(novelty_detector, "wb") as fl:
pickle.dump(nv, fl)
pickle.dump({"id": [tuple(ids) for ids in bf["id"]], "fk": [str(ids) for ids in bf["fk"]]},
# reload novelty detector
with open(novelty_detector, "rb") as fl:
nvc = pickle.load(fl)
ncv_clf = pickle.load(fl)
raise ValueError("Novelty detector file type not implemented")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment