from tsai.basics import *
from tsai.data.all import *
from tsai.models.utils import *
from tsai.models.InceptionTimePlus import *
from tsai.models.TabModel import *
MultiInputNet
This is an implementation created by Ignacio Oguiza (oguiza@timeseriesAI.co).
It can be used to combine different types of deep learning models into a single one that will accept multiple inputs from a MixedDataLoaders.
MultiInputNet
MultiInputNet (*models, c_out=None, reshape_fn=None, multi_output=False, custom_head=None, device=None, **kwargs)
Same as nn.Module
, but no need for subclasses to call super().__init__
= 'NATOPS'
dsid = get_UCR_data(dsid, split_data=False)
X, y, splits = get_ts_features(X, y) ts_features_df
Feature Extraction: 100%|███████████████████████████████████████████| 40/40 [00:07<00:00, 5.23it/s]
# raw ts
= [None, [TSCategorize()]]
tfms = TSStandardize()
batch_tfms = get_ts_dls(X, y, splits=splits, tfms=tfms, batch_tfms=batch_tfms)
ts_dls = build_ts_model(InceptionTimePlus, dls=ts_dls)
ts_model
# ts features
= None
cat_names = ts_features_df.columns[:-2]
cont_names = 'target'
y_names = get_tabular_dls(ts_features_df, cat_names=cat_names, cont_names=cont_names, y_names=y_names, splits=splits)
tab_dls = build_tabular_model(TabModel, dls=tab_dls)
tab_model
# mixed
= get_mixed_dls(ts_dls, tab_dls)
mixed_dls = MultiInputNet(ts_model, tab_model)
MultiModalNet = Learner(mixed_dls, MultiModalNet, metrics=[accuracy, RocAuc()])
learn 1, 1e-3) learn.fit_one_cycle(
epoch | train_loss | valid_loss | accuracy | roc_auc_score | time |
---|---|---|---|---|---|
0 | 1.780674 | 1.571718 | 0.477778 | 0.857444 | 00:05 |
= mixed_dls.one_batch()
(ts, (cat, cont)),yb learn.model((ts, (cat, cont))).shape
torch.Size([64, 6])
tab_dls.c, ts_dls.c, ts_dls.cat
(6, 6, True)
learn.loss_func
FlattenedLoss of CrossEntropyLoss()