google-research
63 строки · 2.2 Кб
1# coding=utf-8
2# Copyright 2024 The Google Research Authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16"""Package for dealing with different models."""
17
18from typing import Any, Dict19
20from models import base21from models import lstm_seq2seq22from models import lstm_seq2seq_saf23from models import tft24from models import tft_saf25import tensorflow as tf26
27
28def get_model_type(model_type, chosen_hparams,29loss_form):30"""Return a forecast model based on the type."""31if loss_form == "MAE":32training_loss_object = tf.keras.losses.MeanAbsoluteError(33name="training_loss")34self_supervised_loss_object = tf.keras.losses.MeanAbsoluteError(35name="self_supervised_loss")36elif loss_form == "MSE":37training_loss_object = tf.keras.losses.MeanSquaredError(38name="training_loss")39self_supervised_loss_object = tf.keras.losses.MeanSquaredError(40name="self_supervised_loss")41else:42raise Exception("The loss type is not supported")43
44if model_type == "lstm_seq2seq":45model = lstm_seq2seq.ForecastModel(46loss_object=training_loss_object, hparams=chosen_hparams)47elif model_type == "lstm_seq2seq_saf":48model = lstm_seq2seq_saf.ForecastModel(49loss_object=training_loss_object,50self_supervised_loss_object=self_supervised_loss_object,51hparams=chosen_hparams)52elif model_type == "tft":53model = tft.ForecastModel(54loss_object=training_loss_object, hparams=chosen_hparams)55elif model_type == "tft_saf":56model = tft_saf.ForecastModel(57loss_object=training_loss_object,58self_supervised_loss_object=self_supervised_loss_object,59hparams=chosen_hparams)60else:61raise Exception("The chosen model is not supported")62
63return model64