-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a structre and a first test run for my example for rnn, so I ad…
…d RNN Layer and a Model class, which holds a List of layers. There are things for an Layer Interface. will structure and check it more tomorrow
- Loading branch information
1 parent
228a09a
commit a434a1a
Showing
4 changed files
with
81 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
"""Layers for neural networks tasks.""" | ||
|
||
from ._rnn_layer import RNN_Layer | ||
from ._model import Model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pandas as pd | ||
import numpy as np | ||
import torch | ||
import torch.nn as nn | ||
from torch.utils.data import DataLoader | ||
from safeds.ml.nn import RNN_Layer | ||
from safeds.data.tabular.containers import Column, Table, TaggedTable, TimeSeries | ||
from safeds.exceptions import ColumnSizeError, DuplicateColumnNameError | ||
|
||
class Model(): | ||
def __init__(self, layers : list): | ||
self._model = PyTorchModel(layers) | ||
|
||
|
||
def from_layers(self, layers: list): | ||
pass | ||
|
||
#this is just a demo function | ||
def model_forward(self, data : DataLoader): | ||
for batch in iter(data): | ||
inputs, labels = batch | ||
inputs = inputs.to(torch.float32) | ||
self._model(inputs) | ||
|
||
|
||
def train(self,x): | ||
pass | ||
|
||
class PyTorchModel(nn.Module): | ||
def __init__(self, LayerListe :list[RNN_Layer]): | ||
super(PyTorchModel, self).__init__() | ||
self.layerliste = [] | ||
for layer in LayerListe: | ||
self.layerliste.append(layer._create_pytorch_layer()) | ||
|
||
def forward(self, x): | ||
out = x | ||
for layer in self.layerliste: | ||
out = layer(out) | ||
return out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pandas as pd | ||
import numpy as np | ||
import torch | ||
import torch.nn as nn | ||
from torch.utils.data import DataLoader | ||
from safeds.data.tabular.containers import Column, Table, TaggedTable, TimeSeries | ||
from safeds.exceptions import ColumnSizeError, DuplicateColumnNameError | ||
|
||
|
||
class RNN_Layer(): | ||
def __init__(self, input_dim, output_dim)-> None: | ||
self._input_dim = input_dim | ||
self._output_dim = output_dim | ||
|
||
|
||
def _create_pytorch_layer(self): | ||
return LSTMLayer(self._input_dim, self._output_dim) | ||
|
||
|
||
|
||
#definiere LSTM Layer in PyTorch | ||
class LSTMLayer(nn.Module): | ||
def __init__(self, input_dim, output_dim): | ||
super(LSTMLayer, self).__init__() | ||
self.lstm = nn.LSTM(input_dim, output_dim, batch_first = True) | ||
|
||
def forward(self, x): | ||
lstm_out, _ = self.lstm(x) | ||
return lstm_out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters