# Path: libml/utils.py
# _GPUS = None
# FLAGS = flags.FLAGS
#         _GPUS = tuple([x.name for x in local_device_protos if x.device_type == 'GPU'])
# class EasyDict(dict):
#     def __init__(self, *args, **kwargs):
# def get_config():
# def setup_main():
# def setup_tf():
# def smart_shape(x):
# def ilog2(x):
# def find_latest_checkpoint(dir, glob_term='model.ckpt-*.meta'):
# def get_latest_global_step(dir):
# def get_latest_global_step_in_subdir(dir):
# def getter_ema(ema, getter, name, *args, **kwargs):
# def model_vars(scope=None):
# def gpu(x):
# def get_available_gpus():
# def get_gpu():
# def average_gradients(tower_grads):
# def para_list(fn, *args):
# def para_mean(fn, *args):
# def para_cat(fn, *args):
# def interleave(x, batch):
# def de_interleave(x, batch):
# def combine_dicts(*args):
# 
# Path: libml/data.py
# DATA_DIR = None
# _DATA_CACHE = None
# SAMPLES_PER_CLASS = [1, 2, 3, 4, 5, 10, 25, 100, 400]
# FLAGS = flags.FLAGS
#     DATA_DIR = FLAGS.data_dir or os.environ['ML_DATA']
# DATASETS = functools.partial(create_datasets, augment_module.augment_function)
# PAIR_DATASETS = functools.partial(create_datasets, augment_module.pair_augment_function)
# MANY_DATASETS = functools.partial(create_datasets, augment_module.many_augment_function)
# QUAD_DATASETS = functools.partial(create_datasets, augment_module.quad_augment_function)
# def _data_setup():
# def record_parse_mnist(serialized_example, image_shape=None):
# def record_parse(serialized_example, image_shape=None):
# def compute_mean_std(data: tf.data.Dataset):
#         def iterator():
#     def __init__(self, data: tf.data.Dataset, augment_fn: AugmentPair, parse_fn=record_parse, image_shape=None):
#     def from_files(cls, filenames: list, augment_fn: AugmentPair, parse_fn=record_parse, image_shape=None):
#             def fetch_dataset(filename):
#     def empty_data(cls, image_shape, augment_fn: AugmentPair = None):
#         def _get_null_input(_):
#     def __getattr__(self, item):
#         def call_and_update(*args, **kwargs):
#     def parse(self):
#     def numpy_augment(self, *args, **kwargs):
#     def augment(self):
#     def memoize(self):
#         def tf_get(index, image_shape):
#             def get(index):
#     def __init__(self, name, train_labeled: DataSet, train_unlabeled: DataSet, test: DataSet, valid: DataSet,
#                  height=32, width=32, colors=3, nclass=10, mean=0, std=1, p_labeled=None, p_unlabeled=None):
#     def creator(cls, name, seed, label, valid, augment, parse_fn=record_parse, do_memoize=False,
#                 nclass=10, colors=3, height=32, width=32):
#         def create():
# def create_datasets(augment_fn):
# class DataSet:
# class DataSets:
# 
# Path: libml/utils.py
# class EasyDict(dict):
#     def __init__(self, *args, **kwargs):
#         super(EasyDict, self).__init__(*args, **kwargs)
#         self.__dict__ = self


import functools
import os
import numpy as np
import tensorflow as tf
from absl import app
from absl import flags
from libml import utils, data, models
from libml.utils import EasyDict
            tf.greater(tf.nn.softmax(logits_y), threshold),
            axis=-1,
            keepdims=True,
        )
        greater_than_thresh = tf.cast(greater_than_thresh, loss_pl.dtype)
        # Only enforce the loss when the model is confident
        loss_pl *= greater_than_thresh
        # Note that we also average over examples without confident outputs;
        # this is consistent with the realistic evaluation codebase
        loss_pl = tf.reduce_mean(loss_pl)

        loss = tf.nn.softmax_cross_entropy_with_logits_v2(labels=l, logits=logits_x)
        loss = tf.reduce_mean(loss)
        tf.summary.scalar('losses/xe', loss)
        tf.summary.scalar('losses/pl', loss_pl)

        # L2 regularization
        loss_wd = sum(tf.nn.l2_loss(v) for v in utils.model_vars('classify') if 'kernel' in v.name)
        tf.summary.scalar('losses/wd', loss_wd)

        ema = tf.train.ExponentialMovingAverage(decay=ema)
        ema_op = ema.apply(utils.model_vars())
        ema_getter = functools.partial(utils.getter_ema, ema)
        post_ops.append(ema_op)

        train_op = tf.train.MomentumOptimizer(lr, 0.9, use_nesterov=True).minimize(
            loss + loss_pl * warmup * consistency_weight + wd * loss_wd, colocate_gradients_with_ops=True)
        with tf.control_dependencies([train_op]):
            train_op = tf.group(*post_ops)


