import tensorflow as tf

        if self.use_bias:
            self.bias = self.add_weight(name="bias", shape=(np.prod(self.out_modes),), initializer=self.bias_initializer, trainable=True)

        super(TTLayerDense, self).build(input_shape)

    def call(self, input_):
        dim = self.order

        out = tf.reshape(input_, [-1, np.prod(self.inp_modes)])
        self.image_max_size = max(self.image_max_size, np.prod(self.inp_modes))
        out = tf.transpose(out, [1, 0])
        for i in range(dim):
            out = tf.reshape(out, [self.mat_ranks[i] * self.inp_modes[i], -1])
            out = tf.matmul(self.mat_cores[i], out)
            out = tf.reshape(out, [self.out_modes[i], -1])
            out = tf.transpose(out, [1, 0])

        out = tf.reshape(out, [-1, np.prod(self.out_modes)])
        # self.image_max_size = max(self.image_max_size, np.prod([val.value for val in out.get_shape()[1:]]))
        if self.use_bias:
            out = tf.add(out, self.bias, name='out')

        if self.activation is not None:
            out = self.activation(out)
        return out

    def compute_output_shape(self, input_shape):
        return (input_shape[0], np.prod(self.out_modes))
