# Path: meta_dataset/learners/base_test.py
# IMAGE_HEIGHT = IMAGE_WIDTH = 84
# IMAGE_SHAPE = (IMAGE_HEIGHT, IMAGE_WIDTH, 3)
# SUPPORT_SIZE, QUERY_SIZE = 5, 15
# NUM_CLASSES = 5
# VALID_ABSTRACT_LEARNER_INIT_ARGS = {
#     'is_training': True,
#     'logit_dim': NUM_CLASSES,
#     'transductive_batch_norm': True,
#     'backprop_through_moments': True,
#     'input_shape': IMAGE_SHAPE,
# }
# VALID_LEARNER_INIT_ARGS = {
#     **VALID_ABSTRACT_LEARNER_INIT_ARGS, 'embedding_fn':
#         functools.partial(
#             functional_backbones.four_layer_convnet, weight_decay=0.01)
# }
# class MockEmbedding(reparameterizable_backbones.ConvNet):
# class MockEpisode(
#     collections.namedtuple(
#         'MockEpisode', 'support_images, query_images, '
#         'support_labels, query_labels')):
# class MockBatch(collections.namedtuple('MockBatch', 'images, labels')):
# class TestLearner(tf.test.TestCase):
# class TestBatchLearner(TestLearner):
# class TestEpisodicLearner(TestLearner):
#   def __init__(self, keep_spatial_dims=False):
#   def way(self):
#   def onehot_support_labels(self):
#   def onehot_query_labels(self):
#   def labels(self):
#   def onehot_labels(self):
#   def way(self):
#   def onehot_labels(self):
#   def learner_cls(self):
#   def learner_kwargs(self):
#   def set_up_learner(self):
#   def testForwardPass(self):
#   def testComputeLoss(self):
#   def testComputeAccuracy(self):
#   def testLearnerInitRandomAccuracy(self):
#   def testLearnerImprovement(self):
#   def testLearnerConvergence(self):
#   def random_data(self):
#   def random_data(self):
# 
# Path: meta_dataset/learners/metric_learners.py
# def _compute_prototypes(embeddings, labels):
# def compute_prototypes(embeddings, labels):
#   def __init__(self, **kwargs):
#   def forward_pass(self, data):
#   def compute_logits_for_episode(self, local_support_embeddings,
#                                  local_query_embeddings, data):
#   def compute_logits(self, support_embeddings, query_embeddings,
#                      onehot_support_labels):
#   def compute_logits(self,
#                      support_embeddings,
#                      query_embeddings,
#                      onehot_support_labels,
#                      cosine_distance=False):
#   def __init__(self,
#                query_dim=128,
#                val_dim=128,
#                rematerialize=True,
#                tformer_weight_decay=0.0,
#                **kwargs):
#   def compute_loss(self, onehot_labels, predictions):
#   def compute_logits_for_episode(self, support_embeddings, query_embeddings,
#                                  data):
#   def _get_dist_rematerialize(self, query_queries, query_values, support_keys,
#                               support_values, labels):
#     def fwd_fn(query_queries_fwd, query_values_fwd, support_keys_fwd,
#                support_values_fwd, labels_fwd):
#       def loop_body(idx, dist):
#     def grad_fn(dy):
#       def loop_body(idx, qq_grad, qv_grad, sk_grad, sv_grad):
#   def _get_dist(self, query_queries, query_values, support_keys, support_values,
#                 labels):
#   def get_support_set_softmax(self, logits, class_ids):
#   def _attend(self, query, key, value, key_class_id):
#   def __init__(self, exact_cosine_distance, **kwargs):
#   def compute_logits(self, support_embeddings, query_embeddings,
#                      onehot_support_labels):
#   def compute_logits(self, support_embeddings, query_embeddings,
#                      onehot_support_labels):
#   def compute_loss(self, onehot_labels, predictions):
#   def __init__(self, num_sets, *args, **kwargs):
#   def forward_pass(self, data, source, *args, **kwargs):
# class MetricLearner(learner_base.EpisodicLearner):
# class PrototypicalNetworkLearner(MetricLearner):
# class CrossTransformerLearner(MetricLearner):
# class MatchingNetworkLearner(MetricLearner):
# class RelationNetworkLearner(MetricLearner):
# class DatasetConditionalPrototypicalNetworkLearner(PrototypicalNetworkLearner):


import gin
import tensorflow.compat.v1 as tf
from meta_dataset.learners import base_test
from meta_dataset.learners import metric_learners
# Copyright 2022 The Meta-Dataset Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Lint as: python3
"""Tests for `meta_dataset.learners.metric_learners`."""



tf.disable_eager_execution()

metric_learner_kwargs = {
    **base_test.VALID_LEARNER_INIT_ARGS,
}

gin.bind_parameter('relationnet_convnet.weight_decay', 0.01)
gin.bind_parameter('relation_module.weight_decay', 0.01)


class CosineMatchingNetworkLearnerTest(base_test.TestEpisodicLearner):

