partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | get_dataset_feature_statistics | Calculate statistics for the specified split. | tensorflow_datasets/core/dataset_info.py | def get_dataset_feature_statistics(builder, split):
"""Calculate statistics for the specified split."""
statistics = statistics_pb2.DatasetFeatureStatistics()
# Make this to the best of our abilities.
schema = schema_pb2.Schema()
dataset = builder.as_dataset(split=split)
# Just computing the number of ex... | def get_dataset_feature_statistics(builder, split):
"""Calculate statistics for the specified split."""
statistics = statistics_pb2.DatasetFeatureStatistics()
# Make this to the best of our abilities.
schema = schema_pb2.Schema()
dataset = builder.as_dataset(split=split)
# Just computing the number of ex... | [
"Calculate",
"statistics",
"for",
"the",
"specified",
"split",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/dataset_info.py#L443-L556 | [
"def",
"get_dataset_feature_statistics",
"(",
"builder",
",",
"split",
")",
":",
"statistics",
"=",
"statistics_pb2",
".",
"DatasetFeatureStatistics",
"(",
")",
"# Make this to the best of our abilities.",
"schema",
"=",
"schema_pb2",
".",
"Schema",
"(",
")",
"dataset",... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | read_from_json | Read JSON-formatted proto into DatasetInfo proto. | tensorflow_datasets/core/dataset_info.py | def read_from_json(json_filename):
"""Read JSON-formatted proto into DatasetInfo proto."""
with tf.io.gfile.GFile(json_filename) as f:
dataset_info_json_str = f.read()
# Parse it back into a proto.
parsed_proto = json_format.Parse(dataset_info_json_str,
dataset_info_pb2.Da... | def read_from_json(json_filename):
"""Read JSON-formatted proto into DatasetInfo proto."""
with tf.io.gfile.GFile(json_filename) as f:
dataset_info_json_str = f.read()
# Parse it back into a proto.
parsed_proto = json_format.Parse(dataset_info_json_str,
dataset_info_pb2.Da... | [
"Read",
"JSON",
"-",
"formatted",
"proto",
"into",
"DatasetInfo",
"proto",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/dataset_info.py#L559-L566 | [
"def",
"read_from_json",
"(",
"json_filename",
")",
":",
"with",
"tf",
".",
"io",
".",
"gfile",
".",
"GFile",
"(",
"json_filename",
")",
"as",
"f",
":",
"dataset_info_json_str",
"=",
"f",
".",
"read",
"(",
")",
"# Parse it back into a proto.",
"parsed_proto",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | DatasetInfo.full_name | Full canonical name: (<dataset_name>/<config_name>/<version>). | tensorflow_datasets/core/dataset_info.py | def full_name(self):
"""Full canonical name: (<dataset_name>/<config_name>/<version>)."""
names = [self._builder.name]
if self._builder.builder_config:
names.append(self._builder.builder_config.name)
names.append(str(self.version))
return posixpath.join(*names) | def full_name(self):
"""Full canonical name: (<dataset_name>/<config_name>/<version>)."""
names = [self._builder.name]
if self._builder.builder_config:
names.append(self._builder.builder_config.name)
names.append(str(self.version))
return posixpath.join(*names) | [
"Full",
"canonical",
"name",
":",
"(",
"<dataset_name",
">",
"/",
"<config_name",
">",
"/",
"<version",
">",
")",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/dataset_info.py#L150-L156 | [
"def",
"full_name",
"(",
"self",
")",
":",
"names",
"=",
"[",
"self",
".",
"_builder",
".",
"name",
"]",
"if",
"self",
".",
"_builder",
".",
"builder_config",
":",
"names",
".",
"append",
"(",
"self",
".",
"_builder",
".",
"builder_config",
".",
"name"... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | DatasetInfo.update_splits_if_different | Overwrite the splits if they are different from the current ones.
* If splits aren't already defined or different (ex: different number of
shards), then the new split dict is used. This will trigger stats
computation during download_and_prepare.
* If splits are already defined in DatasetInfo and si... | tensorflow_datasets/core/dataset_info.py | def update_splits_if_different(self, split_dict):
"""Overwrite the splits if they are different from the current ones.
* If splits aren't already defined or different (ex: different number of
shards), then the new split dict is used. This will trigger stats
computation during download_and_prepare.
... | def update_splits_if_different(self, split_dict):
"""Overwrite the splits if they are different from the current ones.
* If splits aren't already defined or different (ex: different number of
shards), then the new split dict is used. This will trigger stats
computation during download_and_prepare.
... | [
"Overwrite",
"the",
"splits",
"if",
"they",
"are",
"different",
"from",
"the",
"current",
"ones",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/dataset_info.py#L197-L217 | [
"def",
"update_splits_if_different",
"(",
"self",
",",
"split_dict",
")",
":",
"assert",
"isinstance",
"(",
"split_dict",
",",
"splits_lib",
".",
"SplitDict",
")",
"# If splits are already defined and identical, then we do not update",
"if",
"self",
".",
"_splits",
"and",... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | DatasetInfo._set_splits | Split setter (private method). | tensorflow_datasets/core/dataset_info.py | def _set_splits(self, split_dict):
"""Split setter (private method)."""
# Update the dictionary representation.
# Use from/to proto for a clean copy
self._splits = split_dict.copy()
# Update the proto
del self.as_proto.splits[:] # Clear previous
for split_info in split_dict.to_proto():
... | def _set_splits(self, split_dict):
"""Split setter (private method)."""
# Update the dictionary representation.
# Use from/to proto for a clean copy
self._splits = split_dict.copy()
# Update the proto
del self.as_proto.splits[:] # Clear previous
for split_info in split_dict.to_proto():
... | [
"Split",
"setter",
"(",
"private",
"method",
")",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/dataset_info.py#L219-L228 | [
"def",
"_set_splits",
"(",
"self",
",",
"split_dict",
")",
":",
"# Update the dictionary representation.",
"# Use from/to proto for a clean copy",
"self",
".",
"_splits",
"=",
"split_dict",
".",
"copy",
"(",
")",
"# Update the proto",
"del",
"self",
".",
"as_proto",
"... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | DatasetInfo._compute_dynamic_properties | Update from the DatasetBuilder. | tensorflow_datasets/core/dataset_info.py | def _compute_dynamic_properties(self, builder):
"""Update from the DatasetBuilder."""
# Fill other things by going over the dataset.
splits = self.splits
for split_info in utils.tqdm(
splits.values(), desc="Computing statistics...", unit=" split"):
try:
split_name = split_info.name... | def _compute_dynamic_properties(self, builder):
"""Update from the DatasetBuilder."""
# Fill other things by going over the dataset.
splits = self.splits
for split_info in utils.tqdm(
splits.values(), desc="Computing statistics...", unit=" split"):
try:
split_name = split_info.name... | [
"Update",
"from",
"the",
"DatasetBuilder",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/dataset_info.py#L249-L278 | [
"def",
"_compute_dynamic_properties",
"(",
"self",
",",
"builder",
")",
":",
"# Fill other things by going over the dataset.",
"splits",
"=",
"self",
".",
"splits",
"for",
"split_info",
"in",
"utils",
".",
"tqdm",
"(",
"splits",
".",
"values",
"(",
")",
",",
"de... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | DatasetInfo.write_to_directory | Write `DatasetInfo` as JSON to `dataset_info_dir`. | tensorflow_datasets/core/dataset_info.py | def write_to_directory(self, dataset_info_dir):
"""Write `DatasetInfo` as JSON to `dataset_info_dir`."""
# Save the metadata from the features (vocabulary, labels,...)
if self.features:
self.features.save_metadata(dataset_info_dir)
if self.redistribution_info.license:
with tf.io.gfile.GFile... | def write_to_directory(self, dataset_info_dir):
"""Write `DatasetInfo` as JSON to `dataset_info_dir`."""
# Save the metadata from the features (vocabulary, labels,...)
if self.features:
self.features.save_metadata(dataset_info_dir)
if self.redistribution_info.license:
with tf.io.gfile.GFile... | [
"Write",
"DatasetInfo",
"as",
"JSON",
"to",
"dataset_info_dir",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/dataset_info.py#L284-L297 | [
"def",
"write_to_directory",
"(",
"self",
",",
"dataset_info_dir",
")",
":",
"# Save the metadata from the features (vocabulary, labels,...)",
"if",
"self",
".",
"features",
":",
"self",
".",
"features",
".",
"save_metadata",
"(",
"dataset_info_dir",
")",
"if",
"self",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | DatasetInfo.read_from_directory | Update DatasetInfo from the JSON file in `dataset_info_dir`.
This function updates all the dynamically generated fields (num_examples,
hash, time of creation,...) of the DatasetInfo.
This will overwrite all previous metadata.
Args:
dataset_info_dir: `str` The directory containing the metadata f... | tensorflow_datasets/core/dataset_info.py | def read_from_directory(self, dataset_info_dir):
"""Update DatasetInfo from the JSON file in `dataset_info_dir`.
This function updates all the dynamically generated fields (num_examples,
hash, time of creation,...) of the DatasetInfo.
This will overwrite all previous metadata.
Args:
dataset... | def read_from_directory(self, dataset_info_dir):
"""Update DatasetInfo from the JSON file in `dataset_info_dir`.
This function updates all the dynamically generated fields (num_examples,
hash, time of creation,...) of the DatasetInfo.
This will overwrite all previous metadata.
Args:
dataset... | [
"Update",
"DatasetInfo",
"from",
"the",
"JSON",
"file",
"in",
"dataset_info_dir",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/dataset_info.py#L299-L367 | [
"def",
"read_from_directory",
"(",
"self",
",",
"dataset_info_dir",
")",
":",
"if",
"not",
"dataset_info_dir",
":",
"raise",
"ValueError",
"(",
"\"Calling read_from_directory with undefined dataset_info_dir.\"",
")",
"json_filename",
"=",
"self",
".",
"_dataset_info_filenam... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | DatasetInfo.initialize_from_bucket | Initialize DatasetInfo from GCS bucket info files. | tensorflow_datasets/core/dataset_info.py | def initialize_from_bucket(self):
"""Initialize DatasetInfo from GCS bucket info files."""
# In order to support Colab, we use the HTTP GCS API to access the metadata
# files. They are copied locally and then loaded.
tmp_dir = tempfile.mkdtemp("tfds")
data_files = gcs_utils.gcs_dataset_info_files(se... | def initialize_from_bucket(self):
"""Initialize DatasetInfo from GCS bucket info files."""
# In order to support Colab, we use the HTTP GCS API to access the metadata
# files. They are copied locally and then loaded.
tmp_dir = tempfile.mkdtemp("tfds")
data_files = gcs_utils.gcs_dataset_info_files(se... | [
"Initialize",
"DatasetInfo",
"from",
"GCS",
"bucket",
"info",
"files",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/dataset_info.py#L369-L381 | [
"def",
"initialize_from_bucket",
"(",
"self",
")",
":",
"# In order to support Colab, we use the HTTP GCS API to access the metadata",
"# files. They are copied locally and then loaded.",
"tmp_dir",
"=",
"tempfile",
".",
"mkdtemp",
"(",
"\"tfds\"",
")",
"data_files",
"=",
"gcs_ut... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | CycleGAN._split_generators | Returns SplitGenerators. | tensorflow_datasets/image/cycle_gan.py | def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
url = _DL_URLS[self.builder_config.name]
data_dirs = dl_manager.download_and_extract(url)
path_to_dataset = os.path.join(data_dirs, tf.io.gfile.listdir(data_dirs)[0])
train_a_path = os.path.join(path_to_dataset, "trainA")
... | def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
url = _DL_URLS[self.builder_config.name]
data_dirs = dl_manager.download_and_extract(url)
path_to_dataset = os.path.join(data_dirs, tf.io.gfile.listdir(data_dirs)[0])
train_a_path = os.path.join(path_to_dataset, "trainA")
... | [
"Returns",
"SplitGenerators",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/cycle_gan.py#L108-L149 | [
"def",
"_split_generators",
"(",
"self",
",",
"dl_manager",
")",
":",
"url",
"=",
"_DL_URLS",
"[",
"self",
".",
"builder_config",
".",
"name",
"]",
"data_dirs",
"=",
"dl_manager",
".",
"download_and_extract",
"(",
"url",
")",
"path_to_dataset",
"=",
"os",
".... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _map_promise | Map the function into each element and resolve the promise. | tensorflow_datasets/core/download/download_manager.py | def _map_promise(map_fn, all_inputs):
"""Map the function into each element and resolve the promise."""
all_promises = utils.map_nested(map_fn, all_inputs) # Apply the function
res = utils.map_nested(_wait_on_promise, all_promises)
return res | def _map_promise(map_fn, all_inputs):
"""Map the function into each element and resolve the promise."""
all_promises = utils.map_nested(map_fn, all_inputs) # Apply the function
res = utils.map_nested(_wait_on_promise, all_promises)
return res | [
"Map",
"the",
"function",
"into",
"each",
"element",
"and",
"resolve",
"the",
"promise",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/download/download_manager.py#L392-L396 | [
"def",
"_map_promise",
"(",
"map_fn",
",",
"all_inputs",
")",
":",
"all_promises",
"=",
"utils",
".",
"map_nested",
"(",
"map_fn",
",",
"all_inputs",
")",
"# Apply the function",
"res",
"=",
"utils",
".",
"map_nested",
"(",
"_wait_on_promise",
",",
"all_promises... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | DownloadManager._handle_download_result | Store dled file to definitive place, write INFO file, return path. | tensorflow_datasets/core/download/download_manager.py | def _handle_download_result(self, resource, tmp_dir_path, sha256, dl_size):
"""Store dled file to definitive place, write INFO file, return path."""
fnames = tf.io.gfile.listdir(tmp_dir_path)
if len(fnames) > 1:
raise AssertionError('More than one file in %s.' % tmp_dir_path)
original_fname = fnam... | def _handle_download_result(self, resource, tmp_dir_path, sha256, dl_size):
"""Store dled file to definitive place, write INFO file, return path."""
fnames = tf.io.gfile.listdir(tmp_dir_path)
if len(fnames) > 1:
raise AssertionError('More than one file in %s.' % tmp_dir_path)
original_fname = fnam... | [
"Store",
"dled",
"file",
"to",
"definitive",
"place",
"write",
"INFO",
"file",
"return",
"path",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/download/download_manager.py#L196-L215 | [
"def",
"_handle_download_result",
"(",
"self",
",",
"resource",
",",
"tmp_dir_path",
",",
"sha256",
",",
"dl_size",
")",
":",
"fnames",
"=",
"tf",
".",
"io",
".",
"gfile",
".",
"listdir",
"(",
"tmp_dir_path",
")",
"if",
"len",
"(",
"fnames",
")",
">",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | DownloadManager._download | Download resource, returns Promise->path to downloaded file. | tensorflow_datasets/core/download/download_manager.py | def _download(self, resource):
"""Download resource, returns Promise->path to downloaded file."""
if isinstance(resource, six.string_types):
resource = resource_lib.Resource(url=resource)
url = resource.url
if url in self._sizes_checksums:
expected_sha256 = self._sizes_checksums[url][1]
... | def _download(self, resource):
"""Download resource, returns Promise->path to downloaded file."""
if isinstance(resource, six.string_types):
resource = resource_lib.Resource(url=resource)
url = resource.url
if url in self._sizes_checksums:
expected_sha256 = self._sizes_checksums[url][1]
... | [
"Download",
"resource",
"returns",
"Promise",
"-",
">",
"path",
"to",
"downloaded",
"file",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/download/download_manager.py#L221-L247 | [
"def",
"_download",
"(",
"self",
",",
"resource",
")",
":",
"if",
"isinstance",
"(",
"resource",
",",
"six",
".",
"string_types",
")",
":",
"resource",
"=",
"resource_lib",
".",
"Resource",
"(",
"url",
"=",
"resource",
")",
"url",
"=",
"resource",
".",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | DownloadManager._extract | Extract a single archive, returns Promise->path to extraction result. | tensorflow_datasets/core/download/download_manager.py | def _extract(self, resource):
"""Extract a single archive, returns Promise->path to extraction result."""
if isinstance(resource, six.string_types):
resource = resource_lib.Resource(path=resource)
path = resource.path
extract_method = resource.extract_method
if extract_method == resource_lib.E... | def _extract(self, resource):
"""Extract a single archive, returns Promise->path to extraction result."""
if isinstance(resource, six.string_types):
resource = resource_lib.Resource(path=resource)
path = resource.path
extract_method = resource.extract_method
if extract_method == resource_lib.E... | [
"Extract",
"a",
"single",
"archive",
"returns",
"Promise",
"-",
">",
"path",
"to",
"extraction",
"result",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/download/download_manager.py#L251-L266 | [
"def",
"_extract",
"(",
"self",
",",
"resource",
")",
":",
"if",
"isinstance",
"(",
"resource",
",",
"six",
".",
"string_types",
")",
":",
"resource",
"=",
"resource_lib",
".",
"Resource",
"(",
"path",
"=",
"resource",
")",
"path",
"=",
"resource",
".",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | DownloadManager._download_extract | Download-extract `Resource` or url, returns Promise->path. | tensorflow_datasets/core/download/download_manager.py | def _download_extract(self, resource):
"""Download-extract `Resource` or url, returns Promise->path."""
if isinstance(resource, six.string_types):
resource = resource_lib.Resource(url=resource)
def callback(path):
resource.path = path
return self._extract(resource)
return self._downloa... | def _download_extract(self, resource):
"""Download-extract `Resource` or url, returns Promise->path."""
if isinstance(resource, six.string_types):
resource = resource_lib.Resource(url=resource)
def callback(path):
resource.path = path
return self._extract(resource)
return self._downloa... | [
"Download",
"-",
"extract",
"Resource",
"or",
"url",
"returns",
"Promise",
"-",
">",
"path",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/download/download_manager.py#L270-L277 | [
"def",
"_download_extract",
"(",
"self",
",",
"resource",
")",
":",
"if",
"isinstance",
"(",
"resource",
",",
"six",
".",
"string_types",
")",
":",
"resource",
"=",
"resource_lib",
".",
"Resource",
"(",
"url",
"=",
"resource",
")",
"def",
"callback",
"(",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | DownloadManager.download_kaggle_data | Download data for a given Kaggle competition. | tensorflow_datasets/core/download/download_manager.py | def download_kaggle_data(self, competition_name):
"""Download data for a given Kaggle competition."""
with self._downloader.tqdm():
kaggle_downloader = self._downloader.kaggle_downloader(competition_name)
urls = kaggle_downloader.competition_urls
files = kaggle_downloader.competition_files
... | def download_kaggle_data(self, competition_name):
"""Download data for a given Kaggle competition."""
with self._downloader.tqdm():
kaggle_downloader = self._downloader.kaggle_downloader(competition_name)
urls = kaggle_downloader.competition_urls
files = kaggle_downloader.competition_files
... | [
"Download",
"data",
"for",
"a",
"given",
"Kaggle",
"competition",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/download/download_manager.py#L279-L286 | [
"def",
"download_kaggle_data",
"(",
"self",
",",
"competition_name",
")",
":",
"with",
"self",
".",
"_downloader",
".",
"tqdm",
"(",
")",
":",
"kaggle_downloader",
"=",
"self",
".",
"_downloader",
".",
"kaggle_downloader",
"(",
"competition_name",
")",
"urls",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | DownloadManager.download | Download given url(s).
Args:
url_or_urls: url or `list`/`dict` of urls to download and extract. Each
url can be a `str` or `tfds.download.Resource`.
Returns:
downloaded_path(s): `str`, The downloaded paths matching the given input
url_or_urls. | tensorflow_datasets/core/download/download_manager.py | def download(self, url_or_urls):
"""Download given url(s).
Args:
url_or_urls: url or `list`/`dict` of urls to download and extract. Each
url can be a `str` or `tfds.download.Resource`.
Returns:
downloaded_path(s): `str`, The downloaded paths matching the given input
url_or_urls... | def download(self, url_or_urls):
"""Download given url(s).
Args:
url_or_urls: url or `list`/`dict` of urls to download and extract. Each
url can be a `str` or `tfds.download.Resource`.
Returns:
downloaded_path(s): `str`, The downloaded paths matching the given input
url_or_urls... | [
"Download",
"given",
"url",
"(",
"s",
")",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/download/download_manager.py#L288-L301 | [
"def",
"download",
"(",
"self",
",",
"url_or_urls",
")",
":",
"# Add progress bar to follow the download state",
"with",
"self",
".",
"_downloader",
".",
"tqdm",
"(",
")",
":",
"return",
"_map_promise",
"(",
"self",
".",
"_download",
",",
"url_or_urls",
")"
] | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | DownloadManager.iter_archive | Returns iterator over files within archive.
**Important Note**: caller should read files as they are yielded.
Reading out of order is slow.
Args:
resource: path to archive or `tfds.download.Resource`.
Returns:
Generator yielding tuple (path_within_archive, file_obj). | tensorflow_datasets/core/download/download_manager.py | def iter_archive(self, resource):
"""Returns iterator over files within archive.
**Important Note**: caller should read files as they are yielded.
Reading out of order is slow.
Args:
resource: path to archive or `tfds.download.Resource`.
Returns:
Generator yielding tuple (path_within_... | def iter_archive(self, resource):
"""Returns iterator over files within archive.
**Important Note**: caller should read files as they are yielded.
Reading out of order is slow.
Args:
resource: path to archive or `tfds.download.Resource`.
Returns:
Generator yielding tuple (path_within_... | [
"Returns",
"iterator",
"over",
"files",
"within",
"archive",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/download/download_manager.py#L303-L317 | [
"def",
"iter_archive",
"(",
"self",
",",
"resource",
")",
":",
"if",
"isinstance",
"(",
"resource",
",",
"six",
".",
"string_types",
")",
":",
"resource",
"=",
"resource_lib",
".",
"Resource",
"(",
"path",
"=",
"resource",
")",
"return",
"extractor",
".",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | DownloadManager.extract | Extract given path(s).
Args:
path_or_paths: path or `list`/`dict` of path of file to extract. Each
path can be a `str` or `tfds.download.Resource`.
If not explicitly specified in `Resource`, the extraction method is deduced
from downloaded file name.
Returns:
extracted_path(s): `s... | tensorflow_datasets/core/download/download_manager.py | def extract(self, path_or_paths):
"""Extract given path(s).
Args:
path_or_paths: path or `list`/`dict` of path of file to extract. Each
path can be a `str` or `tfds.download.Resource`.
If not explicitly specified in `Resource`, the extraction method is deduced
from downloaded file name.
... | def extract(self, path_or_paths):
"""Extract given path(s).
Args:
path_or_paths: path or `list`/`dict` of path of file to extract. Each
path can be a `str` or `tfds.download.Resource`.
If not explicitly specified in `Resource`, the extraction method is deduced
from downloaded file name.
... | [
"Extract",
"given",
"path",
"(",
"s",
")",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/download/download_manager.py#L319-L335 | [
"def",
"extract",
"(",
"self",
",",
"path_or_paths",
")",
":",
"# Add progress bar to follow the download state",
"with",
"self",
".",
"_extractor",
".",
"tqdm",
"(",
")",
":",
"return",
"_map_promise",
"(",
"self",
".",
"_extract",
",",
"path_or_paths",
")"
] | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | DownloadManager.download_and_extract | Download and extract given url_or_urls.
Is roughly equivalent to:
```
extracted_paths = dl_manager.extract(dl_manager.download(url_or_urls))
```
Args:
url_or_urls: url or `list`/`dict` of urls to download and extract. Each
url can be a `str` or `tfds.download.Resource`.
If not ... | tensorflow_datasets/core/download/download_manager.py | def download_and_extract(self, url_or_urls):
"""Download and extract given url_or_urls.
Is roughly equivalent to:
```
extracted_paths = dl_manager.extract(dl_manager.download(url_or_urls))
```
Args:
url_or_urls: url or `list`/`dict` of urls to download and extract. Each
url can ... | def download_and_extract(self, url_or_urls):
"""Download and extract given url_or_urls.
Is roughly equivalent to:
```
extracted_paths = dl_manager.extract(dl_manager.download(url_or_urls))
```
Args:
url_or_urls: url or `list`/`dict` of urls to download and extract. Each
url can ... | [
"Download",
"and",
"extract",
"given",
"url_or_urls",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/download/download_manager.py#L337-L359 | [
"def",
"download_and_extract",
"(",
"self",
",",
"url_or_urls",
")",
":",
"# Add progress bar to follow the download state",
"with",
"self",
".",
"_downloader",
".",
"tqdm",
"(",
")",
":",
"with",
"self",
".",
"_extractor",
".",
"tqdm",
"(",
")",
":",
"return",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | DownloadManager.manual_dir | Returns the directory containing the manually extracted data. | tensorflow_datasets/core/download/download_manager.py | def manual_dir(self):
"""Returns the directory containing the manually extracted data."""
if not tf.io.gfile.exists(self._manual_dir):
raise AssertionError(
'Manual directory {} does not exist. Create it and download/extract '
'dataset artifacts in there.'.format(self._manual_dir))
... | def manual_dir(self):
"""Returns the directory containing the manually extracted data."""
if not tf.io.gfile.exists(self._manual_dir):
raise AssertionError(
'Manual directory {} does not exist. Create it and download/extract '
'dataset artifacts in there.'.format(self._manual_dir))
... | [
"Returns",
"the",
"directory",
"containing",
"the",
"manually",
"extracted",
"data",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/download/download_manager.py#L362-L368 | [
"def",
"manual_dir",
"(",
"self",
")",
":",
"if",
"not",
"tf",
".",
"io",
".",
"gfile",
".",
"exists",
"(",
"self",
".",
"_manual_dir",
")",
":",
"raise",
"AssertionError",
"(",
"'Manual directory {} does not exist. Create it and download/extract '",
"'dataset artif... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _make_builder_configs | Construct a list of BuilderConfigs.
Construct a list of 75 Cifar10CorruptedConfig objects, corresponding to
the 15 corruption types and 5 severities.
Returns:
A list of 75 Cifar10CorruptedConfig objects. | tensorflow_datasets/image/cifar10_corrupted.py | def _make_builder_configs():
"""Construct a list of BuilderConfigs.
Construct a list of 75 Cifar10CorruptedConfig objects, corresponding to
the 15 corruption types and 5 severities.
Returns:
A list of 75 Cifar10CorruptedConfig objects.
"""
config_list = []
for corruption in _CORRUPTIONS:
for sev... | def _make_builder_configs():
"""Construct a list of BuilderConfigs.
Construct a list of 75 Cifar10CorruptedConfig objects, corresponding to
the 15 corruption types and 5 severities.
Returns:
A list of 75 Cifar10CorruptedConfig objects.
"""
config_list = []
for corruption in _CORRUPTIONS:
for sev... | [
"Construct",
"a",
"list",
"of",
"BuilderConfigs",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/cifar10_corrupted.py#L93-L114 | [
"def",
"_make_builder_configs",
"(",
")",
":",
"config_list",
"=",
"[",
"]",
"for",
"corruption",
"in",
"_CORRUPTIONS",
":",
"for",
"severity",
"in",
"range",
"(",
"1",
",",
"6",
")",
":",
"config_list",
".",
"append",
"(",
"Cifar10CorruptedConfig",
"(",
"... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | Cifar10Corrupted._split_generators | Return the test split of Cifar10.
Args:
dl_manager: download manager object.
Returns:
test split. | tensorflow_datasets/image/cifar10_corrupted.py | def _split_generators(self, dl_manager):
"""Return the test split of Cifar10.
Args:
dl_manager: download manager object.
Returns:
test split.
"""
path = dl_manager.download_and_extract(_DOWNLOAD_URL)
return [
tfds.core.SplitGenerator(
name=tfds.Split.TEST,
... | def _split_generators(self, dl_manager):
"""Return the test split of Cifar10.
Args:
dl_manager: download manager object.
Returns:
test split.
"""
path = dl_manager.download_and_extract(_DOWNLOAD_URL)
return [
tfds.core.SplitGenerator(
name=tfds.Split.TEST,
... | [
"Return",
"the",
"test",
"split",
"of",
"Cifar10",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/cifar10_corrupted.py#L138-L153 | [
"def",
"_split_generators",
"(",
"self",
",",
"dl_manager",
")",
":",
"path",
"=",
"dl_manager",
".",
"download_and_extract",
"(",
"_DOWNLOAD_URL",
")",
"return",
"[",
"tfds",
".",
"core",
".",
"SplitGenerator",
"(",
"name",
"=",
"tfds",
".",
"Split",
".",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | Cifar10Corrupted._generate_examples | Generate corrupted Cifar10 test data.
Apply corruptions to the raw images according to self.corruption_type.
Args:
data_dir: root directory of downloaded dataset
Yields:
dictionary with image file and label. | tensorflow_datasets/image/cifar10_corrupted.py | def _generate_examples(self, data_dir):
"""Generate corrupted Cifar10 test data.
Apply corruptions to the raw images according to self.corruption_type.
Args:
data_dir: root directory of downloaded dataset
Yields:
dictionary with image file and label.
"""
corruption = self.builder_... | def _generate_examples(self, data_dir):
"""Generate corrupted Cifar10 test data.
Apply corruptions to the raw images according to self.corruption_type.
Args:
data_dir: root directory of downloaded dataset
Yields:
dictionary with image file and label.
"""
corruption = self.builder_... | [
"Generate",
"corrupted",
"Cifar10",
"test",
"data",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/cifar10_corrupted.py#L155-L189 | [
"def",
"_generate_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"corruption",
"=",
"self",
".",
"builder_config",
".",
"corruption",
"severity",
"=",
"self",
".",
"builder_config",
".",
"severity",
"images_file",
"=",
"os",
".",
"path",
".",
"join",
"("... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | document_single_builder | Doc string for a single builder, with or without configs. | tensorflow_datasets/scripts/document_datasets.py | def document_single_builder(builder):
"""Doc string for a single builder, with or without configs."""
mod_name = builder.__class__.__module__
cls_name = builder.__class__.__name__
mod_file = sys.modules[mod_name].__file__
if mod_file.endswith("pyc"):
mod_file = mod_file[:-1]
description_prefix = ""
... | def document_single_builder(builder):
"""Doc string for a single builder, with or without configs."""
mod_name = builder.__class__.__module__
cls_name = builder.__class__.__name__
mod_file = sys.modules[mod_name].__file__
if mod_file.endswith("pyc"):
mod_file = mod_file[:-1]
description_prefix = ""
... | [
"Doc",
"string",
"for",
"a",
"single",
"builder",
"with",
"or",
"without",
"configs",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/scripts/document_datasets.py#L196-L265 | [
"def",
"document_single_builder",
"(",
"builder",
")",
":",
"mod_name",
"=",
"builder",
".",
"__class__",
".",
"__module__",
"cls_name",
"=",
"builder",
".",
"__class__",
".",
"__name__",
"mod_file",
"=",
"sys",
".",
"modules",
"[",
"mod_name",
"]",
".",
"__... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | make_module_to_builder_dict | Get all builders organized by module in nested dicts. | tensorflow_datasets/scripts/document_datasets.py | def make_module_to_builder_dict(datasets=None):
"""Get all builders organized by module in nested dicts."""
# pylint: disable=g-long-lambda
# dict to hold tfds->image->mnist->[builders]
module_to_builder = collections.defaultdict(
lambda: collections.defaultdict(
lambda: collections.defaultdict(... | def make_module_to_builder_dict(datasets=None):
"""Get all builders organized by module in nested dicts."""
# pylint: disable=g-long-lambda
# dict to hold tfds->image->mnist->[builders]
module_to_builder = collections.defaultdict(
lambda: collections.defaultdict(
lambda: collections.defaultdict(... | [
"Get",
"all",
"builders",
"organized",
"by",
"module",
"in",
"nested",
"dicts",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/scripts/document_datasets.py#L275-L305 | [
"def",
"make_module_to_builder_dict",
"(",
"datasets",
"=",
"None",
")",
":",
"# pylint: disable=g-long-lambda",
"# dict to hold tfds->image->mnist->[builders]",
"module_to_builder",
"=",
"collections",
".",
"defaultdict",
"(",
"lambda",
":",
"collections",
".",
"defaultdict"... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _pprint_features_dict | Pretty-print tfds.features.FeaturesDict. | tensorflow_datasets/scripts/document_datasets.py | def _pprint_features_dict(features_dict, indent=0, add_prefix=True):
"""Pretty-print tfds.features.FeaturesDict."""
first_last_indent_str = " " * indent
indent_str = " " * (indent + 4)
first_line = "%s%s({" % (
first_last_indent_str if add_prefix else "",
type(features_dict).__name__,
)
lines = ... | def _pprint_features_dict(features_dict, indent=0, add_prefix=True):
"""Pretty-print tfds.features.FeaturesDict."""
first_last_indent_str = " " * indent
indent_str = " " * (indent + 4)
first_line = "%s%s({" % (
first_last_indent_str if add_prefix else "",
type(features_dict).__name__,
)
lines = ... | [
"Pretty",
"-",
"print",
"tfds",
".",
"features",
".",
"FeaturesDict",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/scripts/document_datasets.py#L308-L325 | [
"def",
"_pprint_features_dict",
"(",
"features_dict",
",",
"indent",
"=",
"0",
",",
"add_prefix",
"=",
"True",
")",
":",
"first_last_indent_str",
"=",
"\" \"",
"*",
"indent",
"indent_str",
"=",
"\" \"",
"*",
"(",
"indent",
"+",
"4",
")",
"first_line",
"=",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | make_statistics_information | Make statistics information table. | tensorflow_datasets/scripts/document_datasets.py | def make_statistics_information(info):
"""Make statistics information table."""
if not info.splits.total_num_examples:
# That means that we have yet to calculate the statistics for this.
return "None computed"
stats = [(info.splits.total_num_examples, "ALL")]
for split_name, split_info in info.splits.i... | def make_statistics_information(info):
"""Make statistics information table."""
if not info.splits.total_num_examples:
# That means that we have yet to calculate the statistics for this.
return "None computed"
stats = [(info.splits.total_num_examples, "ALL")]
for split_name, split_info in info.splits.i... | [
"Make",
"statistics",
"information",
"table",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/scripts/document_datasets.py#L337-L351 | [
"def",
"make_statistics_information",
"(",
"info",
")",
":",
"if",
"not",
"info",
".",
"splits",
".",
"total_num_examples",
":",
"# That means that we have yet to calculate the statistics for this.",
"return",
"\"None computed\"",
"stats",
"=",
"[",
"(",
"info",
".",
"s... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | dataset_docs_str | Create dataset documentation string for given datasets.
Args:
datasets: list of datasets for which to create documentation.
If None, then all available datasets will be used.
Returns:
string describing the datasets (in the MarkDown format). | tensorflow_datasets/scripts/document_datasets.py | def dataset_docs_str(datasets=None):
"""Create dataset documentation string for given datasets.
Args:
datasets: list of datasets for which to create documentation.
If None, then all available datasets will be used.
Returns:
string describing the datasets (in the MarkDown format).
"""
m... | def dataset_docs_str(datasets=None):
"""Create dataset documentation string for given datasets.
Args:
datasets: list of datasets for which to create documentation.
If None, then all available datasets will be used.
Returns:
string describing the datasets (in the MarkDown format).
"""
m... | [
"Create",
"dataset",
"documentation",
"string",
"for",
"given",
"datasets",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/scripts/document_datasets.py#L354-L383 | [
"def",
"dataset_docs_str",
"(",
"datasets",
"=",
"None",
")",
":",
"module_to_builder",
"=",
"make_module_to_builder_dict",
"(",
"datasets",
")",
"sections",
"=",
"sorted",
"(",
"list",
"(",
"module_to_builder",
".",
"keys",
"(",
")",
")",
")",
"section_tocs",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | schema_org | Builds schema.org microdata for DatasetSearch from DatasetBuilder.
Markup spec: https://developers.google.com/search/docs/data-types/dataset#dataset
Testing tool: https://search.google.com/structured-data/testing-tool
For Google Dataset Search: https://toolbox.google.com/datasetsearch
Microdata format was cho... | tensorflow_datasets/scripts/document_datasets.py | def schema_org(builder):
# pylint: disable=line-too-long
"""Builds schema.org microdata for DatasetSearch from DatasetBuilder.
Markup spec: https://developers.google.com/search/docs/data-types/dataset#dataset
Testing tool: https://search.google.com/structured-data/testing-tool
For Google Dataset Search: http... | def schema_org(builder):
# pylint: disable=line-too-long
"""Builds schema.org microdata for DatasetSearch from DatasetBuilder.
Markup spec: https://developers.google.com/search/docs/data-types/dataset#dataset
Testing tool: https://search.google.com/structured-data/testing-tool
For Google Dataset Search: http... | [
"Builds",
"schema",
".",
"org",
"microdata",
"for",
"DatasetSearch",
"from",
"DatasetBuilder",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/scripts/document_datasets.py#L414-L449 | [
"def",
"schema_org",
"(",
"builder",
")",
":",
"# pylint: disable=line-too-long",
"# pylint: enable=line-too-long",
"properties",
"=",
"[",
"(",
"lambda",
"x",
":",
"x",
".",
"name",
",",
"SCHEMA_ORG_NAME",
")",
",",
"(",
"lambda",
"x",
":",
"x",
".",
"descrip... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | disk | Generating a Gaussian blurring kernel with disk shape.
Generating a Gaussian blurring kernel with disk shape using cv2 API.
Args:
radius: integer, radius of blurring kernel.
alias_blur: float, standard deviation of Gaussian blurring.
dtype: data type of kernel
Returns:
cv2 object of the Gaussia... | tensorflow_datasets/image/corruptions.py | def disk(radius, alias_blur=0.1, dtype=np.float32):
"""Generating a Gaussian blurring kernel with disk shape.
Generating a Gaussian blurring kernel with disk shape using cv2 API.
Args:
radius: integer, radius of blurring kernel.
alias_blur: float, standard deviation of Gaussian blurring.
dtype: data... | def disk(radius, alias_blur=0.1, dtype=np.float32):
"""Generating a Gaussian blurring kernel with disk shape.
Generating a Gaussian blurring kernel with disk shape using cv2 API.
Args:
radius: integer, radius of blurring kernel.
alias_blur: float, standard deviation of Gaussian blurring.
dtype: data... | [
"Generating",
"a",
"Gaussian",
"blurring",
"kernel",
"with",
"disk",
"shape",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/corruptions.py#L46-L70 | [
"def",
"disk",
"(",
"radius",
",",
"alias_blur",
"=",
"0.1",
",",
"dtype",
"=",
"np",
".",
"float32",
")",
":",
"if",
"radius",
"<=",
"8",
":",
"length",
"=",
"np",
".",
"arange",
"(",
"-",
"8",
",",
"8",
"+",
"1",
")",
"ksize",
"=",
"(",
"3"... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | clipped_zoom | Zoom image with clipping.
Zoom the central part of the image and clip extra pixels.
Args:
img: numpy array, uncorrupted image.
zoom_factor: numpy array, a sequence of float numbers for zoom factor.
Returns:
numpy array, zoomed image after clipping. | tensorflow_datasets/image/corruptions.py | def clipped_zoom(img, zoom_factor):
"""Zoom image with clipping.
Zoom the central part of the image and clip extra pixels.
Args:
img: numpy array, uncorrupted image.
zoom_factor: numpy array, a sequence of float numbers for zoom factor.
Returns:
numpy array, zoomed image after clipping.
"""
h... | def clipped_zoom(img, zoom_factor):
"""Zoom image with clipping.
Zoom the central part of the image and clip extra pixels.
Args:
img: numpy array, uncorrupted image.
zoom_factor: numpy array, a sequence of float numbers for zoom factor.
Returns:
numpy array, zoomed image after clipping.
"""
h... | [
"Zoom",
"image",
"with",
"clipping",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/corruptions.py#L73-L101 | [
"def",
"clipped_zoom",
"(",
"img",
",",
"zoom_factor",
")",
":",
"h",
"=",
"img",
".",
"shape",
"[",
"0",
"]",
"ch",
"=",
"int",
"(",
"np",
".",
"ceil",
"(",
"h",
"/",
"float",
"(",
"zoom_factor",
")",
")",
")",
"top_h",
"=",
"(",
"h",
"-",
"... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | plasma_fractal | Generate a heightmap using diamond-square algorithm.
Modification of the algorithm in
https://github.com/FLHerne/mapgen/blob/master/diamondsquare.py
Args:
mapsize: side length of the heightmap, must be a power of two.
wibbledecay: integer, decay factor.
Returns:
numpy 2d array, side length 'mapsi... | tensorflow_datasets/image/corruptions.py | def plasma_fractal(mapsize=512, wibbledecay=3):
"""Generate a heightmap using diamond-square algorithm.
Modification of the algorithm in
https://github.com/FLHerne/mapgen/blob/master/diamondsquare.py
Args:
mapsize: side length of the heightmap, must be a power of two.
wibbledecay: integer, decay facto... | def plasma_fractal(mapsize=512, wibbledecay=3):
"""Generate a heightmap using diamond-square algorithm.
Modification of the algorithm in
https://github.com/FLHerne/mapgen/blob/master/diamondsquare.py
Args:
mapsize: side length of the heightmap, must be a power of two.
wibbledecay: integer, decay facto... | [
"Generate",
"a",
"heightmap",
"using",
"diamond",
"-",
"square",
"algorithm",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/corruptions.py#L104-L159 | [
"def",
"plasma_fractal",
"(",
"mapsize",
"=",
"512",
",",
"wibbledecay",
"=",
"3",
")",
":",
"if",
"mapsize",
"&",
"(",
"mapsize",
"-",
"1",
")",
"!=",
"0",
":",
"raise",
"ValueError",
"(",
"'mapsize must be a power of two.'",
")",
"maparray",
"=",
"np",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | gaussian_noise | Gaussian noise corruption to images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Added Gaussian noise. | tensorflow_datasets/image/corruptions.py | def gaussian_noise(x, severity=1):
"""Gaussian noise corruption to images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Added Gaussian noise.
"""
c = [.08, .12... | def gaussian_noise(x, severity=1):
"""Gaussian noise corruption to images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Added Gaussian noise.
"""
c = [.08, .12... | [
"Gaussian",
"noise",
"corruption",
"to",
"images",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/corruptions.py#L167-L180 | [
"def",
"gaussian_noise",
"(",
"x",
",",
"severity",
"=",
"1",
")",
":",
"c",
"=",
"[",
".08",
",",
".12",
",",
"0.18",
",",
"0.26",
",",
"0.38",
"]",
"[",
"severity",
"-",
"1",
"]",
"x",
"=",
"np",
".",
"array",
"(",
"x",
")",
"/",
"255.",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | shot_noise | Shot noise corruption to images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Added shot noise. | tensorflow_datasets/image/corruptions.py | def shot_noise(x, severity=1):
"""Shot noise corruption to images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Added shot noise.
"""
c = [60, 25, 12, 5, 3][se... | def shot_noise(x, severity=1):
"""Shot noise corruption to images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Added shot noise.
"""
c = [60, 25, 12, 5, 3][se... | [
"Shot",
"noise",
"corruption",
"to",
"images",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/corruptions.py#L183-L196 | [
"def",
"shot_noise",
"(",
"x",
",",
"severity",
"=",
"1",
")",
":",
"c",
"=",
"[",
"60",
",",
"25",
",",
"12",
",",
"5",
",",
"3",
"]",
"[",
"severity",
"-",
"1",
"]",
"x",
"=",
"np",
".",
"array",
"(",
"x",
")",
"/",
"255.",
"x_clip",
"=... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | impulse_noise | Impulse noise corruption to images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Added impulse noise. | tensorflow_datasets/image/corruptions.py | def impulse_noise(x, severity=1):
"""Impulse noise corruption to images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Added impulse noise.
"""
c = [.03, .06, .... | def impulse_noise(x, severity=1):
"""Impulse noise corruption to images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Added impulse noise.
"""
c = [.03, .06, .... | [
"Impulse",
"noise",
"corruption",
"to",
"images",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/corruptions.py#L199-L213 | [
"def",
"impulse_noise",
"(",
"x",
",",
"severity",
"=",
"1",
")",
":",
"c",
"=",
"[",
".03",
",",
".06",
",",
".09",
",",
"0.17",
",",
"0.27",
"]",
"[",
"severity",
"-",
"1",
"]",
"x",
"=",
"tfds",
".",
"core",
".",
"lazy_imports",
".",
"skimag... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | defocus_blur | Defocus blurring to images.
Apply defocus blurring to images using Gaussian kernel.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Applied defocus blur. | tensorflow_datasets/image/corruptions.py | def defocus_blur(x, severity=1):
"""Defocus blurring to images.
Apply defocus blurring to images using Gaussian kernel.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,2... | def defocus_blur(x, severity=1):
"""Defocus blurring to images.
Apply defocus blurring to images using Gaussian kernel.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,2... | [
"Defocus",
"blurring",
"to",
"images",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/corruptions.py#L216-L236 | [
"def",
"defocus_blur",
"(",
"x",
",",
"severity",
"=",
"1",
")",
":",
"c",
"=",
"[",
"(",
"3",
",",
"0.1",
")",
",",
"(",
"4",
",",
"0.5",
")",
",",
"(",
"6",
",",
"0.5",
")",
",",
"(",
"8",
",",
"0.5",
")",
",",
"(",
"10",
",",
"0.5",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | frosted_glass_blur | Frosted glass blurring to images.
Apply frosted glass blurring to images by shuffling pixels locally.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Applied frosted... | tensorflow_datasets/image/corruptions.py | def frosted_glass_blur(x, severity=1):
"""Frosted glass blurring to images.
Apply frosted glass blurring to images by shuffling pixels locally.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image w... | def frosted_glass_blur(x, severity=1):
"""Frosted glass blurring to images.
Apply frosted glass blurring to images by shuffling pixels locally.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image w... | [
"Frosted",
"glass",
"blurring",
"to",
"images",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/corruptions.py#L239-L270 | [
"def",
"frosted_glass_blur",
"(",
"x",
",",
"severity",
"=",
"1",
")",
":",
"# sigma, max_delta, iterations",
"c",
"=",
"[",
"(",
"0.7",
",",
"1",
",",
"2",
")",
",",
"(",
"0.9",
",",
"2",
",",
"1",
")",
",",
"(",
"1",
",",
"2",
",",
"3",
")",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | zoom_blur | Zoom blurring to images.
Applying zoom blurring to images by zooming the central part of the images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Applied zoom blu... | tensorflow_datasets/image/corruptions.py | def zoom_blur(x, severity=1):
"""Zoom blurring to images.
Applying zoom blurring to images by zooming the central part of the images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 ... | def zoom_blur(x, severity=1):
"""Zoom blurring to images.
Applying zoom blurring to images by zooming the central part of the images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 ... | [
"Zoom",
"blurring",
"to",
"images",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/corruptions.py#L273-L298 | [
"def",
"zoom_blur",
"(",
"x",
",",
"severity",
"=",
"1",
")",
":",
"c",
"=",
"[",
"np",
".",
"arange",
"(",
"1",
",",
"1.11",
",",
"0.01",
")",
",",
"np",
".",
"arange",
"(",
"1",
",",
"1.16",
",",
"0.01",
")",
",",
"np",
".",
"arange",
"("... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | fog | Fog corruption to images.
Adding fog to images. Fog is generated by diamond-square algorithm.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Added fog. | tensorflow_datasets/image/corruptions.py | def fog(x, severity=1):
"""Fog corruption to images.
Adding fog to images. Fog is generated by diamond-square algorithm.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,... | def fog(x, severity=1):
"""Fog corruption to images.
Adding fog to images. Fog is generated by diamond-square algorithm.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,... | [
"Fog",
"corruption",
"to",
"images",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/corruptions.py#L301-L326 | [
"def",
"fog",
"(",
"x",
",",
"severity",
"=",
"1",
")",
":",
"c",
"=",
"[",
"(",
"1.5",
",",
"2",
")",
",",
"(",
"2.",
",",
"2",
")",
",",
"(",
"2.5",
",",
"1.7",
")",
",",
"(",
"2.5",
",",
"1.5",
")",
",",
"(",
"3.",
",",
"1.4",
")",... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | brightness | Change brightness of images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Changed brightness. | tensorflow_datasets/image/corruptions.py | def brightness(x, severity=1):
"""Change brightness of images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Changed brightness.
"""
c = [.1, .2, .3, .4, .5][se... | def brightness(x, severity=1):
"""Change brightness of images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Changed brightness.
"""
c = [.1, .2, .3, .4, .5][se... | [
"Change",
"brightness",
"of",
"images",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/corruptions.py#L329-L346 | [
"def",
"brightness",
"(",
"x",
",",
"severity",
"=",
"1",
")",
":",
"c",
"=",
"[",
".1",
",",
".2",
",",
".3",
",",
".4",
",",
".5",
"]",
"[",
"severity",
"-",
"1",
"]",
"x",
"=",
"np",
".",
"array",
"(",
"x",
")",
"/",
"255.",
"x",
"=",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | contrast | Change contrast of images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Changed contrast. | tensorflow_datasets/image/corruptions.py | def contrast(x, severity=1):
"""Change contrast of images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Changed contrast.
"""
c = [0.4, .3, .2, .1, .05][severi... | def contrast(x, severity=1):
"""Change contrast of images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Changed contrast.
"""
c = [0.4, .3, .2, .1, .05][severi... | [
"Change",
"contrast",
"of",
"images",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/corruptions.py#L349-L364 | [
"def",
"contrast",
"(",
"x",
",",
"severity",
"=",
"1",
")",
":",
"c",
"=",
"[",
"0.4",
",",
".3",
",",
".2",
",",
".1",
",",
".05",
"]",
"[",
"severity",
"-",
"1",
"]",
"x",
"=",
"np",
".",
"array",
"(",
"x",
")",
"/",
"255.",
"means",
"... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | elastic | Conduct elastic transform to images.
Elastic transform is performed on small patches of the images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Applied elastic t... | tensorflow_datasets/image/corruptions.py | def elastic(x, severity=1):
"""Conduct elastic transform to images.
Elastic transform is performed on small patches of the images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pix... | def elastic(x, severity=1):
"""Conduct elastic transform to images.
Elastic transform is performed on small patches of the images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pix... | [
"Conduct",
"elastic",
"transform",
"to",
"images",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/corruptions.py#L367-L425 | [
"def",
"elastic",
"(",
"x",
",",
"severity",
"=",
"1",
")",
":",
"c",
"=",
"[",
"(",
"244",
"*",
"2",
",",
"244",
"*",
"0.7",
",",
"244",
"*",
"0.1",
")",
",",
"(",
"244",
"*",
"2",
",",
"244",
"*",
"0.08",
",",
"244",
"*",
"0.2",
")",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | pixelate | Pixelate images.
Conduct pixelating corruptions to images by first shrinking the images and
then resizing to original size.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in ... | tensorflow_datasets/image/corruptions.py | def pixelate(x, severity=1):
"""Pixelate images.
Conduct pixelating corruptions to images by first shrinking the images and
then resizing to original size.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy ... | def pixelate(x, severity=1):
"""Pixelate images.
Conduct pixelating corruptions to images by first shrinking the images and
then resizing to original size.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy ... | [
"Pixelate",
"images",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/corruptions.py#L428-L447 | [
"def",
"pixelate",
"(",
"x",
",",
"severity",
"=",
"1",
")",
":",
"c",
"=",
"[",
"0.6",
",",
"0.5",
",",
"0.4",
",",
"0.3",
",",
"0.25",
"]",
"[",
"severity",
"-",
"1",
"]",
"shape",
"=",
"x",
".",
"shape",
"x",
"=",
"tfds",
".",
"core",
".... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | jpeg_compression | Conduct jpeg compression to images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Applied jpeg compression. | tensorflow_datasets/image/corruptions.py | def jpeg_compression(x, severity=1):
"""Conduct jpeg compression to images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Applied jpeg compression.
"""
c = [25,... | def jpeg_compression(x, severity=1):
"""Conduct jpeg compression to images.
Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.
Returns:
numpy array, image with uint8 pixels in [0,255]. Applied jpeg compression.
"""
c = [25,... | [
"Conduct",
"jpeg",
"compression",
"to",
"images",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/corruptions.py#L450-L466 | [
"def",
"jpeg_compression",
"(",
"x",
",",
"severity",
"=",
"1",
")",
":",
"c",
"=",
"[",
"25",
",",
"18",
",",
"15",
",",
"10",
",",
"7",
"]",
"[",
"severity",
"-",
"1",
"]",
"x",
"=",
"tfds",
".",
"core",
".",
"lazy_imports",
".",
"PIL_Image",... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | temporary_assignment | Temporarily assign obj.attr to value. | tensorflow_datasets/core/utils/py_utils.py | def temporary_assignment(obj, attr, value):
"""Temporarily assign obj.attr to value."""
original = getattr(obj, attr, None)
setattr(obj, attr, value)
yield
setattr(obj, attr, original) | def temporary_assignment(obj, attr, value):
"""Temporarily assign obj.attr to value."""
original = getattr(obj, attr, None)
setattr(obj, attr, value)
yield
setattr(obj, attr, original) | [
"Temporarily",
"assign",
"obj",
".",
"attr",
"to",
"value",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/utils/py_utils.py#L55-L60 | [
"def",
"temporary_assignment",
"(",
"obj",
",",
"attr",
",",
"value",
")",
":",
"original",
"=",
"getattr",
"(",
"obj",
",",
"attr",
",",
"None",
")",
"setattr",
"(",
"obj",
",",
"attr",
",",
"value",
")",
"yield",
"setattr",
"(",
"obj",
",",
"attr",... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | zip_dict | Iterate over items of dictionaries grouped by their keys. | tensorflow_datasets/core/utils/py_utils.py | def zip_dict(*dicts):
"""Iterate over items of dictionaries grouped by their keys."""
for key in set(itertools.chain(*dicts)): # set merge all keys
# Will raise KeyError if the dict don't have the same keys
yield key, tuple(d[key] for d in dicts) | def zip_dict(*dicts):
"""Iterate over items of dictionaries grouped by their keys."""
for key in set(itertools.chain(*dicts)): # set merge all keys
# Will raise KeyError if the dict don't have the same keys
yield key, tuple(d[key] for d in dicts) | [
"Iterate",
"over",
"items",
"of",
"dictionaries",
"grouped",
"by",
"their",
"keys",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/utils/py_utils.py#L63-L67 | [
"def",
"zip_dict",
"(",
"*",
"dicts",
")",
":",
"for",
"key",
"in",
"set",
"(",
"itertools",
".",
"chain",
"(",
"*",
"dicts",
")",
")",
":",
"# set merge all keys",
"# Will raise KeyError if the dict don't have the same keys",
"yield",
"key",
",",
"tuple",
"(",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | map_nested | Apply a function recursively to each element of a nested data struct. | tensorflow_datasets/core/utils/py_utils.py | def map_nested(function, data_struct, dict_only=False, map_tuple=False):
"""Apply a function recursively to each element of a nested data struct."""
# Could add support for more exotic data_struct, like OrderedDict
if isinstance(data_struct, dict):
return {
k: map_nested(function, v, dict_only, map_t... | def map_nested(function, data_struct, dict_only=False, map_tuple=False):
"""Apply a function recursively to each element of a nested data struct."""
# Could add support for more exotic data_struct, like OrderedDict
if isinstance(data_struct, dict):
return {
k: map_nested(function, v, dict_only, map_t... | [
"Apply",
"a",
"function",
"recursively",
"to",
"each",
"element",
"of",
"a",
"nested",
"data",
"struct",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/utils/py_utils.py#L122-L143 | [
"def",
"map_nested",
"(",
"function",
",",
"data_struct",
",",
"dict_only",
"=",
"False",
",",
"map_tuple",
"=",
"False",
")",
":",
"# Could add support for more exotic data_struct, like OrderedDict",
"if",
"isinstance",
"(",
"data_struct",
",",
"dict",
")",
":",
"r... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | zip_nested | Zip data struct together and return a data struct with the same shape. | tensorflow_datasets/core/utils/py_utils.py | def zip_nested(arg0, *args, **kwargs):
"""Zip data struct together and return a data struct with the same shape."""
# Python 2 do not support kwargs only arguments
dict_only = kwargs.pop("dict_only", False)
assert not kwargs
# Could add support for more exotic data_struct, like OrderedDict
if isinstance(ar... | def zip_nested(arg0, *args, **kwargs):
"""Zip data struct together and return a data struct with the same shape."""
# Python 2 do not support kwargs only arguments
dict_only = kwargs.pop("dict_only", False)
assert not kwargs
# Could add support for more exotic data_struct, like OrderedDict
if isinstance(ar... | [
"Zip",
"data",
"struct",
"together",
"and",
"return",
"a",
"data",
"struct",
"with",
"the",
"same",
"shape",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/utils/py_utils.py#L146-L161 | [
"def",
"zip_nested",
"(",
"arg0",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# Python 2 do not support kwargs only arguments",
"dict_only",
"=",
"kwargs",
".",
"pop",
"(",
"\"dict_only\"",
",",
"False",
")",
"assert",
"not",
"kwargs",
"# Could add sup... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | as_proto_cls | Simulate proto inheritance.
By default, protobuf do not support direct inheritance, so this decorator
simulates inheritance to the class to which it is applied.
Example:
```
@as_proto_class(proto.MyProto)
class A(object):
def custom_method(self):
return self.proto_field * 10
p = proto.MyProt... | tensorflow_datasets/core/utils/py_utils.py | def as_proto_cls(proto_cls):
"""Simulate proto inheritance.
By default, protobuf do not support direct inheritance, so this decorator
simulates inheritance to the class to which it is applied.
Example:
```
@as_proto_class(proto.MyProto)
class A(object):
def custom_method(self):
return self.pr... | def as_proto_cls(proto_cls):
"""Simulate proto inheritance.
By default, protobuf do not support direct inheritance, so this decorator
simulates inheritance to the class to which it is applied.
Example:
```
@as_proto_class(proto.MyProto)
class A(object):
def custom_method(self):
return self.pr... | [
"Simulate",
"proto",
"inheritance",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/utils/py_utils.py#L164-L229 | [
"def",
"as_proto_cls",
"(",
"proto_cls",
")",
":",
"def",
"decorator",
"(",
"cls",
")",
":",
"\"\"\"Decorator applied to the class.\"\"\"",
"class",
"ProtoCls",
"(",
"object",
")",
":",
"\"\"\"Base class simulating the protobuf.\"\"\"",
"def",
"__init__",
"(",
"self",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | tfds_dir | Path to tensorflow_datasets directory. | tensorflow_datasets/core/utils/py_utils.py | def tfds_dir():
"""Path to tensorflow_datasets directory."""
return os.path.dirname(os.path.dirname(os.path.dirname(__file__))) | def tfds_dir():
"""Path to tensorflow_datasets directory."""
return os.path.dirname(os.path.dirname(os.path.dirname(__file__))) | [
"Path",
"to",
"tensorflow_datasets",
"directory",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/utils/py_utils.py#L232-L234 | [
"def",
"tfds_dir",
"(",
")",
":",
"return",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
")",
")"
] | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | atomic_write | Writes to path atomically, by writing to temp file and renaming it. | tensorflow_datasets/core/utils/py_utils.py | def atomic_write(path, mode):
"""Writes to path atomically, by writing to temp file and renaming it."""
tmp_path = "%s%s_%s" % (path, constants.INCOMPLETE_SUFFIX, uuid.uuid4().hex)
with tf.io.gfile.GFile(tmp_path, mode) as file_:
yield file_
tf.io.gfile.rename(tmp_path, path, overwrite=True) | def atomic_write(path, mode):
"""Writes to path atomically, by writing to temp file and renaming it."""
tmp_path = "%s%s_%s" % (path, constants.INCOMPLETE_SUFFIX, uuid.uuid4().hex)
with tf.io.gfile.GFile(tmp_path, mode) as file_:
yield file_
tf.io.gfile.rename(tmp_path, path, overwrite=True) | [
"Writes",
"to",
"path",
"atomically",
"by",
"writing",
"to",
"temp",
"file",
"and",
"renaming",
"it",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/utils/py_utils.py#L238-L243 | [
"def",
"atomic_write",
"(",
"path",
",",
"mode",
")",
":",
"tmp_path",
"=",
"\"%s%s_%s\"",
"%",
"(",
"path",
",",
"constants",
".",
"INCOMPLETE_SUFFIX",
",",
"uuid",
".",
"uuid4",
"(",
")",
".",
"hex",
")",
"with",
"tf",
".",
"io",
".",
"gfile",
".",... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | read_checksum_digest | Given a hash constructor, returns checksum digest and size of file. | tensorflow_datasets/core/utils/py_utils.py | def read_checksum_digest(path, checksum_cls=hashlib.sha256):
"""Given a hash constructor, returns checksum digest and size of file."""
checksum = checksum_cls()
size = 0
with tf.io.gfile.GFile(path, "rb") as f:
while True:
block = f.read(io.DEFAULT_BUFFER_SIZE)
size += len(block)
if not bl... | def read_checksum_digest(path, checksum_cls=hashlib.sha256):
"""Given a hash constructor, returns checksum digest and size of file."""
checksum = checksum_cls()
size = 0
with tf.io.gfile.GFile(path, "rb") as f:
while True:
block = f.read(io.DEFAULT_BUFFER_SIZE)
size += len(block)
if not bl... | [
"Given",
"a",
"hash",
"constructor",
"returns",
"checksum",
"digest",
"and",
"size",
"of",
"file",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/utils/py_utils.py#L262-L273 | [
"def",
"read_checksum_digest",
"(",
"path",
",",
"checksum_cls",
"=",
"hashlib",
".",
"sha256",
")",
":",
"checksum",
"=",
"checksum_cls",
"(",
")",
"size",
"=",
"0",
"with",
"tf",
".",
"io",
".",
"gfile",
".",
"GFile",
"(",
"path",
",",
"\"rb\"",
")",... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | reraise | Reraise an exception with an additional message. | tensorflow_datasets/core/utils/py_utils.py | def reraise(additional_msg):
"""Reraise an exception with an additional message."""
exc_type, exc_value, exc_traceback = sys.exc_info()
msg = str(exc_value) + "\n" + additional_msg
six.reraise(exc_type, exc_type(msg), exc_traceback) | def reraise(additional_msg):
"""Reraise an exception with an additional message."""
exc_type, exc_value, exc_traceback = sys.exc_info()
msg = str(exc_value) + "\n" + additional_msg
six.reraise(exc_type, exc_type(msg), exc_traceback) | [
"Reraise",
"an",
"exception",
"with",
"an",
"additional",
"message",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/utils/py_utils.py#L276-L280 | [
"def",
"reraise",
"(",
"additional_msg",
")",
":",
"exc_type",
",",
"exc_value",
",",
"exc_traceback",
"=",
"sys",
".",
"exc_info",
"(",
")",
"msg",
"=",
"str",
"(",
"exc_value",
")",
"+",
"\"\\n\"",
"+",
"additional_msg",
"six",
".",
"reraise",
"(",
"ex... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | rgetattr | Get attr that handles dots in attr name. | tensorflow_datasets/core/utils/py_utils.py | def rgetattr(obj, attr, *args):
"""Get attr that handles dots in attr name."""
def _getattr(obj, attr):
return getattr(obj, attr, *args)
return functools.reduce(_getattr, [obj] + attr.split(".")) | def rgetattr(obj, attr, *args):
"""Get attr that handles dots in attr name."""
def _getattr(obj, attr):
return getattr(obj, attr, *args)
return functools.reduce(_getattr, [obj] + attr.split(".")) | [
"Get",
"attr",
"that",
"handles",
"dots",
"in",
"attr",
"name",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/utils/py_utils.py#L283-L287 | [
"def",
"rgetattr",
"(",
"obj",
",",
"attr",
",",
"*",
"args",
")",
":",
"def",
"_getattr",
"(",
"obj",
",",
"attr",
")",
":",
"return",
"getattr",
"(",
"obj",
",",
"attr",
",",
"*",
"args",
")",
"return",
"functools",
".",
"reduce",
"(",
"_getattr"... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | CelebAHq._split_generators | Returns SplitGenerators. | tensorflow_datasets/image/celebahq.py | def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
image_tar_file = os.path.join(dl_manager.manual_dir,
self.builder_config.file_name)
if not tf.io.gfile.exists(image_tar_file):
# The current celebahq generation code depends on a concrete version ... | def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
image_tar_file = os.path.join(dl_manager.manual_dir,
self.builder_config.file_name)
if not tf.io.gfile.exists(image_tar_file):
# The current celebahq generation code depends on a concrete version ... | [
"Returns",
"SplitGenerators",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/celebahq.py#L107-L124 | [
"def",
"_split_generators",
"(",
"self",
",",
"dl_manager",
")",
":",
"image_tar_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"dl_manager",
".",
"manual_dir",
",",
"self",
".",
"builder_config",
".",
"file_name",
")",
"if",
"not",
"tf",
".",
"io",
".... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | TedHrlrTranslate._generate_examples | This function returns the examples in the raw (text) form. | tensorflow_datasets/translate/ted_hrlr.py | def _generate_examples(self, source_file, target_file):
"""This function returns the examples in the raw (text) form."""
with tf.io.gfile.GFile(source_file) as f:
source_sentences = f.read().split("\n")
with tf.io.gfile.GFile(target_file) as f:
target_sentences = f.read().split("\n")
assert... | def _generate_examples(self, source_file, target_file):
"""This function returns the examples in the raw (text) form."""
with tf.io.gfile.GFile(source_file) as f:
source_sentences = f.read().split("\n")
with tf.io.gfile.GFile(target_file) as f:
target_sentences = f.read().split("\n")
assert... | [
"This",
"function",
"returns",
"the",
"examples",
"in",
"the",
"raw",
"(",
"text",
")",
"form",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/translate/ted_hrlr.py#L160-L176 | [
"def",
"_generate_examples",
"(",
"self",
",",
"source_file",
",",
"target_file",
")",
":",
"with",
"tf",
".",
"io",
".",
"gfile",
".",
"GFile",
"(",
"source_file",
")",
"as",
"f",
":",
"source_sentences",
"=",
"f",
".",
"read",
"(",
")",
".",
"split",... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | Xnli._generate_examples | This function returns the examples in the raw (text) form. | tensorflow_datasets/text/xnli.py | def _generate_examples(self, filepath):
"""This function returns the examples in the raw (text) form."""
rows_per_pair_id = collections.defaultdict(list)
with tf.io.gfile.GFile(filepath) as f:
reader = csv.DictReader(f, delimiter='\t', quoting=csv.QUOTE_NONE)
for row in reader:
rows_per... | def _generate_examples(self, filepath):
"""This function returns the examples in the raw (text) form."""
rows_per_pair_id = collections.defaultdict(list)
with tf.io.gfile.GFile(filepath) as f:
reader = csv.DictReader(f, delimiter='\t', quoting=csv.QUOTE_NONE)
for row in reader:
rows_per... | [
"This",
"function",
"returns",
"the",
"examples",
"in",
"the",
"raw",
"(",
"text",
")",
"form",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/text/xnli.py#L107-L123 | [
"def",
"_generate_examples",
"(",
"self",
",",
"filepath",
")",
":",
"rows_per_pair_id",
"=",
"collections",
".",
"defaultdict",
"(",
"list",
")",
"with",
"tf",
".",
"io",
".",
"gfile",
".",
"GFile",
"(",
"filepath",
")",
"as",
"f",
":",
"reader",
"=",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | Voc2007._generate_example | Yields examples. | tensorflow_datasets/image/voc.py | def _generate_example(self, data_path, image_id):
"""Yields examples."""
image_filepath = os.path.join(
data_path, "VOCdevkit/VOC2007/JPEGImages", "{}.jpg".format(image_id))
annon_filepath = os.path.join(
data_path, "VOCdevkit/VOC2007/Annotations", "{}.xml".format(image_id))
def _get_ex... | def _generate_example(self, data_path, image_id):
"""Yields examples."""
image_filepath = os.path.join(
data_path, "VOCdevkit/VOC2007/JPEGImages", "{}.jpg".format(image_id))
annon_filepath = os.path.join(
data_path, "VOCdevkit/VOC2007/Annotations", "{}.xml".format(image_id))
def _get_ex... | [
"Yields",
"examples",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/voc.py#L137-L186 | [
"def",
"_generate_example",
"(",
"self",
",",
"data_path",
",",
"image_id",
")",
":",
"image_filepath",
"=",
"os",
".",
"path",
".",
"join",
"(",
"data_path",
",",
"\"VOCdevkit/VOC2007/JPEGImages\"",
",",
"\"{}.jpg\"",
".",
"format",
"(",
"image_id",
")",
")",... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | Image.set_encoding_format | Update the encoding format. | tensorflow_datasets/core/features/image_feature.py | def set_encoding_format(self, encoding_format):
"""Update the encoding format."""
supported = ENCODE_FN.keys()
if encoding_format not in supported:
raise ValueError('`encoding_format` must be one of %s.' % supported)
self._encoding_format = encoding_format | def set_encoding_format(self, encoding_format):
"""Update the encoding format."""
supported = ENCODE_FN.keys()
if encoding_format not in supported:
raise ValueError('`encoding_format` must be one of %s.' % supported)
self._encoding_format = encoding_format | [
"Update",
"the",
"encoding",
"format",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/features/image_feature.py#L97-L102 | [
"def",
"set_encoding_format",
"(",
"self",
",",
"encoding_format",
")",
":",
"supported",
"=",
"ENCODE_FN",
".",
"keys",
"(",
")",
"if",
"encoding_format",
"not",
"in",
"supported",
":",
"raise",
"ValueError",
"(",
"'`encoding_format` must be one of %s.'",
"%",
"s... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | Image.set_shape | Update the shape. | tensorflow_datasets/core/features/image_feature.py | def set_shape(self, shape):
"""Update the shape."""
channels = shape[-1]
acceptable_channels = ACCEPTABLE_CHANNELS[self._encoding_format]
if channels not in acceptable_channels:
raise ValueError('Acceptable `channels` for %s: %s (was %s)' % (
self._encoding_format, acceptable_channels, c... | def set_shape(self, shape):
"""Update the shape."""
channels = shape[-1]
acceptable_channels = ACCEPTABLE_CHANNELS[self._encoding_format]
if channels not in acceptable_channels:
raise ValueError('Acceptable `channels` for %s: %s (was %s)' % (
self._encoding_format, acceptable_channels, c... | [
"Update",
"the",
"shape",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/features/image_feature.py#L104-L111 | [
"def",
"set_shape",
"(",
"self",
",",
"shape",
")",
":",
"channels",
"=",
"shape",
"[",
"-",
"1",
"]",
"acceptable_channels",
"=",
"ACCEPTABLE_CHANNELS",
"[",
"self",
".",
"_encoding_format",
"]",
"if",
"channels",
"not",
"in",
"acceptable_channels",
":",
"r... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | Image._encode_image | Returns np_image encoded as jpeg or png. | tensorflow_datasets/core/features/image_feature.py | def _encode_image(self, np_image):
"""Returns np_image encoded as jpeg or png."""
if np_image.dtype != np.uint8:
raise ValueError('Image should be uint8. Detected: %s.' % np_image.dtype)
utils.assert_shape_match(np_image.shape, self._shape)
return self._runner.run(ENCODE_FN[self._encoding_format],... | def _encode_image(self, np_image):
"""Returns np_image encoded as jpeg or png."""
if np_image.dtype != np.uint8:
raise ValueError('Image should be uint8. Detected: %s.' % np_image.dtype)
utils.assert_shape_match(np_image.shape, self._shape)
return self._runner.run(ENCODE_FN[self._encoding_format],... | [
"Returns",
"np_image",
"encoded",
"as",
"jpeg",
"or",
"png",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/features/image_feature.py#L128-L133 | [
"def",
"_encode_image",
"(",
"self",
",",
"np_image",
")",
":",
"if",
"np_image",
".",
"dtype",
"!=",
"np",
".",
"uint8",
":",
"raise",
"ValueError",
"(",
"'Image should be uint8. Detected: %s.'",
"%",
"np_image",
".",
"dtype",
")",
"utils",
".",
"assert_shape... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | Image.encode_example | Convert the given image into a dict convertible to tf example. | tensorflow_datasets/core/features/image_feature.py | def encode_example(self, image_or_path_or_fobj):
"""Convert the given image into a dict convertible to tf example."""
if isinstance(image_or_path_or_fobj, np.ndarray):
encoded_image = self._encode_image(image_or_path_or_fobj)
elif isinstance(image_or_path_or_fobj, six.string_types):
with tf.io.g... | def encode_example(self, image_or_path_or_fobj):
"""Convert the given image into a dict convertible to tf example."""
if isinstance(image_or_path_or_fobj, np.ndarray):
encoded_image = self._encode_image(image_or_path_or_fobj)
elif isinstance(image_or_path_or_fobj, six.string_types):
with tf.io.g... | [
"Convert",
"the",
"given",
"image",
"into",
"a",
"dict",
"convertible",
"to",
"tf",
"example",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/features/image_feature.py#L135-L144 | [
"def",
"encode_example",
"(",
"self",
",",
"image_or_path_or_fobj",
")",
":",
"if",
"isinstance",
"(",
"image_or_path_or_fobj",
",",
"np",
".",
"ndarray",
")",
":",
"encoded_image",
"=",
"self",
".",
"_encode_image",
"(",
"image_or_path_or_fobj",
")",
"elif",
"i... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | Image.decode_example | Reconstruct the image from the tf example. | tensorflow_datasets/core/features/image_feature.py | def decode_example(self, example):
"""Reconstruct the image from the tf example."""
img = tf.image.decode_image(
example, channels=self._shape[-1], dtype=tf.uint8)
img.set_shape(self._shape)
return img | def decode_example(self, example):
"""Reconstruct the image from the tf example."""
img = tf.image.decode_image(
example, channels=self._shape[-1], dtype=tf.uint8)
img.set_shape(self._shape)
return img | [
"Reconstruct",
"the",
"image",
"from",
"the",
"tf",
"example",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/features/image_feature.py#L146-L151 | [
"def",
"decode_example",
"(",
"self",
",",
"example",
")",
":",
"img",
"=",
"tf",
".",
"image",
".",
"decode_image",
"(",
"example",
",",
"channels",
"=",
"self",
".",
"_shape",
"[",
"-",
"1",
"]",
",",
"dtype",
"=",
"tf",
".",
"uint8",
")",
"img",... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | Image.save_metadata | See base class for details. | tensorflow_datasets/core/features/image_feature.py | def save_metadata(self, data_dir, feature_name=None):
"""See base class for details."""
filepath = _get_metadata_filepath(data_dir, feature_name)
with tf.io.gfile.GFile(filepath, 'w') as f:
json.dump({
'shape': [-1 if d is None else d for d in self._shape],
'encoding_format': self.... | def save_metadata(self, data_dir, feature_name=None):
"""See base class for details."""
filepath = _get_metadata_filepath(data_dir, feature_name)
with tf.io.gfile.GFile(filepath, 'w') as f:
json.dump({
'shape': [-1 if d is None else d for d in self._shape],
'encoding_format': self.... | [
"See",
"base",
"class",
"for",
"details",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/features/image_feature.py#L153-L160 | [
"def",
"save_metadata",
"(",
"self",
",",
"data_dir",
",",
"feature_name",
"=",
"None",
")",
":",
"filepath",
"=",
"_get_metadata_filepath",
"(",
"data_dir",
",",
"feature_name",
")",
"with",
"tf",
".",
"io",
".",
"gfile",
".",
"GFile",
"(",
"filepath",
",... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | Image.load_metadata | See base class for details. | tensorflow_datasets/core/features/image_feature.py | def load_metadata(self, data_dir, feature_name=None):
"""See base class for details."""
# Restore names if defined
filepath = _get_metadata_filepath(data_dir, feature_name)
if tf.io.gfile.exists(filepath):
with tf.io.gfile.GFile(filepath, 'r') as f:
info_data = json.load(f)
self.set_... | def load_metadata(self, data_dir, feature_name=None):
"""See base class for details."""
# Restore names if defined
filepath = _get_metadata_filepath(data_dir, feature_name)
if tf.io.gfile.exists(filepath):
with tf.io.gfile.GFile(filepath, 'r') as f:
info_data = json.load(f)
self.set_... | [
"See",
"base",
"class",
"for",
"details",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/features/image_feature.py#L162-L170 | [
"def",
"load_metadata",
"(",
"self",
",",
"data_dir",
",",
"feature_name",
"=",
"None",
")",
":",
"# Restore names if defined",
"filepath",
"=",
"_get_metadata_filepath",
"(",
"data_dir",
",",
"feature_name",
")",
"if",
"tf",
".",
"io",
".",
"gfile",
".",
"exi... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _create_moving_sequence | Create a moving image sequence from the given image a left padding values.
Args:
image: [in_h, in_w, n_channels] uint8 array
pad_lefts: [sequence_length, 2] int32 array of left padding values
total_padding: tensor of padding values, (pad_h, pad_w)
Returns:
[sequence_length, out_h, out_w, n_channel... | tensorflow_datasets/video/moving_sequence.py | def _create_moving_sequence(image, pad_lefts, total_padding):
"""Create a moving image sequence from the given image a left padding values.
Args:
image: [in_h, in_w, n_channels] uint8 array
pad_lefts: [sequence_length, 2] int32 array of left padding values
total_padding: tensor of padding values, (pad_... | def _create_moving_sequence(image, pad_lefts, total_padding):
"""Create a moving image sequence from the given image a left padding values.
Args:
image: [in_h, in_w, n_channels] uint8 array
pad_lefts: [sequence_length, 2] int32 array of left padding values
total_padding: tensor of padding values, (pad_... | [
"Create",
"a",
"moving",
"image",
"sequence",
"from",
"the",
"given",
"image",
"a",
"left",
"padding",
"values",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/video/moving_sequence.py#L27-L53 | [
"def",
"_create_moving_sequence",
"(",
"image",
",",
"pad_lefts",
",",
"total_padding",
")",
":",
"with",
"tf",
".",
"name_scope",
"(",
"\"moving_sequence\"",
")",
":",
"def",
"get_padded_image",
"(",
"args",
")",
":",
"pad_left",
",",
"=",
"args",
"pad_right"... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _get_linear_trajectory | Construct a linear trajectory from x0.
Args:
x0: N-D float tensor.
velocity: N-D float tensor
t: [sequence_length]-length float tensor
Returns:
x: [sequence_length, ndims] float tensor. | tensorflow_datasets/video/moving_sequence.py | def _get_linear_trajectory(x0, velocity, t):
"""Construct a linear trajectory from x0.
Args:
x0: N-D float tensor.
velocity: N-D float tensor
t: [sequence_length]-length float tensor
Returns:
x: [sequence_length, ndims] float tensor.
"""
x0 = tf.convert_to_tensor(x0)
velocity = tf.convert_... | def _get_linear_trajectory(x0, velocity, t):
"""Construct a linear trajectory from x0.
Args:
x0: N-D float tensor.
velocity: N-D float tensor
t: [sequence_length]-length float tensor
Returns:
x: [sequence_length, ndims] float tensor.
"""
x0 = tf.convert_to_tensor(x0)
velocity = tf.convert_... | [
"Construct",
"a",
"linear",
"trajectory",
"from",
"x0",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/video/moving_sequence.py#L56-L82 | [
"def",
"_get_linear_trajectory",
"(",
"x0",
",",
"velocity",
",",
"t",
")",
":",
"x0",
"=",
"tf",
".",
"convert_to_tensor",
"(",
"x0",
")",
"velocity",
"=",
"tf",
".",
"convert_to_tensor",
"(",
"velocity",
")",
"t",
"=",
"tf",
".",
"convert_to_tensor",
"... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | image_as_moving_sequence | Turn simple static images into sequences of the originals bouncing around.
Adapted from Srivastava et al.
http://www.cs.toronto.edu/~nitish/unsupervised_video/
Example usage:
```python
import tensorflow as tf
import tensorflow_datasets as tfds
from tensorflow_datasets.video import moving_sequence
tf.c... | tensorflow_datasets/video/moving_sequence.py | def image_as_moving_sequence(
image, sequence_length=20, output_size=(64, 64), velocity=0.1,
start_position=None):
"""Turn simple static images into sequences of the originals bouncing around.
Adapted from Srivastava et al.
http://www.cs.toronto.edu/~nitish/unsupervised_video/
Example usage:
```pyth... | def image_as_moving_sequence(
image, sequence_length=20, output_size=(64, 64), velocity=0.1,
start_position=None):
"""Turn simple static images into sequences of the originals bouncing around.
Adapted from Srivastava et al.
http://www.cs.toronto.edu/~nitish/unsupervised_video/
Example usage:
```pyth... | [
"Turn",
"simple",
"static",
"images",
"into",
"sequences",
"of",
"the",
"originals",
"bouncing",
"around",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/video/moving_sequence.py#L115-L234 | [
"def",
"image_as_moving_sequence",
"(",
"image",
",",
"sequence_length",
"=",
"20",
",",
"output_size",
"=",
"(",
"64",
",",
"64",
")",
",",
"velocity",
"=",
"0.1",
",",
"start_position",
"=",
"None",
")",
":",
"ndims",
"=",
"2",
"image",
"=",
"tf",
".... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | Nsynth._split_generators | Returns splits. | tensorflow_datasets/audio/nsynth.py | def _split_generators(self, dl_manager):
"""Returns splits."""
dl_urls = {
split: _BASE_DOWNLOAD_PATH + "%s.tfrecord" % split for split in _SPLITS
}
dl_urls["instrument_labels"] = (_BASE_DOWNLOAD_PATH +
"instrument_labels.txt")
dl_paths = dl_manager.downlo... | def _split_generators(self, dl_manager):
"""Returns splits."""
dl_urls = {
split: _BASE_DOWNLOAD_PATH + "%s.tfrecord" % split for split in _SPLITS
}
dl_urls["instrument_labels"] = (_BASE_DOWNLOAD_PATH +
"instrument_labels.txt")
dl_paths = dl_manager.downlo... | [
"Returns",
"splits",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/audio/nsynth.py#L117-L135 | [
"def",
"_split_generators",
"(",
"self",
",",
"dl_manager",
")",
":",
"dl_urls",
"=",
"{",
"split",
":",
"_BASE_DOWNLOAD_PATH",
"+",
"\"%s.tfrecord\"",
"%",
"split",
"for",
"split",
"in",
"_SPLITS",
"}",
"dl_urls",
"[",
"\"instrument_labels\"",
"]",
"=",
"(",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _str_to_version | Return the tuple (major, minor, patch) version extracted from the str. | tensorflow_datasets/core/utils/version.py | def _str_to_version(version_str, allow_wildcard=False):
"""Return the tuple (major, minor, patch) version extracted from the str."""
reg = _VERSION_WILDCARD_REG if allow_wildcard else _VERSION_RESOLVED_REG
res = reg.match(version_str)
if not res:
msg = "Invalid version '{}'. Format should be x.y.z".format(v... | def _str_to_version(version_str, allow_wildcard=False):
"""Return the tuple (major, minor, patch) version extracted from the str."""
reg = _VERSION_WILDCARD_REG if allow_wildcard else _VERSION_RESOLVED_REG
res = reg.match(version_str)
if not res:
msg = "Invalid version '{}'. Format should be x.y.z".format(v... | [
"Return",
"the",
"tuple",
"(",
"major",
"minor",
"patch",
")",
"version",
"extracted",
"from",
"the",
"str",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/utils/version.py#L70-L83 | [
"def",
"_str_to_version",
"(",
"version_str",
",",
"allow_wildcard",
"=",
"False",
")",
":",
"reg",
"=",
"_VERSION_WILDCARD_REG",
"if",
"allow_wildcard",
"else",
"_VERSION_RESOLVED_REG",
"res",
"=",
"reg",
".",
"match",
"(",
"version_str",
")",
"if",
"not",
"res... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | Version.match | Returns True if other_version matches.
Args:
other_version: string, of the form "x[.y[.x]]" where {x,y,z} can be a
number or a wildcard. | tensorflow_datasets/core/utils/version.py | def match(self, other_version):
"""Returns True if other_version matches.
Args:
other_version: string, of the form "x[.y[.x]]" where {x,y,z} can be a
number or a wildcard.
"""
major, minor, patch = _str_to_version(other_version, allow_wildcard=True)
return (major in [self.major, "*"] ... | def match(self, other_version):
"""Returns True if other_version matches.
Args:
other_version: string, of the form "x[.y[.x]]" where {x,y,z} can be a
number or a wildcard.
"""
major, minor, patch = _str_to_version(other_version, allow_wildcard=True)
return (major in [self.major, "*"] ... | [
"Returns",
"True",
"if",
"other_version",
"matches",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/utils/version.py#L58-L67 | [
"def",
"match",
"(",
"self",
",",
"other_version",
")",
":",
"major",
",",
"minor",
",",
"patch",
"=",
"_str_to_version",
"(",
"other_version",
",",
"allow_wildcard",
"=",
"True",
")",
"return",
"(",
"major",
"in",
"[",
"self",
".",
"major",
",",
"\"*\""... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | Imagenet2012._get_validation_labels | Returns labels for validation.
Args:
val_path: path to TAR file containing validation images. It is used to
retrieve the name of pictures and associate them to labels.
Returns:
dict, mapping from image name (str) to label (str). | tensorflow_datasets/image/imagenet.py | def _get_validation_labels(val_path):
"""Returns labels for validation.
Args:
val_path: path to TAR file containing validation images. It is used to
retrieve the name of pictures and associate them to labels.
Returns:
dict, mapping from image name (str) to label (str).
"""
labels... | def _get_validation_labels(val_path):
"""Returns labels for validation.
Args:
val_path: path to TAR file containing validation images. It is used to
retrieve the name of pictures and associate them to labels.
Returns:
dict, mapping from image name (str) to label (str).
"""
labels... | [
"Returns",
"labels",
"for",
"validation",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/imagenet.py#L86-L102 | [
"def",
"_get_validation_labels",
"(",
"val_path",
")",
":",
"labels_path",
"=",
"tfds",
".",
"core",
".",
"get_tfds_path",
"(",
"_VALIDATION_LABELS_FNAME",
")",
"with",
"tf",
".",
"io",
".",
"gfile",
".",
"GFile",
"(",
"labels_path",
")",
"as",
"labels_f",
"... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | Imagenet2012._generate_examples | Yields examples. | tensorflow_datasets/image/imagenet.py | def _generate_examples(self, archive, validation_labels=None):
"""Yields examples."""
if validation_labels: # Validation split
for example in self._generate_examples_validation(archive,
validation_labels):
yield example
# Training split.... | def _generate_examples(self, archive, validation_labels=None):
"""Yields examples."""
if validation_labels: # Validation split
for example in self._generate_examples_validation(archive,
validation_labels):
yield example
# Training split.... | [
"Yields",
"examples",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/imagenet.py#L131-L151 | [
"def",
"_generate_examples",
"(",
"self",
",",
"archive",
",",
"validation_labels",
"=",
"None",
")",
":",
"if",
"validation_labels",
":",
"# Validation split",
"for",
"example",
"in",
"self",
".",
"_generate_examples_validation",
"(",
"archive",
",",
"validation_la... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | do_files_exist | Whether any of the filenames exist. | tensorflow_datasets/core/file_format_adapter.py | def do_files_exist(filenames):
"""Whether any of the filenames exist."""
preexisting = [tf.io.gfile.exists(f) for f in filenames]
return any(preexisting) | def do_files_exist(filenames):
"""Whether any of the filenames exist."""
preexisting = [tf.io.gfile.exists(f) for f in filenames]
return any(preexisting) | [
"Whether",
"any",
"of",
"the",
"filenames",
"exist",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/file_format_adapter.py#L194-L197 | [
"def",
"do_files_exist",
"(",
"filenames",
")",
":",
"preexisting",
"=",
"[",
"tf",
".",
"io",
".",
"gfile",
".",
"exists",
"(",
"f",
")",
"for",
"f",
"in",
"filenames",
"]",
"return",
"any",
"(",
"preexisting",
")"
] | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | get_incomplete_path | Returns a temporary filename based on filename. | tensorflow_datasets/core/file_format_adapter.py | def get_incomplete_path(filename):
"""Returns a temporary filename based on filename."""
random_suffix = "".join(
random.choice(string.ascii_uppercase + string.digits) for _ in range(6))
return filename + ".incomplete" + random_suffix | def get_incomplete_path(filename):
"""Returns a temporary filename based on filename."""
random_suffix = "".join(
random.choice(string.ascii_uppercase + string.digits) for _ in range(6))
return filename + ".incomplete" + random_suffix | [
"Returns",
"a",
"temporary",
"filename",
"based",
"on",
"filename",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/file_format_adapter.py#L210-L214 | [
"def",
"get_incomplete_path",
"(",
"filename",
")",
":",
"random_suffix",
"=",
"\"\"",
".",
"join",
"(",
"random",
".",
"choice",
"(",
"string",
".",
"ascii_uppercase",
"+",
"string",
".",
"digits",
")",
"for",
"_",
"in",
"range",
"(",
"6",
")",
")",
"... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _incomplete_files | Create temporary files for filenames and rename on exit. | tensorflow_datasets/core/file_format_adapter.py | def _incomplete_files(filenames):
"""Create temporary files for filenames and rename on exit."""
tmp_files = [get_incomplete_path(f) for f in filenames]
try:
yield tmp_files
for tmp, output in zip(tmp_files, filenames):
tf.io.gfile.rename(tmp, output)
finally:
for tmp in tmp_files:
if tf... | def _incomplete_files(filenames):
"""Create temporary files for filenames and rename on exit."""
tmp_files = [get_incomplete_path(f) for f in filenames]
try:
yield tmp_files
for tmp, output in zip(tmp_files, filenames):
tf.io.gfile.rename(tmp, output)
finally:
for tmp in tmp_files:
if tf... | [
"Create",
"temporary",
"files",
"for",
"filenames",
"and",
"rename",
"on",
"exit",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/file_format_adapter.py#L218-L228 | [
"def",
"_incomplete_files",
"(",
"filenames",
")",
":",
"tmp_files",
"=",
"[",
"get_incomplete_path",
"(",
"f",
")",
"for",
"f",
"in",
"filenames",
"]",
"try",
":",
"yield",
"tmp_files",
"for",
"tmp",
",",
"output",
"in",
"zip",
"(",
"tmp_files",
",",
"f... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | incomplete_dir | Create temporary dir for dirname and rename on exit. | tensorflow_datasets/core/file_format_adapter.py | def incomplete_dir(dirname):
"""Create temporary dir for dirname and rename on exit."""
tmp_dir = get_incomplete_path(dirname)
tf.io.gfile.makedirs(tmp_dir)
try:
yield tmp_dir
tf.io.gfile.rename(tmp_dir, dirname)
finally:
if tf.io.gfile.exists(tmp_dir):
tf.io.gfile.rmtree(tmp_dir) | def incomplete_dir(dirname):
"""Create temporary dir for dirname and rename on exit."""
tmp_dir = get_incomplete_path(dirname)
tf.io.gfile.makedirs(tmp_dir)
try:
yield tmp_dir
tf.io.gfile.rename(tmp_dir, dirname)
finally:
if tf.io.gfile.exists(tmp_dir):
tf.io.gfile.rmtree(tmp_dir) | [
"Create",
"temporary",
"dir",
"for",
"dirname",
"and",
"rename",
"on",
"exit",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/file_format_adapter.py#L232-L241 | [
"def",
"incomplete_dir",
"(",
"dirname",
")",
":",
"tmp_dir",
"=",
"get_incomplete_path",
"(",
"dirname",
")",
"tf",
".",
"io",
".",
"gfile",
".",
"makedirs",
"(",
"tmp_dir",
")",
"try",
":",
"yield",
"tmp_dir",
"tf",
".",
"io",
".",
"gfile",
".",
"ren... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _shuffle_tfrecord | Shuffle a single record file in memory. | tensorflow_datasets/core/file_format_adapter.py | def _shuffle_tfrecord(path, random_gen):
"""Shuffle a single record file in memory."""
# Read all records
record_iter = tf.compat.v1.io.tf_record_iterator(path)
all_records = [
r for r in utils.tqdm(
record_iter, desc="Reading...", unit=" examples", leave=False)
]
# Shuffling in memory
ran... | def _shuffle_tfrecord(path, random_gen):
"""Shuffle a single record file in memory."""
# Read all records
record_iter = tf.compat.v1.io.tf_record_iterator(path)
all_records = [
r for r in utils.tqdm(
record_iter, desc="Reading...", unit=" examples", leave=False)
]
# Shuffling in memory
ran... | [
"Shuffle",
"a",
"single",
"record",
"file",
"in",
"memory",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/file_format_adapter.py#L244-L258 | [
"def",
"_shuffle_tfrecord",
"(",
"path",
",",
"random_gen",
")",
":",
"# Read all records",
"record_iter",
"=",
"tf",
".",
"compat",
".",
"v1",
".",
"io",
".",
"tf_record_iterator",
"(",
"path",
")",
"all_records",
"=",
"[",
"r",
"for",
"r",
"in",
"utils",... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _write_tfrecords_from_generator | Writes generated str records to output_files in round-robin order. | tensorflow_datasets/core/file_format_adapter.py | def _write_tfrecords_from_generator(generator, output_files, shuffle=True):
"""Writes generated str records to output_files in round-robin order."""
if do_files_exist(output_files):
raise ValueError(
"Pre-processed files already exists: {}.".format(output_files))
with _incomplete_files(output_files) ... | def _write_tfrecords_from_generator(generator, output_files, shuffle=True):
"""Writes generated str records to output_files in round-robin order."""
if do_files_exist(output_files):
raise ValueError(
"Pre-processed files already exists: {}.".format(output_files))
with _incomplete_files(output_files) ... | [
"Writes",
"generated",
"str",
"records",
"to",
"output_files",
"in",
"round",
"-",
"robin",
"order",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/file_format_adapter.py#L261-L281 | [
"def",
"_write_tfrecords_from_generator",
"(",
"generator",
",",
"output_files",
",",
"shuffle",
"=",
"True",
")",
":",
"if",
"do_files_exist",
"(",
"output_files",
")",
":",
"raise",
"ValueError",
"(",
"\"Pre-processed files already exists: {}.\"",
".",
"format",
"("... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _round_robin_write | Write records from generator round-robin across writers. | tensorflow_datasets/core/file_format_adapter.py | def _round_robin_write(writers, generator):
"""Write records from generator round-robin across writers."""
for i, example in enumerate(utils.tqdm(
generator, unit=" examples", leave=False)):
writers[i % len(writers)].write(example) | def _round_robin_write(writers, generator):
"""Write records from generator round-robin across writers."""
for i, example in enumerate(utils.tqdm(
generator, unit=" examples", leave=False)):
writers[i % len(writers)].write(example) | [
"Write",
"records",
"from",
"generator",
"round",
"-",
"robin",
"across",
"writers",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/file_format_adapter.py#L284-L288 | [
"def",
"_round_robin_write",
"(",
"writers",
",",
"generator",
")",
":",
"for",
"i",
",",
"example",
"in",
"enumerate",
"(",
"utils",
".",
"tqdm",
"(",
"generator",
",",
"unit",
"=",
"\" examples\"",
",",
"leave",
"=",
"False",
")",
")",
":",
"writers",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _item_to_tf_feature | Single item to a tf.train.Feature. | tensorflow_datasets/core/file_format_adapter.py | def _item_to_tf_feature(item, key_name):
"""Single item to a tf.train.Feature."""
v = item
if isinstance(v, (list, tuple)) and not v:
raise ValueError(
"Feature {} received an empty list value, so is unable to infer the "
"feature type to record. To support empty value, the corresponding "
... | def _item_to_tf_feature(item, key_name):
"""Single item to a tf.train.Feature."""
v = item
if isinstance(v, (list, tuple)) and not v:
raise ValueError(
"Feature {} received an empty list value, so is unable to infer the "
"feature type to record. To support empty value, the corresponding "
... | [
"Single",
"item",
"to",
"a",
"tf",
".",
"train",
".",
"Feature",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/file_format_adapter.py#L307-L344 | [
"def",
"_item_to_tf_feature",
"(",
"item",
",",
"key_name",
")",
":",
"v",
"=",
"item",
"if",
"isinstance",
"(",
"v",
",",
"(",
"list",
",",
"tuple",
")",
")",
"and",
"not",
"v",
":",
"raise",
"ValueError",
"(",
"\"Feature {} received an empty list value, so... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _dict_to_tf_features | Builds tf.train.Features from (string -> int/float/str list) dictionary. | tensorflow_datasets/core/file_format_adapter.py | def _dict_to_tf_features(example_dict):
"""Builds tf.train.Features from (string -> int/float/str list) dictionary."""
features = {k: _item_to_tf_feature(v, k) for k, v
in six.iteritems(example_dict)}
return tf.train.Features(feature=features) | def _dict_to_tf_features(example_dict):
"""Builds tf.train.Features from (string -> int/float/str list) dictionary."""
features = {k: _item_to_tf_feature(v, k) for k, v
in six.iteritems(example_dict)}
return tf.train.Features(feature=features) | [
"Builds",
"tf",
".",
"train",
".",
"Features",
"from",
"(",
"string",
"-",
">",
"int",
"/",
"float",
"/",
"str",
"list",
")",
"dictionary",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/file_format_adapter.py#L347-L351 | [
"def",
"_dict_to_tf_features",
"(",
"example_dict",
")",
":",
"features",
"=",
"{",
"k",
":",
"_item_to_tf_feature",
"(",
"v",
",",
"k",
")",
"for",
"k",
",",
"v",
"in",
"six",
".",
"iteritems",
"(",
"example_dict",
")",
"}",
"return",
"tf",
".",
"trai... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _async_tqdm | Wrapper around Tqdm which can be updated in threads.
Usage:
```
with utils.async_tqdm(...) as pbar:
# pbar can then be modified inside a thread
# pbar.update_total(3)
# pbar.update()
```
Args:
*args: args of tqdm
**kwargs: kwargs of tqdm
Yields:
pbar: Async pbar which can be shar... | tensorflow_datasets/core/utils/tqdm_utils.py | def _async_tqdm(*args, **kwargs):
"""Wrapper around Tqdm which can be updated in threads.
Usage:
```
with utils.async_tqdm(...) as pbar:
# pbar can then be modified inside a thread
# pbar.update_total(3)
# pbar.update()
```
Args:
*args: args of tqdm
**kwargs: kwargs of tqdm
Yields:... | def _async_tqdm(*args, **kwargs):
"""Wrapper around Tqdm which can be updated in threads.
Usage:
```
with utils.async_tqdm(...) as pbar:
# pbar can then be modified inside a thread
# pbar.update_total(3)
# pbar.update()
```
Args:
*args: args of tqdm
**kwargs: kwargs of tqdm
Yields:... | [
"Wrapper",
"around",
"Tqdm",
"which",
"can",
"be",
"updated",
"in",
"threads",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/utils/tqdm_utils.py#L79-L102 | [
"def",
"_async_tqdm",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"with",
"tqdm_lib",
".",
"tqdm",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"as",
"pbar",
":",
"pbar",
"=",
"_TqdmPbarAsync",
"(",
"pbar",
")",
"yield",
"pbar",
"pbar",... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _TqdmPbarAsync.update_total | Increment total pbar value. | tensorflow_datasets/core/utils/tqdm_utils.py | def update_total(self, n=1):
"""Increment total pbar value."""
with self._lock:
self._pbar.total += n
self.refresh() | def update_total(self, n=1):
"""Increment total pbar value."""
with self._lock:
self._pbar.total += n
self.refresh() | [
"Increment",
"total",
"pbar",
"value",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/utils/tqdm_utils.py#L114-L118 | [
"def",
"update_total",
"(",
"self",
",",
"n",
"=",
"1",
")",
":",
"with",
"self",
".",
"_lock",
":",
"self",
".",
"_pbar",
".",
"total",
"+=",
"n",
"self",
".",
"refresh",
"(",
")"
] | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _TqdmPbarAsync.update | Increment current value. | tensorflow_datasets/core/utils/tqdm_utils.py | def update(self, n=1):
"""Increment current value."""
with self._lock:
self._pbar.update(n)
self.refresh() | def update(self, n=1):
"""Increment current value."""
with self._lock:
self._pbar.update(n)
self.refresh() | [
"Increment",
"current",
"value",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/utils/tqdm_utils.py#L120-L124 | [
"def",
"update",
"(",
"self",
",",
"n",
"=",
"1",
")",
":",
"with",
"self",
".",
"_lock",
":",
"self",
".",
"_pbar",
".",
"update",
"(",
"n",
")",
"self",
".",
"refresh",
"(",
")"
] | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | AbstractReasoning._build_pcollection | Generate examples as dicts. | tensorflow_datasets/image/abstract_reasoning.py | def _build_pcollection(self, pipeline, folder, split):
"""Generate examples as dicts."""
beam = tfds.core.lazy_imports.apache_beam
split_type = self.builder_config.split_type
filename = os.path.join(folder, "{}.tar.gz".format(split_type))
def _extract_data(inputs):
"""Extracts files from th... | def _build_pcollection(self, pipeline, folder, split):
"""Generate examples as dicts."""
beam = tfds.core.lazy_imports.apache_beam
split_type = self.builder_config.split_type
filename = os.path.join(folder, "{}.tar.gz".format(split_type))
def _extract_data(inputs):
"""Extracts files from th... | [
"Generate",
"examples",
"as",
"dicts",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/image/abstract_reasoning.py#L250-L305 | [
"def",
"_build_pcollection",
"(",
"self",
",",
"pipeline",
",",
"folder",
",",
"split",
")",
":",
"beam",
"=",
"tfds",
".",
"core",
".",
"lazy_imports",
".",
"apache_beam",
"split_type",
"=",
"self",
".",
"builder_config",
".",
"split_type",
"filename",
"=",... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _copy | Copy data read from src file obj to new file in dest_path. | tensorflow_datasets/core/download/extractor.py | def _copy(src_file, dest_path):
"""Copy data read from src file obj to new file in dest_path."""
tf.io.gfile.makedirs(os.path.dirname(dest_path))
with tf.io.gfile.GFile(dest_path, 'wb') as dest_file:
while True:
data = src_file.read(io.DEFAULT_BUFFER_SIZE)
if not data:
break
dest_fil... | def _copy(src_file, dest_path):
"""Copy data read from src file obj to new file in dest_path."""
tf.io.gfile.makedirs(os.path.dirname(dest_path))
with tf.io.gfile.GFile(dest_path, 'wb') as dest_file:
while True:
data = src_file.read(io.DEFAULT_BUFFER_SIZE)
if not data:
break
dest_fil... | [
"Copy",
"data",
"read",
"from",
"src",
"file",
"obj",
"to",
"new",
"file",
"in",
"dest_path",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/download/extractor.py#L103-L111 | [
"def",
"_copy",
"(",
"src_file",
",",
"dest_path",
")",
":",
"tf",
".",
"io",
".",
"gfile",
".",
"makedirs",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"dest_path",
")",
")",
"with",
"tf",
".",
"io",
".",
"gfile",
".",
"GFile",
"(",
"dest_path",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | iter_tar | Iter over tar archive, yielding (path, object-like) tuples.
Args:
arch_f: File object of the archive to iterate.
gz: If True, open a gzip'ed archive.
stream: If True, open the archive in stream mode which allows for faster
processing and less temporary disk consumption, but random access to the
... | tensorflow_datasets/core/download/extractor.py | def iter_tar(arch_f, gz=False, stream=False):
"""Iter over tar archive, yielding (path, object-like) tuples.
Args:
arch_f: File object of the archive to iterate.
gz: If True, open a gzip'ed archive.
stream: If True, open the archive in stream mode which allows for faster
processing and less tempo... | def iter_tar(arch_f, gz=False, stream=False):
"""Iter over tar archive, yielding (path, object-like) tuples.
Args:
arch_f: File object of the archive to iterate.
gz: If True, open a gzip'ed archive.
stream: If True, open the archive in stream mode which allows for faster
processing and less tempo... | [
"Iter",
"over",
"tar",
"archive",
"yielding",
"(",
"path",
"object",
"-",
"like",
")",
"tuples",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/download/extractor.py#L133-L158 | [
"def",
"iter_tar",
"(",
"arch_f",
",",
"gz",
"=",
"False",
",",
"stream",
"=",
"False",
")",
":",
"read_type",
"=",
"'r'",
"+",
"(",
"'|'",
"if",
"stream",
"else",
"':'",
")",
"if",
"gz",
":",
"read_type",
"+=",
"'gz'",
"with",
"_open_or_pass",
"(",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _Extractor.tqdm | Add a progression bar for the current extraction. | tensorflow_datasets/core/download/extractor.py | def tqdm(self):
"""Add a progression bar for the current extraction."""
with utils.async_tqdm(
total=0, desc='Extraction completed...', unit=' file') as pbar_path:
self._pbar_path = pbar_path
yield | def tqdm(self):
"""Add a progression bar for the current extraction."""
with utils.async_tqdm(
total=0, desc='Extraction completed...', unit=' file') as pbar_path:
self._pbar_path = pbar_path
yield | [
"Add",
"a",
"progression",
"bar",
"for",
"the",
"current",
"extraction",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/download/extractor.py#L68-L73 | [
"def",
"tqdm",
"(",
"self",
")",
":",
"with",
"utils",
".",
"async_tqdm",
"(",
"total",
"=",
"0",
",",
"desc",
"=",
"'Extraction completed...'",
",",
"unit",
"=",
"' file'",
")",
"as",
"pbar_path",
":",
"self",
".",
"_pbar_path",
"=",
"pbar_path",
"yield... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _Extractor.extract | Returns `promise.Promise` => to_path. | tensorflow_datasets/core/download/extractor.py | def extract(self, path, extract_method, to_path):
"""Returns `promise.Promise` => to_path."""
self._pbar_path.update_total(1)
if extract_method not in _EXTRACT_METHODS:
raise ValueError('Unknown extraction method "%s".' % extract_method)
future = self._executor.submit(self._sync_extract,
... | def extract(self, path, extract_method, to_path):
"""Returns `promise.Promise` => to_path."""
self._pbar_path.update_total(1)
if extract_method not in _EXTRACT_METHODS:
raise ValueError('Unknown extraction method "%s".' % extract_method)
future = self._executor.submit(self._sync_extract,
... | [
"Returns",
"promise",
".",
"Promise",
"=",
">",
"to_path",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/download/extractor.py#L75-L82 | [
"def",
"extract",
"(",
"self",
",",
"path",
",",
"extract_method",
",",
"to_path",
")",
":",
"self",
".",
"_pbar_path",
".",
"update_total",
"(",
"1",
")",
"if",
"extract_method",
"not",
"in",
"_EXTRACT_METHODS",
":",
"raise",
"ValueError",
"(",
"'Unknown ex... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _Extractor._sync_extract | Returns `to_path` once resource has been extracted there. | tensorflow_datasets/core/download/extractor.py | def _sync_extract(self, from_path, method, to_path):
"""Returns `to_path` once resource has been extracted there."""
to_path_tmp = '%s%s_%s' % (to_path, constants.INCOMPLETE_SUFFIX,
uuid.uuid4().hex)
try:
for path, handle in iter_archive(from_path, method):
_copy... | def _sync_extract(self, from_path, method, to_path):
"""Returns `to_path` once resource has been extracted there."""
to_path_tmp = '%s%s_%s' % (to_path, constants.INCOMPLETE_SUFFIX,
uuid.uuid4().hex)
try:
for path, handle in iter_archive(from_path, method):
_copy... | [
"Returns",
"to_path",
"once",
"resource",
"has",
"been",
"extracted",
"there",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/download/extractor.py#L84-L100 | [
"def",
"_sync_extract",
"(",
"self",
",",
"from_path",
",",
"method",
",",
"to_path",
")",
":",
"to_path_tmp",
"=",
"'%s%s_%s'",
"%",
"(",
"to_path",
",",
"constants",
".",
"INCOMPLETE_SUFFIX",
",",
"uuid",
".",
"uuid4",
"(",
")",
".",
"hex",
")",
"try",... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | to_serialized_field | Convert a `TensorInfo` object into a feature proto object. | tensorflow_datasets/core/features/feature.py | def to_serialized_field(tensor_info):
"""Convert a `TensorInfo` object into a feature proto object."""
# Select the type
dtype = tensor_info.dtype
# TODO(b/119937875): TF Examples proto only support int64, float32 and string
# This create limitation like float64 downsampled to float32, bool converted
# to ... | def to_serialized_field(tensor_info):
"""Convert a `TensorInfo` object into a feature proto object."""
# Select the type
dtype = tensor_info.dtype
# TODO(b/119937875): TF Examples proto only support int64, float32 and string
# This create limitation like float64 downsampled to float32, bool converted
# to ... | [
"Convert",
"a",
"TensorInfo",
"object",
"into",
"a",
"feature",
"proto",
"object",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/features/feature.py#L576-L612 | [
"def",
"to_serialized_field",
"(",
"tensor_info",
")",
":",
"# Select the type",
"dtype",
"=",
"tensor_info",
".",
"dtype",
"# TODO(b/119937875): TF Examples proto only support int64, float32 and string",
"# This create limitation like float64 downsampled to float32, bool converted",
"# ... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | to_feature | Convert the given value to Feature if necessary. | tensorflow_datasets/core/features/feature.py | def to_feature(value):
"""Convert the given value to Feature if necessary."""
if isinstance(value, FeatureConnector):
return value
elif utils.is_dtype(value): # tf.int32, tf.string,...
return Tensor(shape=(), dtype=tf.as_dtype(value))
elif isinstance(value, dict):
return FeaturesDict(value)
else:... | def to_feature(value):
"""Convert the given value to Feature if necessary."""
if isinstance(value, FeatureConnector):
return value
elif utils.is_dtype(value): # tf.int32, tf.string,...
return Tensor(shape=(), dtype=tf.as_dtype(value))
elif isinstance(value, dict):
return FeaturesDict(value)
else:... | [
"Convert",
"the",
"given",
"value",
"to",
"Feature",
"if",
"necessary",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/features/feature.py#L615-L624 | [
"def",
"to_feature",
"(",
"value",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"FeatureConnector",
")",
":",
"return",
"value",
"elif",
"utils",
".",
"is_dtype",
"(",
"value",
")",
":",
"# tf.int32, tf.string,...",
"return",
"Tensor",
"(",
"shape",
"=",... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | decode_single_feature_from_dict | Decode the given feature from the tfexample_dict.
Args:
feature_k (str): Feature key in the tfexample_dict
feature (FeatureConnector): Connector object to use to decode the field
tfexample_dict (dict): Dict containing the data to decode.
Returns:
decoded_feature: The output of the feature.decode_e... | tensorflow_datasets/core/features/feature.py | def decode_single_feature_from_dict(
feature_k,
feature,
tfexample_dict):
"""Decode the given feature from the tfexample_dict.
Args:
feature_k (str): Feature key in the tfexample_dict
feature (FeatureConnector): Connector object to use to decode the field
tfexample_dict (dict): Dict contain... | def decode_single_feature_from_dict(
feature_k,
feature,
tfexample_dict):
"""Decode the given feature from the tfexample_dict.
Args:
feature_k (str): Feature key in the tfexample_dict
feature (FeatureConnector): Connector object to use to decode the field
tfexample_dict (dict): Dict contain... | [
"Decode",
"the",
"given",
"feature",
"from",
"the",
"tfexample_dict",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/features/feature.py#L627-L651 | [
"def",
"decode_single_feature_from_dict",
"(",
"feature_k",
",",
"feature",
",",
"tfexample_dict",
")",
":",
"# Singleton case",
"if",
"not",
"feature",
".",
"serialized_keys",
":",
"data_to_decode",
"=",
"tfexample_dict",
"[",
"feature_k",
"]",
"# Feature contains sub ... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | _assert_keys_match | Ensure the two list of keys matches. | tensorflow_datasets/core/features/feature.py | def _assert_keys_match(keys1, keys2):
"""Ensure the two list of keys matches."""
if set(keys1) != set(keys2):
raise ValueError('{} {}'.format(list(keys1), list(keys2))) | def _assert_keys_match(keys1, keys2):
"""Ensure the two list of keys matches."""
if set(keys1) != set(keys2):
raise ValueError('{} {}'.format(list(keys1), list(keys2))) | [
"Ensure",
"the",
"two",
"list",
"of",
"keys",
"matches",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/features/feature.py#L654-L657 | [
"def",
"_assert_keys_match",
"(",
"keys1",
",",
"keys2",
")",
":",
"if",
"set",
"(",
"keys1",
")",
"!=",
"set",
"(",
"keys2",
")",
":",
"raise",
"ValueError",
"(",
"'{} {}'",
".",
"format",
"(",
"list",
"(",
"keys1",
")",
",",
"list",
"(",
"keys2",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | FeaturesDict.get_tensor_info | See base class for details. | tensorflow_datasets/core/features/feature.py | def get_tensor_info(self):
"""See base class for details."""
return {
feature_key: feature.get_tensor_info()
for feature_key, feature in self._feature_dict.items()
} | def get_tensor_info(self):
"""See base class for details."""
return {
feature_key: feature.get_tensor_info()
for feature_key, feature in self._feature_dict.items()
} | [
"See",
"base",
"class",
"for",
"details",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/features/feature.py#L437-L442 | [
"def",
"get_tensor_info",
"(",
"self",
")",
":",
"return",
"{",
"feature_key",
":",
"feature",
".",
"get_tensor_info",
"(",
")",
"for",
"feature_key",
",",
"feature",
"in",
"self",
".",
"_feature_dict",
".",
"items",
"(",
")",
"}"
] | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | FeaturesDict.get_serialized_info | See base class for details. | tensorflow_datasets/core/features/feature.py | def get_serialized_info(self):
"""See base class for details."""
# Flatten tf-example features dict
# Use NonMutableDict to ensure there is no collision between features keys
features_dict = utils.NonMutableDict()
for feature_key, feature in self._feature_dict.items():
serialized_info = featur... | def get_serialized_info(self):
"""See base class for details."""
# Flatten tf-example features dict
# Use NonMutableDict to ensure there is no collision between features keys
features_dict = utils.NonMutableDict()
for feature_key, feature in self._feature_dict.items():
serialized_info = featur... | [
"See",
"base",
"class",
"for",
"details",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/features/feature.py#L444-L466 | [
"def",
"get_serialized_info",
"(",
"self",
")",
":",
"# Flatten tf-example features dict",
"# Use NonMutableDict to ensure there is no collision between features keys",
"features_dict",
"=",
"utils",
".",
"NonMutableDict",
"(",
")",
"for",
"feature_key",
",",
"feature",
"in",
... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | FeaturesDict.encode_example | See base class for details. | tensorflow_datasets/core/features/feature.py | def encode_example(self, example_dict):
"""See base class for details."""
# Flatten dict matching the tf-example features
# Use NonMutableDict to ensure there is no collision between features keys
tfexample_dict = utils.NonMutableDict()
# Iterate over example fields
for feature_key, (feature, e... | def encode_example(self, example_dict):
"""See base class for details."""
# Flatten dict matching the tf-example features
# Use NonMutableDict to ensure there is no collision between features keys
tfexample_dict = utils.NonMutableDict()
# Iterate over example fields
for feature_key, (feature, e... | [
"See",
"base",
"class",
"for",
"details",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/features/feature.py#L468-L490 | [
"def",
"encode_example",
"(",
"self",
",",
"example_dict",
")",
":",
"# Flatten dict matching the tf-example features",
"# Use NonMutableDict to ensure there is no collision between features keys",
"tfexample_dict",
"=",
"utils",
".",
"NonMutableDict",
"(",
")",
"# Iterate over exa... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
train | FeaturesDict.decode_example | See base class for details. | tensorflow_datasets/core/features/feature.py | def decode_example(self, tfexample_dict):
"""See base class for details."""
tensor_dict = {}
# Iterate over the Tensor dict keys
for feature_key, feature in six.iteritems(self._feature_dict):
decoded_feature = decode_single_feature_from_dict(
feature_k=feature_key,
feature=feat... | def decode_example(self, tfexample_dict):
"""See base class for details."""
tensor_dict = {}
# Iterate over the Tensor dict keys
for feature_key, feature in six.iteritems(self._feature_dict):
decoded_feature = decode_single_feature_from_dict(
feature_k=feature_key,
feature=feat... | [
"See",
"base",
"class",
"for",
"details",
"."
] | tensorflow/datasets | python | https://github.com/tensorflow/datasets/blob/46ceb0cf7b4690f38ecbbc689e4d659a903d08dc/tensorflow_datasets/core/features/feature.py#L492-L503 | [
"def",
"decode_example",
"(",
"self",
",",
"tfexample_dict",
")",
":",
"tensor_dict",
"=",
"{",
"}",
"# Iterate over the Tensor dict keys",
"for",
"feature_key",
",",
"feature",
"in",
"six",
".",
"iteritems",
"(",
"self",
".",
"_feature_dict",
")",
":",
"decoded... | 46ceb0cf7b4690f38ecbbc689e4d659a903d08dc |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.