BaseNetTorch.py 853 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import torch
from torch import nn
import numpy as np
from config import config 
import logging 

class BaseNet(nn.Module):
    def __init__(self, epochs=50, verbose=True, model_number=0):
        """
        BaseNet class for ConvNet and EEGnet to inherit common functionality 
        """
        super().__init__()
        self.epochs = epochs
        self.verbose = verbose
        self.model_number = model_number

        if self.verbose:
            print(self) # works for torch 

        # Get cpu or gpu device for training.
        self.device = "cuda" if torch.cuda.is_available() else "cpu"
        logging.info("Using {} device".format(self.device))

    # abstract method 
    def forward(self, x):
        pass

    # abstract method
    def _split_model(self):
        pass

    # abstract method
    def _build_model(self):
        pass