# Path: meta_dataset/learners/base_test.py
# IMAGE_HEIGHT = IMAGE_WIDTH = 84
# IMAGE_SHAPE = (IMAGE_HEIGHT, IMAGE_WIDTH, 3)
# SUPPORT_SIZE, QUERY_SIZE = 5, 15
# NUM_CLASSES = 5
# VALID_ABSTRACT_LEARNER_INIT_ARGS = {
#     'is_training': True,
#     'logit_dim': NUM_CLASSES,
#     'transductive_batch_norm': True,
#     'backprop_through_moments': True,
#     'input_shape': IMAGE_SHAPE,
# }
# VALID_LEARNER_INIT_ARGS = {
#     **VALID_ABSTRACT_LEARNER_INIT_ARGS, 'embedding_fn':
#         functools.partial(
#             functional_backbones.four_layer_convnet, weight_decay=0.01)
# }
# class MockEmbedding(reparameterizable_backbones.ConvNet):
# class MockEpisode(
#     collections.namedtuple(
#         'MockEpisode', 'support_images, query_images, '
#         'support_labels, query_labels')):
# class MockBatch(collections.namedtuple('MockBatch', 'images, labels')):
# class TestLearner(tf.test.TestCase):
# class TestBatchLearner(TestLearner):
# class TestEpisodicLearner(TestLearner):
#   def __init__(self, keep_spatial_dims=False):
#   def way(self):
#   def onehot_support_labels(self):
#   def onehot_query_labels(self):
#   def labels(self):
#   def onehot_labels(self):
#   def way(self):
#   def onehot_labels(self):
#   def learner_cls(self):
#   def learner_kwargs(self):
#   def set_up_learner(self):
#   def testForwardPass(self):
#   def testComputeLoss(self):
#   def testComputeAccuracy(self):
#   def testLearnerInitRandomAccuracy(self):
#   def testLearnerImprovement(self):
#   def testLearnerConvergence(self):
#   def random_data(self):
#   def random_data(self):
# 
# Path: meta_dataset/learners/metric_learners.py
# def _compute_prototypes(embeddings, labels):
# def compute_prototypes(embeddings, labels):
#   def __init__(self, **kwargs):
#   def forward_pass(self, data):
#   def compute_logits_for_episode(self, local_support_embeddings,
#                                  local_query_embeddings, data):
#   def compute_logits(self, support_embeddings, query_embeddings,
#                      onehot_support_labels):
#   def compute_logits(self,
#                      support_embeddings,
#                      query_embeddings,
#                      onehot_support_labels,
#                      cosine_distance=False):
#   def __init__(self,
#                query_dim=128,
#                val_dim=128,
#                rematerialize=True,
#                tformer_weight_decay=0.0,
#                **kwargs):
#   def compute_loss(self, onehot_labels, predictions):
#   def compute_logits_for_episode(self, support_embeddings, query_embeddings,
#                                  data):
#   def _get_dist_rematerialize(self, query_queries, query_values, support_keys,
#                               support_values, labels):
#     def fwd_fn(query_queries_fwd, query_values_fwd, support_keys_fwd,
#                support_values_fwd, labels_fwd):
#       def loop_body(idx, dist):
#     def grad_fn(dy):
#       def loop_body(idx, qq_grad, qv_grad, sk_grad, sv_grad):
#   def _get_dist(self, query_queries, query_values, support_keys, support_values,
#                 labels):
#   def get_support_set_softmax(self, logits, class_ids):
#   def _attend(self, query, key, value, key_class_id):
#   def __init__(self, exact_cosine_distance, **kwargs):
#   def compute_logits(self, support_embeddings, query_embeddings,
#                      onehot_support_labels):
#   def compute_logits(self, support_embeddings, query_embeddings,
#                      onehot_support_labels):
#   def compute_loss(self, onehot_labels, predictions):
#   def __init__(self, num_sets, *args, **kwargs):
#   def forward_pass(self, data, source, *args, **kwargs):
# class MetricLearner(learner_base.EpisodicLearner):
# class PrototypicalNetworkLearner(MetricLearner):
# class CrossTransformerLearner(MetricLearner):
# class MatchingNetworkLearner(MetricLearner):
# class RelationNetworkLearner(MetricLearner):
# class DatasetConditionalPrototypicalNetworkLearner(PrototypicalNetworkLearner):


# Path: meta_dataset/learners/metric_learners_test.py
import gin
import tensorflow.compat.v1 as tf
from meta_dataset.learners import base_test
from meta_dataset.learners import metric_learners

# Copyright 2022 The Meta-Dataset Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Lint as: python3
"""Tests for `meta_dataset.learners.metric_learners`."""



tf.disable_eager_execution()

metric_learner_kwargs = {
    **base_test.VALID_LEARNER_INIT_ARGS,
}

gin.bind_parameter('relationnet_convnet.weight_decay', 0.01)
gin.bind_parameter('relation_module.weight_decay', 0.01)


class CosineMatchingNetworkLearnerTest(base_test.TestEpisodicLearner):

  learner_cls = metric_learners.MatchingNetworkLearner