# Path: selfsup/multi/methods/base.py
# class Method:
#     def __init__(self, name, batch_size):
#         self.name = name
#         self.batch_size = batch_size
# 
#     def input_size(self):
#         return 0
# 
#     def batch_loader(self):
#         raise NotImplemented("Abstract base class")
# 
#     def build_network(network, y, phase_test):
#         raise NotImplemented("Abstract base class")
# 
#     @property
#     def basenet_settings():
#         return {}
# 
#     def make_path(self, name, ext, iteration):
#         return f'img/{self.name}_{name}_{iteration}.png'


import selfsup
import tensorflow as tf
import os
from .base import Method
from collections import OrderedDict
    def basenet_settings(self):
        return {'convolutional': False}

    def batch(self):
        x, extra = self._loader.batch()
        assert 'saliency' in extra
        return x, extra

    def build_network(self, network, extra, phase_test, global_step):
        info = selfsup.info.create(scale_summary=True)

        z = network['activations']['top']

        logits = self.basenet.decoder(z, channels=self._classes, multiple=4)
        y = tf.image.resize_bilinear(extra['saliency'], logits.get_shape().as_list()[1:3])

        labels = tf.to_int32(tf.floor(y[..., 0] * self._classes * 0.99999))

        with tf.variable_scope('primary_loss'):
            loss_each = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=labels, logits=logits)
            primary_loss = tf.reduce_mean(loss_each)

        #with tf.name_scope('weight_decay'):
            #wd = 0.0005
            #l2_loss = tf.nn.l2_loss(fc8W)
            #weight_decay = wd * l2_loss

        with tf.name_scope('loss'):
            loss = primary_loss


# Path: selfsup/multi/methods/base.py
# class Method:
#     def __init__(self, name, batch_size):
#         self.name = name
#         self.batch_size = batch_size
# 
#     def input_size(self):
#         return 0
# 
#     def batch_loader(self):
#         raise NotImplemented("Abstract base class")
# 
#     def build_network(network, y, phase_test):
#         raise NotImplemented("Abstract base class")
# 
#     @property
#     def basenet_settings():
#         return {}
# 
#     def make_path(self, name, ext, iteration):
#         return f'img/{self.name}_{name}_{iteration}.png'


# Path: selfsup/multi/methods/video_saliency.py
import selfsup
import tensorflow as tf
import os
from .base import Method
from collections import OrderedDict

    def basenet_settings(self):
        return {'convolutional': False}

    def batch(self):
        x, extra = self._loader.batch()
        assert 'saliency' in extra
        return x, extra

    def build_network(self, network, extra, phase_test, global_step):
        info = selfsup.info.create(scale_summary=True)

        z = network['activations']['top']

        logits = self.basenet.decoder(z, channels=self._classes, multiple=4)
        y = tf.image.resize_bilinear(extra['saliency'], logits.get_shape().as_list()[1:3])

        labels = tf.to_int32(tf.floor(y[..., 0] * self._classes * 0.99999))

        with tf.variable_scope('primary_loss'):
            loss_each = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=labels, logits=logits)
            primary_loss = tf.reduce_mean(loss_each)

        #with tf.name_scope('weight_decay'):
            #wd = 0.0005
            #l2_loss = tf.nn.l2_loss(fc8W)
            #weight_decay = wd * l2_loss

        with tf.name_scope('loss'):
            loss = primary_loss


        variables = info['vars']