Skip to content
Snippets Groups Projects
Select Git revision
  • ae2d5c0960527ad0da2d10ff47e1e9c2f1610280
  • bing_issues#190_tf2
  • bing_tf2_convert
  • bing_issue#189_train_modular
  • simon_#172_integrate_weatherbench
  • develop
  • bing_issue#188_restructure_ambs
  • yan_issue#100_extract_prcp_data
  • bing_issue#170_data_preprocess_training_tf1
  • Gong2022_temperature_forecasts
  • bing_issue#186_clean_GMD1_tag
  • yan_issue#179_integrate_GZAWS_data_onfly
  • bing_issue#178_runscript_bug_postprocess
  • michael_issue#187_bugfix_setup_runscript_template
  • bing_issue#180_bugs_postprpocess_meta_postprocess
  • yan_issue#177_repo_for_CLGAN_gmd
  • bing_issue#176_integrate_weather_bench
  • michael_issue#181_eval_era5_forecasts
  • michael_issue#182_eval_subdomain
  • michael_issue#119_warmup_Horovod
  • bing_issue#160_test_zam347
  • ambs_v1
  • ambs_gmd_nowcasting_v1.0
  • GMD1
  • modular_booster_20210203
  • new_structure_20201004_v1.0
  • old_structure_20200930
27 results

plot_ambs_forecast.py

Blame
  • test_training_monitoring.py 3.28 KiB
    import keras
    import pytest
    import os
    
    from src.plotting.training_monitoring import PlotModelLearningRate, PlotModelHistory
    from src.helpers import LearningRateDecay
    
    
    @pytest.fixture
    def path():
        p = os.path.join(os.path.dirname(__file__), "TestExperiment")
        if not os.path.exists(p):
            os.makedirs(p)
        return p
    
    
    class TestPlotModelHistory:
    
        @pytest.fixture
        def history(self):
            hist = keras.callbacks.History()
            hist.epoch = [0, 1]
            hist.history = {'val_loss': [0.5586272982587484, 0.45712877659670287],
                         'val_mean_squared_error': [0.5586272982587484, 0.45712877659670287],
                         'val_mean_absolute_error': [0.595368885413389, 0.530547587585537],
                         'loss': [0.6795708956961347, 0.45963566494176616],
                         'mean_squared_error': [0.6795708956961347, 0.45963566494176616],
                         'mean_absolute_error': [0.6523177288928538, 0.5363963260296364]}
            return hist
    
        @pytest.fixture
        def history_var(self):
            hist = keras.callbacks.History()
            hist.epoch = [0, 1]
            hist.history = {'val_loss': [0.5586272982587484, 0.45712877659670287],
                         'test_loss': [0.595368885413389, 0.530547587585537],
                         'loss': [0.6795708956961347, 0.45963566494176616],
                         'mean_squared_error': [0.6795708956961347, 0.45963566494176616],
                         'mean_absolute_error': [0.6523177288928538, 0.5363963260296364]}
            return hist
    
        @pytest.fixture
        def no_init(self):
            return object.__new__(PlotModelHistory)
    
        def test_plot_from_hist_obj(self, history, path):
            assert "hist_obj.pdf" not in os.listdir(path)
            PlotModelHistory(os.path.join(path, "hist_obj.pdf"), history)
            assert "hist_obj.pdf" in os.listdir(path)
    
        def test_plot_from_hist_dict(self, history, path):
            assert "hist_dict.pdf" not in os.listdir(path)
            PlotModelHistory(os.path.join(path, "hist_dict.pdf"), history.history)
            assert "hist_dict.pdf" in os.listdir(path)
    
        def test_plot_additional_loss(self, history_var, path):
            assert "hist_additional.pdf" not in os.listdir(path)
            PlotModelHistory(os.path.join(path, "hist_additional.pdf"), history_var)
            assert "hist_additional.pdf" in os.listdir(path)
    
        def test_filter_list(self, no_init):
            res = no_init._filter_columns({'loss': None, 'another_loss': None, 'val_loss': None, 'wrong': None})
            assert res == ['another_loss']
    
    
    class TestPlotModelLearningRate:
    
        @pytest.fixture
        def learning_rate(self):
            lr_obj = LearningRateDecay()
            lr_obj.lr = {"lr": [0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.0094, 0.0094, 0.0094, 0.0094,
                                0.0094, 0.0094, 0.0094, 0.0094, 0.0094, 0.0094]}
            return lr_obj
    
        def test_plot_from_lr_obj(self, learning_rate, path):
            assert "lr_obj.pdf" not in os.listdir(path)
            PlotModelLearningRate(os.path.join(path, "lr_obj.pdf"), learning_rate)
            assert "lr_obj.pdf" in os.listdir(path)
    
        def test_plot_from_lr_dict(self, learning_rate, path):
            assert "lr_dict.pdf" not in os.listdir(path)
            PlotModelLearningRate(os.path.join(path, "lr_dict.pdf"), learning_rate.lr)
            assert "lr_dict.pdf" in os.listdir(path)