import tensorflow as tf
import numpy as np


class AbstractModel:

    def __init__(self):
        self.graph = tf.Graph()
        self.sess = tf.Session(graph=self.graph)
        with self.graph.as_default():
            with self.sess.as_default():
                self.model = self.build()
        self.weights_path = None
        self.best_weights_path = None

        self.x_train_path = ""
        self.y_train_path = ""
        self.x_test_path = ""
        self.y_test_path = ""

    @property
    def x_train(self):
        print("加载训练集x。。。")
        return np.load(self.x_train_path)

    @property
    def y_train(self):
        print("加载训练集y。。。")
        return np.load(self.y_train_path)

    @property
    def x_test(self):
        print("加载测试集x。。。")
        return np.load(self.x_test_path)

    @property
    def y_test(self):
        print("加载测试集y。。")
        return np.load(self.y_test_path)

    def build(self):
        """创建"""

    def train(self, batch_size, epochs):
        """训练 """

    def load(self, path=None):
        """加载参数"""
        with self.graph.as_default():
            with self.sess.as_default():
                path = path or self.best_weights_path
                self.model.load_weights(path)

    def predict(self, inputs):
        """预测"""
        with self.graph.as_default():
            with self.sess.as_default():
                inputs = self.pre_process(inputs)
                outputs = self.inference(inputs)
                outputs = self.post_process(outputs)
                return outputs

    def test(self):
        """测试"""

    def inference(self, x):
        """推理"""
        return x

    def pre_process(self, x):
        """预处理"""
        return x

    def post_process(self, x):
        """后处理"""
        return x
