Exemplo n.º 1
0
    def on_epoch_end(self, epoch, logs):
        if self.every_epoch:
            met_dict = {'epoch': epoch}
            for key, value in logs.items():
                logs[key] = round(value, 4)
            met_dict.update(logs)
            log_metrics(met_dict, verbose=False)

        elif epoch == self.params['epochs'] - 1:
            met_dict = {}
            for key, value in logs.items():
                logs[key] = round(value, 4)
            met_dict.update(logs)
            log_metrics(met_dict, verbose=False)

            if self.notify_slack:
                result = {
                    'message':
                    'Training complete after ' + str(self.params['epochs']) +
                    ' epochs.',
                    'metrics':
                    met_dict
                }
                if self.hyperparams:
                    result['hyperparams'] = self.hyperparams
                notify(json.dumps(result, indent=2, cls=Encoder),
                       verbose=False,
                       safe=True)
Exemplo n.º 2
0
def test_notify(resp, expected_result, safe, capsys):
    with mock.patch("jovian.utils.slack.post_slack_message", return_value=resp):
        notify({"key": "value"}, safe=safe)

        captured = capsys.readouterr()
        if "errors" in resp:
            assert captured.err.strip() == expected_result
        else:
            assert captured.out.strip() == expected_result
Exemplo n.º 3
0
    def test_notify_safe_false_raises_api_error(self, mock_requests_post,
                                                mock_get_api_key):
        with fake_creds('.jovian-notify', 'credentials.json'):
            # setUp
            creds = {
                "WEBAPP_URL": "https://staging.jovian.ml/",
                "GUEST_KEY": "b6538d4dfde04fcf993463a828a9cec6",
                "API_URL": "https://api-staging.jovian.ai",
                "API_KEY": "fake_invalid_api_key",
                "ORG_ID": "staging"
            }
            write_creds(creds)

            data = {'key': 'value'}
            with self.assertRaises(ApiError):
                notify(data)
Exemplo n.º 4
0
def test_notify_log_error(mock_requests_post, capsys):
    with fake_creds('.jovian-notify', 'credentials.json'):
        # setUp
        creds = {
            "WEBAPP_URL": "https://staging.jovian.ml/",
            "GUEST_KEY": "b6538d4dfde04fcf993463a828a9cec6",
            "API_URL": "https://api-staging.jovian.ai",
            "API_KEY": "fake_expired_api_key",
            "ORG_ID": "staging"
        }
        write_creds(creds)

        data = {'key': 'value'}
        notify(data)

        captured = capsys.readouterr()

        assert captured.err.strip() == "[jovian] Error: The token has expired"
Exemplo n.º 5
0
def test_notify_safe_true(mock_requests_post, mock_get_api_key, capsys):
    with fake_creds('.jovian-notify', 'credentials.json'):
        # setUp
        creds = {
            "WEBAPP_URL": "https://staging.jovian.ml/",
            "GUEST_KEY": "b6538d4dfde04fcf993463a828a9cec6",
            "API_URL": "https://api-staging.jovian.ai",
            "API_KEY": "fake_invalid_api_key",
            "ORG_ID": "staging"
        }
        write_creds(creds)

        data = {'key': 'value'}
        notify(data, safe=True)

        captured = capsys.readouterr()

        assert captured.out.strip() == "[jovian] message_sent:False"