Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import numpy as np
from torchmeta.utils.data import Task, MetaDataset
from torchmeta.toy.sinusoid import SinusoidTask
class SinusoidAndLine(MetaDataset):
"""
Simple multimodal regression task, based on sinusoids and lines, as
introduced in [1].
Parameters
----------
num_samples_per_task : int
Number of examples per task.
num_tasks : int (default: 1,000,000)
Overall number of tasks to sample.
noise_std : float, optional
Amount of noise to include in the targets for each task. If `None`, then
nos noise is included, and the target is either a sine function, or a
linear function of the input.
def apply_wrapper(wrapper, task_or_dataset=None):
if task_or_dataset is None:
return wrapper
from torchmeta.utils.data import MetaDataset
if isinstance(task_or_dataset, Task):
return wrapper(task_or_dataset)
elif isinstance(task_or_dataset, MetaDataset):
if task_or_dataset.dataset_transform is None:
dataset_transform = wrapper
else:
dataset_transform = Compose([
task_or_dataset.dataset_transform, wrapper])
task_or_dataset.dataset_transform = dataset_transform
return task_or_dataset
else:
raise NotImplementedError()
import numpy as np
from torchmeta.utils.data import Task, MetaDataset
class Harmonic(MetaDataset):
"""
Simple regression task, based on the sum of two sine waves, as introduced
in [1].
Parameters
----------
num_samples_per_task : int
Number of examples per task.
num_tasks : int (default: 5,000)
Overall number of tasks to sample.
noise_std : float, optional
Amount of noise to include in the targets for each task. If `None`, then
nos noise is included, and the target is the sum of 2 sine functions of
the input.
import numpy as np
from torchmeta.utils.data import Task, MetaDataset
class Sinusoid(MetaDataset):
"""
Simple regression task, based on sinusoids, as introduced in [1].
Parameters
----------
num_samples_per_task : int
Number of examples per task.
num_tasks : int (default: 1,000,000)
Overall number of tasks to sample.
noise_std : float, optional
Amount of noise to include in the targets for each task. If `None`, then
nos noise is included, and the target is a sine function of the input.
transform : callable, optional
import os
import json
import h5py
import numpy as np
import torch
import copy
from torchmeta.utils.data import Task, MetaDataset
from torchmeta.datasets.utils import get_asset
class TCGA(MetaDataset):
"""
The TCGA dataset [1]. A dataset of classification tasks over the values of
an attribute, based on the gene expression data from patients diagnosed with
specific types of cancer. This dataset is based on data from the Cancer
Genome Atlas Program from the National Cancer Institute.
Parameters
----------
root : string
Root directory where the dataset folder `omniglot` exists.
meta_train : bool (default: `False`)
Use the meta-train split of the dataset. If set to `True`, then the
arguments `meta_val` and `meta_test` must be set to `False`. Exactly one
of these three arguments must be set to `True`.