# Path: libml/utils.py
# _GPUS = None
# FLAGS = flags.FLAGS
#         _GPUS = tuple([x.name for x in local_device_protos if x.device_type == 'GPU'])
# class EasyDict(dict):
#     def __init__(self, *args, **kwargs):
# def get_config():
# def setup_main():
# def setup_tf():
# def smart_shape(x):
# def ilog2(x):
# def find_latest_checkpoint(dir, glob_term='model.ckpt-*.meta'):
# def get_latest_global_step(dir):
# def get_latest_global_step_in_subdir(dir):
# def getter_ema(ema, getter, name, *args, **kwargs):
# def model_vars(scope=None):
# def gpu(x):
# def get_available_gpus():
# def get_gpu():
# def average_gradients(tower_grads):
# def para_list(fn, *args):
# def para_mean(fn, *args):
# def para_cat(fn, *args):
# def interleave(x, batch):
# def de_interleave(x, batch):
# def combine_dicts(*args):
# 
# Path: libml/data.py
# DATA_DIR = None
# _DATA_CACHE = None
# SAMPLES_PER_CLASS = [1, 2, 3, 4, 5, 10, 25, 100, 400]
# FLAGS = flags.FLAGS
#     DATA_DIR = FLAGS.data_dir or os.environ['ML_DATA']
# DATASETS = functools.partial(create_datasets, augment_module.augment_function)
# PAIR_DATASETS = functools.partial(create_datasets, augment_module.pair_augment_function)
# MANY_DATASETS = functools.partial(create_datasets, augment_module.many_augment_function)
# QUAD_DATASETS = functools.partial(create_datasets, augment_module.quad_augment_function)
# def _data_setup():
# def record_parse_mnist(serialized_example, image_shape=None):
# def record_parse(serialized_example, image_shape=None):
# def compute_mean_std(data: tf.data.Dataset):
#         def iterator():
#     def __init__(self, data: tf.data.Dataset, augment_fn: AugmentPair, parse_fn=record_parse, image_shape=None):
#     def from_files(cls, filenames: list, augment_fn: AugmentPair, parse_fn=record_parse, image_shape=None):
#             def fetch_dataset(filename):
#     def empty_data(cls, image_shape, augment_fn: AugmentPair = None):
#         def _get_null_input(_):
#     def __getattr__(self, item):
#         def call_and_update(*args, **kwargs):
#     def parse(self):
#     def numpy_augment(self, *args, **kwargs):
#     def augment(self):
#     def memoize(self):
#         def tf_get(index, image_shape):
#             def get(index):
#     def __init__(self, name, train_labeled: DataSet, train_unlabeled: DataSet, test: DataSet, valid: DataSet,
#                  height=32, width=32, colors=3, nclass=10, mean=0, std=1, p_labeled=None, p_unlabeled=None):
#     def creator(cls, name, seed, label, valid, augment, parse_fn=record_parse, do_memoize=False,
#                 nclass=10, colors=3, height=32, width=32):
#         def create():
# def create_datasets(augment_fn):
# class DataSet:
# class DataSets:
# 
# Path: libml/utils.py
# class EasyDict(dict):
#     def __init__(self, *args, **kwargs):
#         super(EasyDict, self).__init__(*args, **kwargs)
#         self.__dict__ = self


# Path: pseudo_label.py
import functools
import os
import numpy as np
import tensorflow as tf
from absl import app
from absl import flags
from libml import utils, data, models
from libml.utils import EasyDict

            tf.greater(tf.nn.softmax(logits_y), threshold),
            axis=-1,
            keepdims=True,
        )
        greater_than_thresh = tf.cast(greater_than_thresh, loss_pl.dtype)
        # Only enforce the loss when the model is confident
        loss_pl *= greater_than_thresh
        # Note that we also average over examples without confident outputs;
        # this is consistent with the realistic evaluation codebase
        loss_pl = tf.reduce_mean(loss_pl)

        loss = tf.nn.softmax_cross_entropy_with_logits_v2(labels=l, logits=logits_x)
        loss = tf.reduce_mean(loss)
        tf.summary.scalar('losses/xe', loss)
        tf.summary.scalar('losses/pl', loss_pl)

        # L2 regularization
        loss_wd = sum(tf.nn.l2_loss(v) for v in utils.model_vars('classify') if 'kernel' in v.name)
        tf.summary.scalar('losses/wd', loss_wd)

        ema = tf.train.ExponentialMovingAverage(decay=ema)
        ema_op = ema.apply(utils.model_vars())
        ema_getter = functools.partial(utils.getter_ema, ema)
        post_ops.append(ema_op)

        train_op = tf.train.MomentumOptimizer(lr, 0.9, use_nesterov=True).minimize(
            loss + loss_pl * warmup * consistency_weight + wd * loss_wd, colocate_gradients_with_ops=True)
        with tf.control_dependencies([train_op]):
            train_op = tf.group(*post_ops)


        return EasyDict(