-
Notifications
You must be signed in to change notification settings - Fork 17
/
model.py
executable file
·41 lines (30 loc) · 1.04 KB
/
model.py
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
35
36
37
38
39
40
41
# !/usr/bin/env python3
# -*- coding: utf-8 -*-
import abc
import numpy as np
import tensorflow as tf # install tf 2.0 or later
class BaseModel(tf.keras.Model, abc.ABC):
def __init__(self, name, *args, **kwargs):
"""
Neural network base class. Subclass BaseModel to define how (and what)
a concrete Model should learn based on input data.
:param name:
str, model name
"""
super(BaseModel, self).__init__(name)
@abc.abstractmethod
def build(self, input_shape):
"""
Set as instance attributes all layers to be used in call method.
:param input_shape:
tuple, input shape where first dimension is batch_size
"""
raise NotImplementedError("To be implemented in subclass.")
@abc.abstractmethod
def call(self, x):
"""
Implement a single forward pass using the defined layers.
:param x:
tf.Tensor, batch
"""
raise NotImplementedError("To be implemented in subclass.")