id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
28,400 | googleapis/google-cloud-python | firestore/google/cloud/firestore_v1beta1/gapic/firestore_client.py | FirestoreClient.begin_transaction | def begin_transaction(
self,
database,
options_=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Starts a new transaction.
Example:
>>> from google.cloud im... | python | def begin_transaction(
self,
database,
options_=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Starts a new transaction.
Example:
>>> from google.cloud im... | [
"def",
"begin_transaction",
"(",
"self",
",",
"database",
",",
"options_",
"=",
"None",
",",
"retry",
"=",
"google",
".",
"api_core",
".",
"gapic_v1",
".",
"method",
".",
"DEFAULT",
",",
"timeout",
"=",
"google",
".",
"api_core",
".",
"gapic_v1",
".",
"m... | Starts a new transaction.
Example:
>>> from google.cloud import firestore_v1beta1
>>>
>>> client = firestore_v1beta1.FirestoreClient()
>>>
>>> database = client.database_root_path('[PROJECT]', '[DATABASE]')
>>>
>>> response = c... | [
"Starts",
"a",
"new",
"transaction",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/firestore/google/cloud/firestore_v1beta1/gapic/firestore_client.py#L866-L942 |
28,401 | googleapis/google-cloud-python | firestore/google/cloud/firestore_v1beta1/gapic/firestore_client.py | FirestoreClient.run_query | def run_query(
self,
parent,
structured_query=None,
transaction=None,
new_transaction=None,
read_time=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Ru... | python | def run_query(
self,
parent,
structured_query=None,
transaction=None,
new_transaction=None,
read_time=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Ru... | [
"def",
"run_query",
"(",
"self",
",",
"parent",
",",
"structured_query",
"=",
"None",
",",
"transaction",
"=",
"None",
",",
"new_transaction",
"=",
"None",
",",
"read_time",
"=",
"None",
",",
"retry",
"=",
"google",
".",
"api_core",
".",
"gapic_v1",
".",
... | Runs a query.
Example:
>>> from google.cloud import firestore_v1beta1
>>>
>>> client = firestore_v1beta1.FirestoreClient()
>>>
>>> parent = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', '[ANY_PATH]')
>>>
>>> for... | [
"Runs",
"a",
"query",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/firestore/google/cloud/firestore_v1beta1/gapic/firestore_client.py#L1102-L1214 |
28,402 | googleapis/google-cloud-python | firestore/google/cloud/firestore_v1beta1/gapic/firestore_client.py | FirestoreClient.write | def write(
self,
requests,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Streams batches of document updates and deletes, in order.
EXPERIMENTAL: This method interface might chang... | python | def write(
self,
requests,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Streams batches of document updates and deletes, in order.
EXPERIMENTAL: This method interface might chang... | [
"def",
"write",
"(",
"self",
",",
"requests",
",",
"retry",
"=",
"google",
".",
"api_core",
".",
"gapic_v1",
".",
"method",
".",
"DEFAULT",
",",
"timeout",
"=",
"google",
".",
"api_core",
".",
"gapic_v1",
".",
"method",
".",
"DEFAULT",
",",
"metadata",
... | Streams batches of document updates and deletes, in order.
EXPERIMENTAL: This method interface might change in the future.
Example:
>>> from google.cloud import firestore_v1beta1
>>>
>>> client = firestore_v1beta1.FirestoreClient()
>>>
>>> da... | [
"Streams",
"batches",
"of",
"document",
"updates",
"and",
"deletes",
"in",
"order",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/firestore/google/cloud/firestore_v1beta1/gapic/firestore_client.py#L1216-L1276 |
28,403 | googleapis/google-cloud-python | logging/google/cloud/logging_v2/gapic/logging_service_v2_client.py | LoggingServiceV2Client.log_path | def log_path(cls, project, log):
"""Return a fully-qualified log string."""
return google.api_core.path_template.expand(
"projects/{project}/logs/{log}", project=project, log=log
) | python | def log_path(cls, project, log):
"""Return a fully-qualified log string."""
return google.api_core.path_template.expand(
"projects/{project}/logs/{log}", project=project, log=log
) | [
"def",
"log_path",
"(",
"cls",
",",
"project",
",",
"log",
")",
":",
"return",
"google",
".",
"api_core",
".",
"path_template",
".",
"expand",
"(",
"\"projects/{project}/logs/{log}\"",
",",
"project",
"=",
"project",
",",
"log",
"=",
"log",
")"
] | Return a fully-qualified log string. | [
"Return",
"a",
"fully",
"-",
"qualified",
"log",
"string",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/logging/google/cloud/logging_v2/gapic/logging_service_v2_client.py#L75-L79 |
28,404 | googleapis/google-cloud-python | logging/google/cloud/logging_v2/gapic/logging_service_v2_client.py | LoggingServiceV2Client.delete_log | def delete_log(
self,
log_name,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Deletes all the log entries in a log.
The log reappears if it receives new entries.
Log entrie... | python | def delete_log(
self,
log_name,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Deletes all the log entries in a log.
The log reappears if it receives new entries.
Log entrie... | [
"def",
"delete_log",
"(",
"self",
",",
"log_name",
",",
"retry",
"=",
"google",
".",
"api_core",
".",
"gapic_v1",
".",
"method",
".",
"DEFAULT",
",",
"timeout",
"=",
"google",
".",
"api_core",
".",
"gapic_v1",
".",
"method",
".",
"DEFAULT",
",",
"metadat... | Deletes all the log entries in a log.
The log reappears if it receives new entries.
Log entries written shortly before the delete operation might not be
deleted.
Example:
>>> from google.cloud import logging_v2
>>>
>>> client = logging_v2.LoggingServi... | [
"Deletes",
"all",
"the",
"log",
"entries",
"in",
"a",
"log",
".",
"The",
"log",
"reappears",
"if",
"it",
"receives",
"new",
"entries",
".",
"Log",
"entries",
"written",
"shortly",
"before",
"the",
"delete",
"operation",
"might",
"not",
"be",
"deleted",
"."... | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/logging/google/cloud/logging_v2/gapic/logging_service_v2_client.py#L187-L266 |
28,405 | googleapis/google-cloud-python | api_core/google/api_core/path_template.py | _expand_variable_match | def _expand_variable_match(positional_vars, named_vars, match):
"""Expand a matched variable with its value.
Args:
positional_vars (list): A list of positonal variables. This list will
be modified.
named_vars (dict): A dictionary of named variables.
match (re.Match): A regul... | python | def _expand_variable_match(positional_vars, named_vars, match):
"""Expand a matched variable with its value.
Args:
positional_vars (list): A list of positonal variables. This list will
be modified.
named_vars (dict): A dictionary of named variables.
match (re.Match): A regul... | [
"def",
"_expand_variable_match",
"(",
"positional_vars",
",",
"named_vars",
",",
"match",
")",
":",
"positional",
"=",
"match",
".",
"group",
"(",
"\"positional\"",
")",
"name",
"=",
"match",
".",
"group",
"(",
"\"name\"",
")",
"if",
"name",
"is",
"not",
"... | Expand a matched variable with its value.
Args:
positional_vars (list): A list of positonal variables. This list will
be modified.
named_vars (dict): A dictionary of named variables.
match (re.Match): A regular expression match.
Returns:
str: The expanded variable t... | [
"Expand",
"a",
"matched",
"variable",
"with",
"its",
"value",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/api_core/google/api_core/path_template.py#L65-L101 |
28,406 | googleapis/google-cloud-python | api_core/google/api_core/path_template.py | expand | def expand(tmpl, *args, **kwargs):
"""Expand a path template with the given variables.
..code-block:: python
>>> expand('users/*/messages/*', 'me', '123')
users/me/messages/123
>>> expand('/v1/{name=shelves/*/books/*}', name='shelves/1/books/3')
/v1/shelves/1/books/3
Args:... | python | def expand(tmpl, *args, **kwargs):
"""Expand a path template with the given variables.
..code-block:: python
>>> expand('users/*/messages/*', 'me', '123')
users/me/messages/123
>>> expand('/v1/{name=shelves/*/books/*}', name='shelves/1/books/3')
/v1/shelves/1/books/3
Args:... | [
"def",
"expand",
"(",
"tmpl",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"replacer",
"=",
"functools",
".",
"partial",
"(",
"_expand_variable_match",
",",
"list",
"(",
"args",
")",
",",
"kwargs",
")",
"return",
"_VARIABLE_RE",
".",
"sub",
"("... | Expand a path template with the given variables.
..code-block:: python
>>> expand('users/*/messages/*', 'me', '123')
users/me/messages/123
>>> expand('/v1/{name=shelves/*/books/*}', name='shelves/1/books/3')
/v1/shelves/1/books/3
Args:
tmpl (str): The path template.
... | [
"Expand",
"a",
"path",
"template",
"with",
"the",
"given",
"variables",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/api_core/google/api_core/path_template.py#L104-L128 |
28,407 | googleapis/google-cloud-python | api_core/google/api_core/path_template.py | _replace_variable_with_pattern | def _replace_variable_with_pattern(match):
"""Replace a variable match with a pattern that can be used to validate it.
Args:
match (re.Match): A regular expression match
Returns:
str: A regular expression pattern that can be used to validate the
variable in an expanded path.
... | python | def _replace_variable_with_pattern(match):
"""Replace a variable match with a pattern that can be used to validate it.
Args:
match (re.Match): A regular expression match
Returns:
str: A regular expression pattern that can be used to validate the
variable in an expanded path.
... | [
"def",
"_replace_variable_with_pattern",
"(",
"match",
")",
":",
"positional",
"=",
"match",
".",
"group",
"(",
"\"positional\"",
")",
"name",
"=",
"match",
".",
"group",
"(",
"\"name\"",
")",
"template",
"=",
"match",
".",
"group",
"(",
"\"template\"",
")",... | Replace a variable match with a pattern that can be used to validate it.
Args:
match (re.Match): A regular expression match
Returns:
str: A regular expression pattern that can be used to validate the
variable in an expanded path.
Raises:
ValueError: If an unexpected te... | [
"Replace",
"a",
"variable",
"match",
"with",
"a",
"pattern",
"that",
"can",
"be",
"used",
"to",
"validate",
"it",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/api_core/google/api_core/path_template.py#L131-L159 |
28,408 | googleapis/google-cloud-python | api_core/google/api_core/path_template.py | validate | def validate(tmpl, path):
"""Validate a path against the path template.
.. code-block:: python
>>> validate('users/*/messages/*', 'users/me/messages/123')
True
>>> validate('users/*/messages/*', 'users/me/drafts/123')
False
>>> validate('/v1/{name=shelves/*/books/*}', /... | python | def validate(tmpl, path):
"""Validate a path against the path template.
.. code-block:: python
>>> validate('users/*/messages/*', 'users/me/messages/123')
True
>>> validate('users/*/messages/*', 'users/me/drafts/123')
False
>>> validate('/v1/{name=shelves/*/books/*}', /... | [
"def",
"validate",
"(",
"tmpl",
",",
"path",
")",
":",
"pattern",
"=",
"_generate_pattern_for_template",
"(",
"tmpl",
")",
"+",
"\"$\"",
"return",
"True",
"if",
"re",
".",
"match",
"(",
"pattern",
",",
"path",
")",
"is",
"not",
"None",
"else",
"False"
] | Validate a path against the path template.
.. code-block:: python
>>> validate('users/*/messages/*', 'users/me/messages/123')
True
>>> validate('users/*/messages/*', 'users/me/drafts/123')
False
>>> validate('/v1/{name=shelves/*/books/*}', /v1/shelves/1/books/3)
Tru... | [
"Validate",
"a",
"path",
"against",
"the",
"path",
"template",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/api_core/google/api_core/path_template.py#L175-L197 |
28,409 | googleapis/google-cloud-python | bigtable/google/cloud/bigtable/app_profile.py | AppProfile.name | def name(self):
"""AppProfile name used in requests.
.. note::
This property will not change if ``app_profile_id`` does not, but
the return value is not cached.
The AppProfile name is of the form
``"projects/../instances/../app_profile/{app_profile_id}"``
... | python | def name(self):
"""AppProfile name used in requests.
.. note::
This property will not change if ``app_profile_id`` does not, but
the return value is not cached.
The AppProfile name is of the form
``"projects/../instances/../app_profile/{app_profile_id}"``
... | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"instance_admin_client",
".",
"app_profile_path",
"(",
"self",
".",
"_instance",
".",
"_client",
".",
"project",
",",
"self",
".",
"_instance",
".",
"instance_id",
",",
"self",
".",
"app_profile_id... | AppProfile name used in requests.
.. note::
This property will not change if ``app_profile_id`` does not, but
the return value is not cached.
The AppProfile name is of the form
``"projects/../instances/../app_profile/{app_profile_id}"``
:rtype: str
:re... | [
"AppProfile",
"name",
"used",
"in",
"requests",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/bigtable/google/cloud/bigtable/app_profile.py#L85-L103 |
28,410 | googleapis/google-cloud-python | bigtable/google/cloud/bigtable/app_profile.py | AppProfile.from_pb | def from_pb(cls, app_profile_pb, instance):
"""Creates an instance app_profile from a protobuf.
:type app_profile_pb: :class:`instance_pb2.app_profile_pb`
:param app_profile_pb: An instance protobuf object.
:type instance: :class:`google.cloud.bigtable.instance.Instance`
:param... | python | def from_pb(cls, app_profile_pb, instance):
"""Creates an instance app_profile from a protobuf.
:type app_profile_pb: :class:`instance_pb2.app_profile_pb`
:param app_profile_pb: An instance protobuf object.
:type instance: :class:`google.cloud.bigtable.instance.Instance`
:param... | [
"def",
"from_pb",
"(",
"cls",
",",
"app_profile_pb",
",",
"instance",
")",
":",
"match_app_profile_name",
"=",
"_APP_PROFILE_NAME_RE",
".",
"match",
"(",
"app_profile_pb",
".",
"name",
")",
"if",
"match_app_profile_name",
"is",
"None",
":",
"raise",
"ValueError",
... | Creates an instance app_profile from a protobuf.
:type app_profile_pb: :class:`instance_pb2.app_profile_pb`
:param app_profile_pb: An instance protobuf object.
:type instance: :class:`google.cloud.bigtable.instance.Instance`
:param instance: The instance that owns the cluster.
... | [
"Creates",
"an",
"instance",
"app_profile",
"from",
"a",
"protobuf",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/bigtable/google/cloud/bigtable/app_profile.py#L131-L171 |
28,411 | googleapis/google-cloud-python | bigtable/google/cloud/bigtable/app_profile.py | AppProfile.reload | def reload(self):
"""Reload the metadata for this cluster"""
app_profile_pb = self.instance_admin_client.get_app_profile(self.name)
# NOTE: _update_from_pb does not check that the project and
# app_profile ID on the response match the request.
self._update_from_pb(app_pro... | python | def reload(self):
"""Reload the metadata for this cluster"""
app_profile_pb = self.instance_admin_client.get_app_profile(self.name)
# NOTE: _update_from_pb does not check that the project and
# app_profile ID on the response match the request.
self._update_from_pb(app_pro... | [
"def",
"reload",
"(",
"self",
")",
":",
"app_profile_pb",
"=",
"self",
".",
"instance_admin_client",
".",
"get_app_profile",
"(",
"self",
".",
"name",
")",
"# NOTE: _update_from_pb does not check that the project and",
"# app_profile ID on the response match the request."... | Reload the metadata for this cluster | [
"Reload",
"the",
"metadata",
"for",
"this",
"cluster"
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/bigtable/google/cloud/bigtable/app_profile.py#L227-L234 |
28,412 | googleapis/google-cloud-python | bigtable/google/cloud/bigtable/app_profile.py | AppProfile.exists | def exists(self):
"""Check whether the AppProfile already exists.
:rtype: bool
:returns: True if the AppProfile exists, else False.
"""
try:
self.instance_admin_client.get_app_profile(self.name)
return True
# NOTE: There could be other exceptions ... | python | def exists(self):
"""Check whether the AppProfile already exists.
:rtype: bool
:returns: True if the AppProfile exists, else False.
"""
try:
self.instance_admin_client.get_app_profile(self.name)
return True
# NOTE: There could be other exceptions ... | [
"def",
"exists",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"instance_admin_client",
".",
"get_app_profile",
"(",
"self",
".",
"name",
")",
"return",
"True",
"# NOTE: There could be other exceptions that are returned to the user.",
"except",
"NotFound",
":",
"ret... | Check whether the AppProfile already exists.
:rtype: bool
:returns: True if the AppProfile exists, else False. | [
"Check",
"whether",
"the",
"AppProfile",
"already",
"exists",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/bigtable/google/cloud/bigtable/app_profile.py#L236-L247 |
28,413 | googleapis/google-cloud-python | bigtable/google/cloud/bigtable/app_profile.py | AppProfile.create | def create(self, ignore_warnings=None):
"""Create this AppProfile.
.. note::
Uses the ``instance`` and ``app_profile_id`` on the current
:class:`AppProfile` in addition to the ``routing_policy_type``,
``description``, ``cluster_id`` and ``allow_transactional_writes`... | python | def create(self, ignore_warnings=None):
"""Create this AppProfile.
.. note::
Uses the ``instance`` and ``app_profile_id`` on the current
:class:`AppProfile` in addition to the ``routing_policy_type``,
``description``, ``cluster_id`` and ``allow_transactional_writes`... | [
"def",
"create",
"(",
"self",
",",
"ignore_warnings",
"=",
"None",
")",
":",
"return",
"self",
".",
"from_pb",
"(",
"self",
".",
"instance_admin_client",
".",
"create_app_profile",
"(",
"parent",
"=",
"self",
".",
"_instance",
".",
"name",
",",
"app_profile_... | Create this AppProfile.
.. note::
Uses the ``instance`` and ``app_profile_id`` on the current
:class:`AppProfile` in addition to the ``routing_policy_type``,
``description``, ``cluster_id`` and ``allow_transactional_writes``.
To change them before creating, rese... | [
"Create",
"this",
"AppProfile",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/bigtable/google/cloud/bigtable/app_profile.py#L249-L283 |
28,414 | googleapis/google-cloud-python | bigtable/google/cloud/bigtable/app_profile.py | AppProfile.update | def update(self, ignore_warnings=None):
"""Update this app_profile.
.. note::
Update any or all of the following values:
``routing_policy_type``
``description``
``cluster_id``
``allow_transactional_writes``
"""
update_mask_pb... | python | def update(self, ignore_warnings=None):
"""Update this app_profile.
.. note::
Update any or all of the following values:
``routing_policy_type``
``description``
``cluster_id``
``allow_transactional_writes``
"""
update_mask_pb... | [
"def",
"update",
"(",
"self",
",",
"ignore_warnings",
"=",
"None",
")",
":",
"update_mask_pb",
"=",
"field_mask_pb2",
".",
"FieldMask",
"(",
")",
"if",
"self",
".",
"description",
"is",
"not",
"None",
":",
"update_mask_pb",
".",
"paths",
".",
"append",
"("... | Update this app_profile.
.. note::
Update any or all of the following values:
``routing_policy_type``
``description``
``cluster_id``
``allow_transactional_writes`` | [
"Update",
"this",
"app_profile",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/bigtable/google/cloud/bigtable/app_profile.py#L285-L311 |
28,415 | googleapis/google-cloud-python | logging/google/cloud/logging_v2/gapic/config_service_v2_client.py | ConfigServiceV2Client.sink_path | def sink_path(cls, project, sink):
"""Return a fully-qualified sink string."""
return google.api_core.path_template.expand(
"projects/{project}/sinks/{sink}", project=project, sink=sink
) | python | def sink_path(cls, project, sink):
"""Return a fully-qualified sink string."""
return google.api_core.path_template.expand(
"projects/{project}/sinks/{sink}", project=project, sink=sink
) | [
"def",
"sink_path",
"(",
"cls",
",",
"project",
",",
"sink",
")",
":",
"return",
"google",
".",
"api_core",
".",
"path_template",
".",
"expand",
"(",
"\"projects/{project}/sinks/{sink}\"",
",",
"project",
"=",
"project",
",",
"sink",
"=",
"sink",
")"
] | Return a fully-qualified sink string. | [
"Return",
"a",
"fully",
"-",
"qualified",
"sink",
"string",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/logging/google/cloud/logging_v2/gapic/config_service_v2_client.py#L88-L92 |
28,416 | googleapis/google-cloud-python | logging/google/cloud/logging_v2/gapic/config_service_v2_client.py | ConfigServiceV2Client.exclusion_path | def exclusion_path(cls, project, exclusion):
"""Return a fully-qualified exclusion string."""
return google.api_core.path_template.expand(
"projects/{project}/exclusions/{exclusion}",
project=project,
exclusion=exclusion,
) | python | def exclusion_path(cls, project, exclusion):
"""Return a fully-qualified exclusion string."""
return google.api_core.path_template.expand(
"projects/{project}/exclusions/{exclusion}",
project=project,
exclusion=exclusion,
) | [
"def",
"exclusion_path",
"(",
"cls",
",",
"project",
",",
"exclusion",
")",
":",
"return",
"google",
".",
"api_core",
".",
"path_template",
".",
"expand",
"(",
"\"projects/{project}/exclusions/{exclusion}\"",
",",
"project",
"=",
"project",
",",
"exclusion",
"=",
... | Return a fully-qualified exclusion string. | [
"Return",
"a",
"fully",
"-",
"qualified",
"exclusion",
"string",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/logging/google/cloud/logging_v2/gapic/config_service_v2_client.py#L95-L101 |
28,417 | googleapis/google-cloud-python | logging/google/cloud/logging_v2/gapic/config_service_v2_client.py | ConfigServiceV2Client.create_sink | def create_sink(
self,
parent,
sink,
unique_writer_identity=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Creates a sink that exports specified log entries to a desti... | python | def create_sink(
self,
parent,
sink,
unique_writer_identity=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Creates a sink that exports specified log entries to a desti... | [
"def",
"create_sink",
"(",
"self",
",",
"parent",
",",
"sink",
",",
"unique_writer_identity",
"=",
"None",
",",
"retry",
"=",
"google",
".",
"api_core",
".",
"gapic_v1",
".",
"method",
".",
"DEFAULT",
",",
"timeout",
"=",
"google",
".",
"api_core",
".",
... | Creates a sink that exports specified log entries to a destination. The
export of newly-ingested log entries begins immediately, unless the
sink's ``writer_identity`` is not permitted to write to the destination.
A sink can export log entries only from the resource owning the sink.
Exam... | [
"Creates",
"a",
"sink",
"that",
"exports",
"specified",
"log",
"entries",
"to",
"a",
"destination",
".",
"The",
"export",
"of",
"newly",
"-",
"ingested",
"log",
"entries",
"begins",
"immediately",
"unless",
"the",
"sink",
"s",
"writer_identity",
"is",
"not",
... | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/logging/google/cloud/logging_v2/gapic/config_service_v2_client.py#L390-L493 |
28,418 | googleapis/google-cloud-python | logging/google/cloud/logging_v2/gapic/config_service_v2_client.py | ConfigServiceV2Client.create_exclusion | def create_exclusion(
self,
parent,
exclusion,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Creates a new exclusion in a specified parent resource.
Only log entries belong... | python | def create_exclusion(
self,
parent,
exclusion,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Creates a new exclusion in a specified parent resource.
Only log entries belong... | [
"def",
"create_exclusion",
"(",
"self",
",",
"parent",
",",
"exclusion",
",",
"retry",
"=",
"google",
".",
"api_core",
".",
"gapic_v1",
".",
"method",
".",
"DEFAULT",
",",
"timeout",
"=",
"google",
".",
"api_core",
".",
"gapic_v1",
".",
"method",
".",
"D... | Creates a new exclusion in a specified parent resource.
Only log entries belonging to that resource can be excluded.
You can have up to 10 exclusions in a resource.
Example:
>>> from google.cloud import logging_v2
>>>
>>> client = logging_v2.ConfigServiceV2Cl... | [
"Creates",
"a",
"new",
"exclusion",
"in",
"a",
"specified",
"parent",
"resource",
".",
"Only",
"log",
"entries",
"belonging",
"to",
"that",
"resource",
"can",
"be",
"excluded",
".",
"You",
"can",
"have",
"up",
"to",
"10",
"exclusions",
"in",
"a",
"resource... | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/logging/google/cloud/logging_v2/gapic/config_service_v2_client.py#L886-L976 |
28,419 | googleapis/google-cloud-python | spanner/google/cloud/spanner_v1/_helpers.py | _parse_value_pb | def _parse_value_pb(value_pb, field_type):
"""Convert a Value protobuf to cell data.
:type value_pb: :class:`~google.protobuf.struct_pb2.Value`
:param value_pb: protobuf to convert
:type field_type: :class:`~google.cloud.spanner_v1.proto.type_pb2.Type`
:param field_type: type code for the value
... | python | def _parse_value_pb(value_pb, field_type):
"""Convert a Value protobuf to cell data.
:type value_pb: :class:`~google.protobuf.struct_pb2.Value`
:param value_pb: protobuf to convert
:type field_type: :class:`~google.cloud.spanner_v1.proto.type_pb2.Type`
:param field_type: type code for the value
... | [
"def",
"_parse_value_pb",
"(",
"value_pb",
",",
"field_type",
")",
":",
"if",
"value_pb",
".",
"HasField",
"(",
"\"null_value\"",
")",
":",
"return",
"None",
"if",
"field_type",
".",
"code",
"==",
"type_pb2",
".",
"STRING",
":",
"result",
"=",
"value_pb",
... | Convert a Value protobuf to cell data.
:type value_pb: :class:`~google.protobuf.struct_pb2.Value`
:param value_pb: protobuf to convert
:type field_type: :class:`~google.cloud.spanner_v1.proto.type_pb2.Type`
:param field_type: type code for the value
:rtype: varies on field_type
:returns: valu... | [
"Convert",
"a",
"Value",
"protobuf",
"to",
"cell",
"data",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/spanner/google/cloud/spanner_v1/_helpers.py#L122-L167 |
28,420 | googleapis/google-cloud-python | spanner/google/cloud/spanner_v1/_helpers.py | _parse_list_value_pbs | def _parse_list_value_pbs(rows, row_type):
"""Convert a list of ListValue protobufs into a list of list of cell data.
:type rows: list of :class:`~google.protobuf.struct_pb2.ListValue`
:param rows: row data returned from a read/query
:type row_type: :class:`~google.cloud.spanner_v1.proto.type_pb2.Stru... | python | def _parse_list_value_pbs(rows, row_type):
"""Convert a list of ListValue protobufs into a list of list of cell data.
:type rows: list of :class:`~google.protobuf.struct_pb2.ListValue`
:param rows: row data returned from a read/query
:type row_type: :class:`~google.cloud.spanner_v1.proto.type_pb2.Stru... | [
"def",
"_parse_list_value_pbs",
"(",
"rows",
",",
"row_type",
")",
":",
"result",
"=",
"[",
"]",
"for",
"row",
"in",
"rows",
":",
"row_data",
"=",
"[",
"]",
"for",
"value_pb",
",",
"field",
"in",
"zip",
"(",
"row",
".",
"values",
",",
"row_type",
"."... | Convert a list of ListValue protobufs into a list of list of cell data.
:type rows: list of :class:`~google.protobuf.struct_pb2.ListValue`
:param rows: row data returned from a read/query
:type row_type: :class:`~google.cloud.spanner_v1.proto.type_pb2.StructType`
:param row_type: row schema specificat... | [
"Convert",
"a",
"list",
"of",
"ListValue",
"protobufs",
"into",
"a",
"list",
"of",
"list",
"of",
"cell",
"data",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/spanner/google/cloud/spanner_v1/_helpers.py#L173-L191 |
28,421 | googleapis/google-cloud-python | asset/google/cloud/asset_v1/gapic/asset_service_client.py | AssetServiceClient.export_assets | def export_assets(
self,
parent,
output_config,
read_time=None,
asset_types=None,
content_type=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Exports a... | python | def export_assets(
self,
parent,
output_config,
read_time=None,
asset_types=None,
content_type=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Exports a... | [
"def",
"export_assets",
"(",
"self",
",",
"parent",
",",
"output_config",
",",
"read_time",
"=",
"None",
",",
"asset_types",
"=",
"None",
",",
"content_type",
"=",
"None",
",",
"retry",
"=",
"google",
".",
"api_core",
".",
"gapic_v1",
".",
"method",
".",
... | Exports assets with time and resource types to a given Cloud Storage
location. The output format is newline-delimited JSON. This API
implements the ``google.longrunning.Operation`` API allowing you to keep
track of the export.
Example:
>>> from google.cloud import asset_v1
... | [
"Exports",
"assets",
"with",
"time",
"and",
"resource",
"types",
"to",
"a",
"given",
"Cloud",
"Storage",
"location",
".",
"The",
"output",
"format",
"is",
"newline",
"-",
"delimited",
"JSON",
".",
"This",
"API",
"implements",
"the",
"google",
".",
"longrunni... | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/asset/google/cloud/asset_v1/gapic/asset_service_client.py#L179-L288 |
28,422 | googleapis/google-cloud-python | asset/google/cloud/asset_v1/gapic/asset_service_client.py | AssetServiceClient.batch_get_assets_history | def batch_get_assets_history(
self,
parent,
content_type,
read_time_window,
asset_names=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Batch gets the update hi... | python | def batch_get_assets_history(
self,
parent,
content_type,
read_time_window,
asset_names=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Batch gets the update hi... | [
"def",
"batch_get_assets_history",
"(",
"self",
",",
"parent",
",",
"content_type",
",",
"read_time_window",
",",
"asset_names",
"=",
"None",
",",
"retry",
"=",
"google",
".",
"api_core",
".",
"gapic_v1",
".",
"method",
".",
"DEFAULT",
",",
"timeout",
"=",
"... | Batch gets the update history of assets that overlap a time window. For
RESOURCE content, this API outputs history with asset in both non-delete
or deleted status. For IAM\_POLICY content, this API outputs history
when the asset and its attached IAM POLICY both exist. This can create
gap... | [
"Batch",
"gets",
"the",
"update",
"history",
"of",
"assets",
"that",
"overlap",
"a",
"time",
"window",
".",
"For",
"RESOURCE",
"content",
"this",
"API",
"outputs",
"history",
"with",
"asset",
"in",
"both",
"non",
"-",
"delete",
"or",
"deleted",
"status",
"... | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/asset/google/cloud/asset_v1/gapic/asset_service_client.py#L290-L387 |
28,423 | googleapis/google-cloud-python | bigquery_storage/google/cloud/bigquery_storage_v1beta1/reader.py | _avro_schema | def _avro_schema(read_session):
"""Extract and parse Avro schema from a read session.
Args:
read_session ( \
~google.cloud.bigquery_storage_v1beta1.types.ReadSession \
):
The read session associated with this read rows stream. This
contains the schema, which ... | python | def _avro_schema(read_session):
"""Extract and parse Avro schema from a read session.
Args:
read_session ( \
~google.cloud.bigquery_storage_v1beta1.types.ReadSession \
):
The read session associated with this read rows stream. This
contains the schema, which ... | [
"def",
"_avro_schema",
"(",
"read_session",
")",
":",
"json_schema",
"=",
"json",
".",
"loads",
"(",
"read_session",
".",
"avro_schema",
".",
"schema",
")",
"column_names",
"=",
"tuple",
"(",
"(",
"field",
"[",
"\"name\"",
"]",
"for",
"field",
"in",
"json_... | Extract and parse Avro schema from a read session.
Args:
read_session ( \
~google.cloud.bigquery_storage_v1beta1.types.ReadSession \
):
The read session associated with this read rows stream. This
contains the schema, which is required to parse the data
... | [
"Extract",
"and",
"parse",
"Avro",
"schema",
"from",
"a",
"read",
"session",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/bigquery_storage/google/cloud/bigquery_storage_v1beta1/reader.py#L375-L393 |
28,424 | googleapis/google-cloud-python | bigquery_storage/google/cloud/bigquery_storage_v1beta1/reader.py | _avro_rows | def _avro_rows(block, avro_schema):
"""Parse all rows in a stream block.
Args:
block ( \
~google.cloud.bigquery_storage_v1beta1.types.ReadRowsResponse \
):
A block containing Avro bytes to parse into rows.
avro_schema (fastavro.schema):
A parsed Avro ... | python | def _avro_rows(block, avro_schema):
"""Parse all rows in a stream block.
Args:
block ( \
~google.cloud.bigquery_storage_v1beta1.types.ReadRowsResponse \
):
A block containing Avro bytes to parse into rows.
avro_schema (fastavro.schema):
A parsed Avro ... | [
"def",
"_avro_rows",
"(",
"block",
",",
"avro_schema",
")",
":",
"blockio",
"=",
"six",
".",
"BytesIO",
"(",
"block",
".",
"avro_rows",
".",
"serialized_binary_rows",
")",
"while",
"True",
":",
"# Loop in a while loop because schemaless_reader can only read",
"# a sin... | Parse all rows in a stream block.
Args:
block ( \
~google.cloud.bigquery_storage_v1beta1.types.ReadRowsResponse \
):
A block containing Avro bytes to parse into rows.
avro_schema (fastavro.schema):
A parsed Avro schema, used to deserialized the bytes in t... | [
"Parse",
"all",
"rows",
"in",
"a",
"stream",
"block",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/bigquery_storage/google/cloud/bigquery_storage_v1beta1/reader.py#L396-L421 |
28,425 | googleapis/google-cloud-python | bigquery_storage/google/cloud/bigquery_storage_v1beta1/reader.py | _copy_stream_position | def _copy_stream_position(position):
"""Copy a StreamPosition.
Args:
position (Union[ \
dict, \
~google.cloud.bigquery_storage_v1beta1.types.StreamPosition \
]):
StreamPostion (or dictionary in StreamPosition format) to copy.
Returns:
~google.clo... | python | def _copy_stream_position(position):
"""Copy a StreamPosition.
Args:
position (Union[ \
dict, \
~google.cloud.bigquery_storage_v1beta1.types.StreamPosition \
]):
StreamPostion (or dictionary in StreamPosition format) to copy.
Returns:
~google.clo... | [
"def",
"_copy_stream_position",
"(",
"position",
")",
":",
"if",
"isinstance",
"(",
"position",
",",
"types",
".",
"StreamPosition",
")",
":",
"output",
"=",
"types",
".",
"StreamPosition",
"(",
")",
"output",
".",
"CopyFrom",
"(",
"position",
")",
"return",... | Copy a StreamPosition.
Args:
position (Union[ \
dict, \
~google.cloud.bigquery_storage_v1beta1.types.StreamPosition \
]):
StreamPostion (or dictionary in StreamPosition format) to copy.
Returns:
~google.cloud.bigquery_storage_v1beta1.types.StreamPosi... | [
"Copy",
"a",
"StreamPosition",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/bigquery_storage/google/cloud/bigquery_storage_v1beta1/reader.py#L424-L443 |
28,426 | googleapis/google-cloud-python | bigquery_storage/google/cloud/bigquery_storage_v1beta1/reader.py | ReadRowsStream._reconnect | def _reconnect(self):
"""Reconnect to the ReadRows stream using the most recent offset."""
self._wrapped = self._client.read_rows(
_copy_stream_position(self._position), **self._read_rows_kwargs
) | python | def _reconnect(self):
"""Reconnect to the ReadRows stream using the most recent offset."""
self._wrapped = self._client.read_rows(
_copy_stream_position(self._position), **self._read_rows_kwargs
) | [
"def",
"_reconnect",
"(",
"self",
")",
":",
"self",
".",
"_wrapped",
"=",
"self",
".",
"_client",
".",
"read_rows",
"(",
"_copy_stream_position",
"(",
"self",
".",
"_position",
")",
",",
"*",
"*",
"self",
".",
"_read_rows_kwargs",
")"
] | Reconnect to the ReadRows stream using the most recent offset. | [
"Reconnect",
"to",
"the",
"ReadRows",
"stream",
"using",
"the",
"most",
"recent",
"offset",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/bigquery_storage/google/cloud/bigquery_storage_v1beta1/reader.py#L128-L132 |
28,427 | googleapis/google-cloud-python | bigquery_storage/google/cloud/bigquery_storage_v1beta1/reader.py | ReadRowsIterable.pages | def pages(self):
"""A generator of all pages in the stream.
Returns:
types.GeneratorType[google.cloud.bigquery_storage_v1beta1.ReadRowsPage]:
A generator of pages.
"""
# Each page is an iterator of rows. But also has num_items, remaining,
# and to_dat... | python | def pages(self):
"""A generator of all pages in the stream.
Returns:
types.GeneratorType[google.cloud.bigquery_storage_v1beta1.ReadRowsPage]:
A generator of pages.
"""
# Each page is an iterator of rows. But also has num_items, remaining,
# and to_dat... | [
"def",
"pages",
"(",
"self",
")",
":",
"# Each page is an iterator of rows. But also has num_items, remaining,",
"# and to_dataframe.",
"avro_schema",
",",
"column_names",
"=",
"_avro_schema",
"(",
"self",
".",
"_read_session",
")",
"for",
"block",
"in",
"self",
".",
"_... | A generator of all pages in the stream.
Returns:
types.GeneratorType[google.cloud.bigquery_storage_v1beta1.ReadRowsPage]:
A generator of pages. | [
"A",
"generator",
"of",
"all",
"pages",
"in",
"the",
"stream",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/bigquery_storage/google/cloud/bigquery_storage_v1beta1/reader.py#L226-L238 |
28,428 | googleapis/google-cloud-python | bigquery_storage/google/cloud/bigquery_storage_v1beta1/reader.py | ReadRowsPage._parse_block | def _parse_block(self):
"""Parse metadata and rows from the block only once."""
if self._iter_rows is not None:
return
rows = _avro_rows(self._block, self._avro_schema)
self._num_items = self._block.avro_rows.row_count
self._remaining = self._block.avro_rows.row_coun... | python | def _parse_block(self):
"""Parse metadata and rows from the block only once."""
if self._iter_rows is not None:
return
rows = _avro_rows(self._block, self._avro_schema)
self._num_items = self._block.avro_rows.row_count
self._remaining = self._block.avro_rows.row_coun... | [
"def",
"_parse_block",
"(",
"self",
")",
":",
"if",
"self",
".",
"_iter_rows",
"is",
"not",
"None",
":",
"return",
"rows",
"=",
"_avro_rows",
"(",
"self",
".",
"_block",
",",
"self",
".",
"_avro_schema",
")",
"self",
".",
"_num_items",
"=",
"self",
"."... | Parse metadata and rows from the block only once. | [
"Parse",
"metadata",
"and",
"rows",
"from",
"the",
"block",
"only",
"once",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/bigquery_storage/google/cloud/bigquery_storage_v1beta1/reader.py#L301-L309 |
28,429 | googleapis/google-cloud-python | bigquery_storage/google/cloud/bigquery_storage_v1beta1/reader.py | ReadRowsPage.next | def next(self):
"""Get the next row in the page."""
self._parse_block()
if self._remaining > 0:
self._remaining -= 1
return six.next(self._iter_rows) | python | def next(self):
"""Get the next row in the page."""
self._parse_block()
if self._remaining > 0:
self._remaining -= 1
return six.next(self._iter_rows) | [
"def",
"next",
"(",
"self",
")",
":",
"self",
".",
"_parse_block",
"(",
")",
"if",
"self",
".",
"_remaining",
">",
"0",
":",
"self",
".",
"_remaining",
"-=",
"1",
"return",
"six",
".",
"next",
"(",
"self",
".",
"_iter_rows",
")"
] | Get the next row in the page. | [
"Get",
"the",
"next",
"row",
"in",
"the",
"page",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/bigquery_storage/google/cloud/bigquery_storage_v1beta1/reader.py#L327-L332 |
28,430 | googleapis/google-cloud-python | spanner/google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py | InstanceAdminClient.instance_config_path | def instance_config_path(cls, project, instance_config):
"""Return a fully-qualified instance_config string."""
return google.api_core.path_template.expand(
"projects/{project}/instanceConfigs/{instance_config}",
project=project,
instance_config=instance_config,
... | python | def instance_config_path(cls, project, instance_config):
"""Return a fully-qualified instance_config string."""
return google.api_core.path_template.expand(
"projects/{project}/instanceConfigs/{instance_config}",
project=project,
instance_config=instance_config,
... | [
"def",
"instance_config_path",
"(",
"cls",
",",
"project",
",",
"instance_config",
")",
":",
"return",
"google",
".",
"api_core",
".",
"path_template",
".",
"expand",
"(",
"\"projects/{project}/instanceConfigs/{instance_config}\"",
",",
"project",
"=",
"project",
",",... | Return a fully-qualified instance_config string. | [
"Return",
"a",
"fully",
"-",
"qualified",
"instance_config",
"string",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/spanner/google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py#L110-L116 |
28,431 | googleapis/google-cloud-python | spanner/google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py | InstanceAdminClient.create_instance | def create_instance(
self,
parent,
instance_id,
instance,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Creates an instance and begins preparing it to begin serving. The
... | python | def create_instance(
self,
parent,
instance_id,
instance,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Creates an instance and begins preparing it to begin serving. The
... | [
"def",
"create_instance",
"(",
"self",
",",
"parent",
",",
"instance_id",
",",
"instance",
",",
"retry",
"=",
"google",
".",
"api_core",
".",
"gapic_v1",
".",
"method",
".",
"DEFAULT",
",",
"timeout",
"=",
"google",
".",
"api_core",
".",
"gapic_v1",
".",
... | Creates an instance and begins preparing it to begin serving. The
returned ``long-running operation`` can be used to track the progress of
preparing the new instance. The instance name is assigned by the caller.
If the named instance already exists, ``CreateInstance`` returns
``ALREADY_E... | [
"Creates",
"an",
"instance",
"and",
"begins",
"preparing",
"it",
"to",
"begin",
"serving",
".",
"The",
"returned",
"long",
"-",
"running",
"operation",
"can",
"be",
"used",
"to",
"track",
"the",
"progress",
"of",
"preparing",
"the",
"new",
"instance",
".",
... | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/spanner/google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py#L594-L725 |
28,432 | googleapis/google-cloud-python | spanner/google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py | InstanceAdminClient.update_instance | def update_instance(
self,
instance,
field_mask,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Updates an instance, and begins allocating or releasing resources as
requeste... | python | def update_instance(
self,
instance,
field_mask,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Updates an instance, and begins allocating or releasing resources as
requeste... | [
"def",
"update_instance",
"(",
"self",
",",
"instance",
",",
"field_mask",
",",
"retry",
"=",
"google",
".",
"api_core",
".",
"gapic_v1",
".",
"method",
".",
"DEFAULT",
",",
"timeout",
"=",
"google",
".",
"api_core",
".",
"gapic_v1",
".",
"method",
".",
... | Updates an instance, and begins allocating or releasing resources as
requested. The returned ``long-running operation`` can be used to track
the progress of updating the instance. If the named instance does not
exist, returns ``NOT_FOUND``.
Immediately upon completion of this request:
... | [
"Updates",
"an",
"instance",
"and",
"begins",
"allocating",
"or",
"releasing",
"resources",
"as",
"requested",
".",
"The",
"returned",
"long",
"-",
"running",
"operation",
"can",
"be",
"used",
"to",
"track",
"the",
"progress",
"of",
"updating",
"the",
"instanc... | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/spanner/google/cloud/spanner_admin_instance_v1/gapic/instance_admin_client.py#L727-L866 |
28,433 | googleapis/google-cloud-python | websecurityscanner/google/cloud/websecurityscanner_v1alpha/gapic/web_security_scanner_client.py | WebSecurityScannerClient.scan_config_path | def scan_config_path(cls, project, scan_config):
"""Return a fully-qualified scan_config string."""
return google.api_core.path_template.expand(
"projects/{project}/scanConfigs/{scan_config}",
project=project,
scan_config=scan_config,
) | python | def scan_config_path(cls, project, scan_config):
"""Return a fully-qualified scan_config string."""
return google.api_core.path_template.expand(
"projects/{project}/scanConfigs/{scan_config}",
project=project,
scan_config=scan_config,
) | [
"def",
"scan_config_path",
"(",
"cls",
",",
"project",
",",
"scan_config",
")",
":",
"return",
"google",
".",
"api_core",
".",
"path_template",
".",
"expand",
"(",
"\"projects/{project}/scanConfigs/{scan_config}\"",
",",
"project",
"=",
"project",
",",
"scan_config"... | Return a fully-qualified scan_config string. | [
"Return",
"a",
"fully",
"-",
"qualified",
"scan_config",
"string",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/websecurityscanner/google/cloud/websecurityscanner_v1alpha/gapic/web_security_scanner_client.py#L105-L111 |
28,434 | googleapis/google-cloud-python | websecurityscanner/google/cloud/websecurityscanner_v1alpha/gapic/web_security_scanner_client.py | WebSecurityScannerClient.scan_run_path | def scan_run_path(cls, project, scan_config, scan_run):
"""Return a fully-qualified scan_run string."""
return google.api_core.path_template.expand(
"projects/{project}/scanConfigs/{scan_config}/scanRuns/{scan_run}",
project=project,
scan_config=scan_config,
... | python | def scan_run_path(cls, project, scan_config, scan_run):
"""Return a fully-qualified scan_run string."""
return google.api_core.path_template.expand(
"projects/{project}/scanConfigs/{scan_config}/scanRuns/{scan_run}",
project=project,
scan_config=scan_config,
... | [
"def",
"scan_run_path",
"(",
"cls",
",",
"project",
",",
"scan_config",
",",
"scan_run",
")",
":",
"return",
"google",
".",
"api_core",
".",
"path_template",
".",
"expand",
"(",
"\"projects/{project}/scanConfigs/{scan_config}/scanRuns/{scan_run}\"",
",",
"project",
"=... | Return a fully-qualified scan_run string. | [
"Return",
"a",
"fully",
"-",
"qualified",
"scan_run",
"string",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/websecurityscanner/google/cloud/websecurityscanner_v1alpha/gapic/web_security_scanner_client.py#L114-L121 |
28,435 | googleapis/google-cloud-python | spanner/google/cloud/spanner_v1/client.py | Client.copy | def copy(self):
"""Make a copy of this client.
Copies the local data stored as simple types but does not copy the
current state of any open connections with the Cloud Bigtable API.
:rtype: :class:`.Client`
:returns: A copy of the current client.
"""
return self.... | python | def copy(self):
"""Make a copy of this client.
Copies the local data stored as simple types but does not copy the
current state of any open connections with the Cloud Bigtable API.
:rtype: :class:`.Client`
:returns: A copy of the current client.
"""
return self.... | [
"def",
"copy",
"(",
"self",
")",
":",
"return",
"self",
".",
"__class__",
"(",
"project",
"=",
"self",
".",
"project",
",",
"credentials",
"=",
"self",
".",
"_credentials",
",",
"user_agent",
"=",
"self",
".",
"user_agent",
",",
")"
] | Make a copy of this client.
Copies the local data stored as simple types but does not copy the
current state of any open connections with the Cloud Bigtable API.
:rtype: :class:`.Client`
:returns: A copy of the current client. | [
"Make",
"a",
"copy",
"of",
"this",
"client",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/spanner/google/cloud/spanner_v1/client.py#L169-L182 |
28,436 | googleapis/google-cloud-python | spanner/google/cloud/spanner_v1/client.py | Client.list_instance_configs | def list_instance_configs(self, page_size=None, page_token=None):
"""List available instance configurations for the client's project.
.. _RPC docs: https://cloud.google.com/spanner/docs/reference/rpc/\
google.spanner.admin.instance.v1#google.spanner.admin.\
i... | python | def list_instance_configs(self, page_size=None, page_token=None):
"""List available instance configurations for the client's project.
.. _RPC docs: https://cloud.google.com/spanner/docs/reference/rpc/\
google.spanner.admin.instance.v1#google.spanner.admin.\
i... | [
"def",
"list_instance_configs",
"(",
"self",
",",
"page_size",
"=",
"None",
",",
"page_token",
"=",
"None",
")",
":",
"metadata",
"=",
"_metadata_with_prefix",
"(",
"self",
".",
"project_name",
")",
"path",
"=",
"\"projects/%s\"",
"%",
"(",
"self",
".",
"pro... | List available instance configurations for the client's project.
.. _RPC docs: https://cloud.google.com/spanner/docs/reference/rpc/\
google.spanner.admin.instance.v1#google.spanner.admin.\
instance.v1.InstanceAdmin.ListInstanceConfigs
See `RPC docs`_.
... | [
"List",
"available",
"instance",
"configurations",
"for",
"the",
"client",
"s",
"project",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/spanner/google/cloud/spanner_v1/client.py#L184-L220 |
28,437 | googleapis/google-cloud-python | spanner/google/cloud/spanner_v1/client.py | Client.list_instances | def list_instances(self, filter_="", page_size=None, page_token=None):
"""List instances for the client's project.
See
https://cloud.google.com/spanner/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.InstanceAdmin.ListInstances
:type filter_: string
... | python | def list_instances(self, filter_="", page_size=None, page_token=None):
"""List instances for the client's project.
See
https://cloud.google.com/spanner/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.InstanceAdmin.ListInstances
:type filter_: string
... | [
"def",
"list_instances",
"(",
"self",
",",
"filter_",
"=",
"\"\"",
",",
"page_size",
"=",
"None",
",",
"page_token",
"=",
"None",
")",
":",
"metadata",
"=",
"_metadata_with_prefix",
"(",
"self",
".",
"project_name",
")",
"path",
"=",
"\"projects/%s\"",
"%",
... | List instances for the client's project.
See
https://cloud.google.com/spanner/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.InstanceAdmin.ListInstances
:type filter_: string
:param filter_: (Optional) Filter to select instances listed. See
... | [
"List",
"instances",
"for",
"the",
"client",
"s",
"project",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/spanner/google/cloud/spanner_v1/client.py#L256-L292 |
28,438 | googleapis/google-cloud-python | bigquery/google/cloud/bigquery/retry.py | _should_retry | def _should_retry(exc):
"""Predicate for determining when to retry.
We retry if and only if the 'reason' is 'backendError'
or 'rateLimitExceeded'.
"""
if not hasattr(exc, "errors"):
return False
if len(exc.errors) == 0:
# Check for unstructured error returns, e.g. from GFE
... | python | def _should_retry(exc):
"""Predicate for determining when to retry.
We retry if and only if the 'reason' is 'backendError'
or 'rateLimitExceeded'.
"""
if not hasattr(exc, "errors"):
return False
if len(exc.errors) == 0:
# Check for unstructured error returns, e.g. from GFE
... | [
"def",
"_should_retry",
"(",
"exc",
")",
":",
"if",
"not",
"hasattr",
"(",
"exc",
",",
"\"errors\"",
")",
":",
"return",
"False",
"if",
"len",
"(",
"exc",
".",
"errors",
")",
"==",
"0",
":",
"# Check for unstructured error returns, e.g. from GFE",
"return",
... | Predicate for determining when to retry.
We retry if and only if the 'reason' is 'backendError'
or 'rateLimitExceeded'. | [
"Predicate",
"for",
"determining",
"when",
"to",
"retry",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/bigquery/google/cloud/bigquery/retry.py#L30-L44 |
28,439 | googleapis/google-cloud-python | logging/google/cloud/logging/_helpers.py | entry_from_resource | def entry_from_resource(resource, client, loggers):
"""Detect correct entry type from resource and instantiate.
:type resource: dict
:param resource: One entry resource from API response.
:type client: :class:`~google.cloud.logging.client.Client`
:param client: Client that owns the log entry.
... | python | def entry_from_resource(resource, client, loggers):
"""Detect correct entry type from resource and instantiate.
:type resource: dict
:param resource: One entry resource from API response.
:type client: :class:`~google.cloud.logging.client.Client`
:param client: Client that owns the log entry.
... | [
"def",
"entry_from_resource",
"(",
"resource",
",",
"client",
",",
"loggers",
")",
":",
"if",
"\"textPayload\"",
"in",
"resource",
":",
"return",
"TextEntry",
".",
"from_api_repr",
"(",
"resource",
",",
"client",
",",
"loggers",
")",
"if",
"\"jsonPayload\"",
"... | Detect correct entry type from resource and instantiate.
:type resource: dict
:param resource: One entry resource from API response.
:type client: :class:`~google.cloud.logging.client.Client`
:param client: Client that owns the log entry.
:type loggers: dict
:param loggers:
A mapping ... | [
"Detect",
"correct",
"entry",
"type",
"from",
"resource",
"and",
"instantiate",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/logging/google/cloud/logging/_helpers.py#L28-L55 |
28,440 | googleapis/google-cloud-python | logging/google/cloud/logging/_helpers.py | retrieve_metadata_server | def retrieve_metadata_server(metadata_key):
"""Retrieve the metadata key in the metadata server.
See: https://cloud.google.com/compute/docs/storing-retrieving-metadata
:type metadata_key: str
:param metadata_key: Key of the metadata which will form the url. You can
also supply... | python | def retrieve_metadata_server(metadata_key):
"""Retrieve the metadata key in the metadata server.
See: https://cloud.google.com/compute/docs/storing-retrieving-metadata
:type metadata_key: str
:param metadata_key: Key of the metadata which will form the url. You can
also supply... | [
"def",
"retrieve_metadata_server",
"(",
"metadata_key",
")",
":",
"url",
"=",
"METADATA_URL",
"+",
"metadata_key",
"try",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"headers",
"=",
"METADATA_HEADERS",
")",
"if",
"response",
".",
"status_cod... | Retrieve the metadata key in the metadata server.
See: https://cloud.google.com/compute/docs/storing-retrieving-metadata
:type metadata_key: str
:param metadata_key: Key of the metadata which will form the url. You can
also supply query parameters after the metadata key.
... | [
"Retrieve",
"the",
"metadata",
"key",
"in",
"the",
"metadata",
"server",
"."
] | 85e80125a59cb10f8cb105f25ecc099e4b940b50 | https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/logging/google/cloud/logging/_helpers.py#L58-L84 |
28,441 | tensorflow/cleverhans | cleverhans/utils_tf.py | batch_eval | def batch_eval(*args, **kwargs):
"""
Wrapper around deprecated function.
"""
# Inside function to avoid circular import
from cleverhans.evaluation import batch_eval as new_batch_eval
warnings.warn("batch_eval has moved to cleverhans.evaluation. "
"batch_eval will be removed from utils_tf on ... | python | def batch_eval(*args, **kwargs):
"""
Wrapper around deprecated function.
"""
# Inside function to avoid circular import
from cleverhans.evaluation import batch_eval as new_batch_eval
warnings.warn("batch_eval has moved to cleverhans.evaluation. "
"batch_eval will be removed from utils_tf on ... | [
"def",
"batch_eval",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# Inside function to avoid circular import",
"from",
"cleverhans",
".",
"evaluation",
"import",
"batch_eval",
"as",
"new_batch_eval",
"warnings",
".",
"warn",
"(",
"\"batch_eval has moved to cl... | Wrapper around deprecated function. | [
"Wrapper",
"around",
"deprecated",
"function",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/cleverhans/utils_tf.py#L292-L301 |
28,442 | tensorflow/cleverhans | cleverhans/utils_tf.py | get_available_gpus | def get_available_gpus():
"""
Returns a list of string names of all available GPUs
"""
local_device_protos = device_lib.list_local_devices()
return [x.name for x in local_device_protos if x.device_type == 'GPU'] | python | def get_available_gpus():
"""
Returns a list of string names of all available GPUs
"""
local_device_protos = device_lib.list_local_devices()
return [x.name for x in local_device_protos if x.device_type == 'GPU'] | [
"def",
"get_available_gpus",
"(",
")",
":",
"local_device_protos",
"=",
"device_lib",
".",
"list_local_devices",
"(",
")",
"return",
"[",
"x",
".",
"name",
"for",
"x",
"in",
"local_device_protos",
"if",
"x",
".",
"device_type",
"==",
"'GPU'",
"]"
] | Returns a list of string names of all available GPUs | [
"Returns",
"a",
"list",
"of",
"string",
"names",
"of",
"all",
"available",
"GPUs"
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/cleverhans/utils_tf.py#L526-L531 |
28,443 | tensorflow/cleverhans | cleverhans/utils_tf.py | clip_by_value | def clip_by_value(t, clip_value_min, clip_value_max, name=None):
"""
A wrapper for clip_by_value that casts the clipping range if needed.
"""
def cast_clip(clip):
"""
Cast clipping range argument if needed.
"""
if t.dtype in (tf.float32, tf.float64):
if hasattr(clip, 'dtype'):
# Co... | python | def clip_by_value(t, clip_value_min, clip_value_max, name=None):
"""
A wrapper for clip_by_value that casts the clipping range if needed.
"""
def cast_clip(clip):
"""
Cast clipping range argument if needed.
"""
if t.dtype in (tf.float32, tf.float64):
if hasattr(clip, 'dtype'):
# Co... | [
"def",
"clip_by_value",
"(",
"t",
",",
"clip_value_min",
",",
"clip_value_max",
",",
"name",
"=",
"None",
")",
":",
"def",
"cast_clip",
"(",
"clip",
")",
":",
"\"\"\"\n Cast clipping range argument if needed.\n \"\"\"",
"if",
"t",
".",
"dtype",
"in",
"(",
... | A wrapper for clip_by_value that casts the clipping range if needed. | [
"A",
"wrapper",
"for",
"clip_by_value",
"that",
"casts",
"the",
"clipping",
"range",
"if",
"needed",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/cleverhans/utils_tf.py#L540-L559 |
28,444 | tensorflow/cleverhans | cleverhans/utils_tf.py | mul | def mul(a, b):
"""
A wrapper around tf multiplication that does more automatic casting of
the input.
"""
def multiply(a, b):
"""Multiplication"""
return a * b
return op_with_scalar_cast(a, b, multiply) | python | def mul(a, b):
"""
A wrapper around tf multiplication that does more automatic casting of
the input.
"""
def multiply(a, b):
"""Multiplication"""
return a * b
return op_with_scalar_cast(a, b, multiply) | [
"def",
"mul",
"(",
"a",
",",
"b",
")",
":",
"def",
"multiply",
"(",
"a",
",",
"b",
")",
":",
"\"\"\"Multiplication\"\"\"",
"return",
"a",
"*",
"b",
"return",
"op_with_scalar_cast",
"(",
"a",
",",
"b",
",",
"multiply",
")"
] | A wrapper around tf multiplication that does more automatic casting of
the input. | [
"A",
"wrapper",
"around",
"tf",
"multiplication",
"that",
"does",
"more",
"automatic",
"casting",
"of",
"the",
"input",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/cleverhans/utils_tf.py#L561-L569 |
28,445 | tensorflow/cleverhans | cleverhans/utils_tf.py | div | def div(a, b):
"""
A wrapper around tf division that does more automatic casting of
the input.
"""
def divide(a, b):
"""Division"""
return a / b
return op_with_scalar_cast(a, b, divide) | python | def div(a, b):
"""
A wrapper around tf division that does more automatic casting of
the input.
"""
def divide(a, b):
"""Division"""
return a / b
return op_with_scalar_cast(a, b, divide) | [
"def",
"div",
"(",
"a",
",",
"b",
")",
":",
"def",
"divide",
"(",
"a",
",",
"b",
")",
":",
"\"\"\"Division\"\"\"",
"return",
"a",
"/",
"b",
"return",
"op_with_scalar_cast",
"(",
"a",
",",
"b",
",",
"divide",
")"
] | A wrapper around tf division that does more automatic casting of
the input. | [
"A",
"wrapper",
"around",
"tf",
"division",
"that",
"does",
"more",
"automatic",
"casting",
"of",
"the",
"input",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/cleverhans/utils_tf.py#L571-L579 |
28,446 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py | ImageBatchesBase._write_single_batch_images_internal | def _write_single_batch_images_internal(self, batch_id, client_batch):
"""Helper method to write images from single batch into datastore."""
client = self._datastore_client
batch_key = client.key(self._entity_kind_batches, batch_id)
for img_id, img in iteritems(self._data[batch_id]['images']):
img... | python | def _write_single_batch_images_internal(self, batch_id, client_batch):
"""Helper method to write images from single batch into datastore."""
client = self._datastore_client
batch_key = client.key(self._entity_kind_batches, batch_id)
for img_id, img in iteritems(self._data[batch_id]['images']):
img... | [
"def",
"_write_single_batch_images_internal",
"(",
"self",
",",
"batch_id",
",",
"client_batch",
")",
":",
"client",
"=",
"self",
".",
"_datastore_client",
"batch_key",
"=",
"client",
".",
"key",
"(",
"self",
".",
"_entity_kind_batches",
",",
"batch_id",
")",
"f... | Helper method to write images from single batch into datastore. | [
"Helper",
"method",
"to",
"write",
"images",
"from",
"single",
"batch",
"into",
"datastore",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py#L72-L81 |
28,447 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py | ImageBatchesBase.write_to_datastore | def write_to_datastore(self):
"""Writes all image batches to the datastore."""
client = self._datastore_client
with client.no_transact_batch() as client_batch:
for batch_id, batch_data in iteritems(self._data):
batch_key = client.key(self._entity_kind_batches, batch_id)
batch_entity = ... | python | def write_to_datastore(self):
"""Writes all image batches to the datastore."""
client = self._datastore_client
with client.no_transact_batch() as client_batch:
for batch_id, batch_data in iteritems(self._data):
batch_key = client.key(self._entity_kind_batches, batch_id)
batch_entity = ... | [
"def",
"write_to_datastore",
"(",
"self",
")",
":",
"client",
"=",
"self",
".",
"_datastore_client",
"with",
"client",
".",
"no_transact_batch",
"(",
")",
"as",
"client_batch",
":",
"for",
"batch_id",
",",
"batch_data",
"in",
"iteritems",
"(",
"self",
".",
"... | Writes all image batches to the datastore. | [
"Writes",
"all",
"image",
"batches",
"to",
"the",
"datastore",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py#L83-L94 |
28,448 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py | ImageBatchesBase.write_single_batch_images_to_datastore | def write_single_batch_images_to_datastore(self, batch_id):
"""Writes only images from one batch to the datastore."""
client = self._datastore_client
with client.no_transact_batch() as client_batch:
self._write_single_batch_images_internal(batch_id, client_batch) | python | def write_single_batch_images_to_datastore(self, batch_id):
"""Writes only images from one batch to the datastore."""
client = self._datastore_client
with client.no_transact_batch() as client_batch:
self._write_single_batch_images_internal(batch_id, client_batch) | [
"def",
"write_single_batch_images_to_datastore",
"(",
"self",
",",
"batch_id",
")",
":",
"client",
"=",
"self",
".",
"_datastore_client",
"with",
"client",
".",
"no_transact_batch",
"(",
")",
"as",
"client_batch",
":",
"self",
".",
"_write_single_batch_images_internal... | Writes only images from one batch to the datastore. | [
"Writes",
"only",
"images",
"from",
"one",
"batch",
"to",
"the",
"datastore",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py#L96-L100 |
28,449 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py | ImageBatchesBase.init_from_datastore | def init_from_datastore(self):
"""Initializes batches by reading from the datastore."""
self._data = {}
for entity in self._datastore_client.query_fetch(
kind=self._entity_kind_batches):
batch_id = entity.key.flat_path[-1]
self._data[batch_id] = dict(entity)
self._data[batch_id]['i... | python | def init_from_datastore(self):
"""Initializes batches by reading from the datastore."""
self._data = {}
for entity in self._datastore_client.query_fetch(
kind=self._entity_kind_batches):
batch_id = entity.key.flat_path[-1]
self._data[batch_id] = dict(entity)
self._data[batch_id]['i... | [
"def",
"init_from_datastore",
"(",
"self",
")",
":",
"self",
".",
"_data",
"=",
"{",
"}",
"for",
"entity",
"in",
"self",
".",
"_datastore_client",
".",
"query_fetch",
"(",
"kind",
"=",
"self",
".",
"_entity_kind_batches",
")",
":",
"batch_id",
"=",
"entity... | Initializes batches by reading from the datastore. | [
"Initializes",
"batches",
"by",
"reading",
"from",
"the",
"datastore",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py#L102-L114 |
28,450 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py | ImageBatchesBase.add_batch | def add_batch(self, batch_id, batch_properties=None):
"""Adds batch with give ID and list of properties."""
if batch_properties is None:
batch_properties = {}
if not isinstance(batch_properties, dict):
raise ValueError('batch_properties has to be dict, however it was: '
+ ... | python | def add_batch(self, batch_id, batch_properties=None):
"""Adds batch with give ID and list of properties."""
if batch_properties is None:
batch_properties = {}
if not isinstance(batch_properties, dict):
raise ValueError('batch_properties has to be dict, however it was: '
+ ... | [
"def",
"add_batch",
"(",
"self",
",",
"batch_id",
",",
"batch_properties",
"=",
"None",
")",
":",
"if",
"batch_properties",
"is",
"None",
":",
"batch_properties",
"=",
"{",
"}",
"if",
"not",
"isinstance",
"(",
"batch_properties",
",",
"dict",
")",
":",
"ra... | Adds batch with give ID and list of properties. | [
"Adds",
"batch",
"with",
"give",
"ID",
"and",
"list",
"of",
"properties",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py#L125-L133 |
28,451 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py | ImageBatchesBase.add_image | def add_image(self, batch_id, image_id, image_properties=None):
"""Adds image to given batch."""
if batch_id not in self._data:
raise KeyError('Batch with ID "{0}" does not exist'.format(batch_id))
if image_properties is None:
image_properties = {}
if not isinstance(image_properties, dict):
... | python | def add_image(self, batch_id, image_id, image_properties=None):
"""Adds image to given batch."""
if batch_id not in self._data:
raise KeyError('Batch with ID "{0}" does not exist'.format(batch_id))
if image_properties is None:
image_properties = {}
if not isinstance(image_properties, dict):
... | [
"def",
"add_image",
"(",
"self",
",",
"batch_id",
",",
"image_id",
",",
"image_properties",
"=",
"None",
")",
":",
"if",
"batch_id",
"not",
"in",
"self",
".",
"_data",
":",
"raise",
"KeyError",
"(",
"'Batch with ID \"{0}\" does not exist'",
".",
"format",
"(",... | Adds image to given batch. | [
"Adds",
"image",
"to",
"given",
"batch",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py#L135-L144 |
28,452 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py | DatasetBatches._read_image_list | def _read_image_list(self, skip_image_ids=None):
"""Reads list of dataset images from the datastore."""
if skip_image_ids is None:
skip_image_ids = []
images = self._storage_client.list_blobs(
prefix=os.path.join('dataset', self._dataset_name) + '/')
zip_files = [i for i in images if i.end... | python | def _read_image_list(self, skip_image_ids=None):
"""Reads list of dataset images from the datastore."""
if skip_image_ids is None:
skip_image_ids = []
images = self._storage_client.list_blobs(
prefix=os.path.join('dataset', self._dataset_name) + '/')
zip_files = [i for i in images if i.end... | [
"def",
"_read_image_list",
"(",
"self",
",",
"skip_image_ids",
"=",
"None",
")",
":",
"if",
"skip_image_ids",
"is",
"None",
":",
"skip_image_ids",
"=",
"[",
"]",
"images",
"=",
"self",
".",
"_storage_client",
".",
"list_blobs",
"(",
"prefix",
"=",
"os",
".... | Reads list of dataset images from the datastore. | [
"Reads",
"list",
"of",
"dataset",
"images",
"from",
"the",
"datastore",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py#L189-L222 |
28,453 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py | DatasetBatches.init_from_storage_write_to_datastore | def init_from_storage_write_to_datastore(self,
batch_size=100,
allowed_epsilon=None,
skip_image_ids=None,
max_num_images=None):
"""Initializes d... | python | def init_from_storage_write_to_datastore(self,
batch_size=100,
allowed_epsilon=None,
skip_image_ids=None,
max_num_images=None):
"""Initializes d... | [
"def",
"init_from_storage_write_to_datastore",
"(",
"self",
",",
"batch_size",
"=",
"100",
",",
"allowed_epsilon",
"=",
"None",
",",
"skip_image_ids",
"=",
"None",
",",
"max_num_images",
"=",
"None",
")",
":",
"if",
"allowed_epsilon",
"is",
"None",
":",
"allowed... | Initializes dataset batches from the list of images in the datastore.
Args:
batch_size: batch size
allowed_epsilon: list of allowed epsilon or None to use default
skip_image_ids: list of image ids to skip
max_num_images: maximum number of images to read | [
"Initializes",
"dataset",
"batches",
"from",
"the",
"list",
"of",
"images",
"in",
"the",
"datastore",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py#L224-L255 |
28,454 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py | AversarialBatches.init_from_dataset_and_submissions_write_to_datastore | def init_from_dataset_and_submissions_write_to_datastore(
self, dataset_batches, attack_submission_ids):
"""Init list of adversarial batches from dataset batches and submissions.
Args:
dataset_batches: instances of DatasetBatches
attack_submission_ids: iterable with IDs of all (targeted and n... | python | def init_from_dataset_and_submissions_write_to_datastore(
self, dataset_batches, attack_submission_ids):
"""Init list of adversarial batches from dataset batches and submissions.
Args:
dataset_batches: instances of DatasetBatches
attack_submission_ids: iterable with IDs of all (targeted and n... | [
"def",
"init_from_dataset_and_submissions_write_to_datastore",
"(",
"self",
",",
"dataset_batches",
",",
"attack_submission_ids",
")",
":",
"batches_x_attacks",
"=",
"itertools",
".",
"product",
"(",
"dataset_batches",
".",
"data",
".",
"keys",
"(",
")",
",",
"attack_... | Init list of adversarial batches from dataset batches and submissions.
Args:
dataset_batches: instances of DatasetBatches
attack_submission_ids: iterable with IDs of all (targeted and nontargeted)
attack submissions, could be obtains as
CompetitionSubmissions.get_all_attack_ids() | [
"Init",
"list",
"of",
"adversarial",
"batches",
"from",
"dataset",
"batches",
"and",
"submissions",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py#L272-L289 |
28,455 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py | AversarialBatches.count_generated_adv_examples | def count_generated_adv_examples(self):
"""Returns total number of all generated adversarial examples."""
result = {}
for v in itervalues(self.data):
s_id = v['submission_id']
result[s_id] = result.get(s_id, 0) + len(v['images'])
return result | python | def count_generated_adv_examples(self):
"""Returns total number of all generated adversarial examples."""
result = {}
for v in itervalues(self.data):
s_id = v['submission_id']
result[s_id] = result.get(s_id, 0) + len(v['images'])
return result | [
"def",
"count_generated_adv_examples",
"(",
"self",
")",
":",
"result",
"=",
"{",
"}",
"for",
"v",
"in",
"itervalues",
"(",
"self",
".",
"data",
")",
":",
"s_id",
"=",
"v",
"[",
"'submission_id'",
"]",
"result",
"[",
"s_id",
"]",
"=",
"result",
".",
... | Returns total number of all generated adversarial examples. | [
"Returns",
"total",
"number",
"of",
"all",
"generated",
"adversarial",
"examples",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/image_batches.py#L291-L297 |
28,456 | tensorflow/cleverhans | cleverhans/utils.py | create_logger | def create_logger(name):
"""
Create a logger object with the given name.
If this is the first time that we call this method, then initialize the
formatter.
"""
base = logging.getLogger("cleverhans")
if len(base.handlers) == 0:
ch = logging.StreamHandler()
formatter = logging.Formatter('[%(levelna... | python | def create_logger(name):
"""
Create a logger object with the given name.
If this is the first time that we call this method, then initialize the
formatter.
"""
base = logging.getLogger("cleverhans")
if len(base.handlers) == 0:
ch = logging.StreamHandler()
formatter = logging.Formatter('[%(levelna... | [
"def",
"create_logger",
"(",
"name",
")",
":",
"base",
"=",
"logging",
".",
"getLogger",
"(",
"\"cleverhans\"",
")",
"if",
"len",
"(",
"base",
".",
"handlers",
")",
"==",
"0",
":",
"ch",
"=",
"logging",
".",
"StreamHandler",
"(",
")",
"formatter",
"=",... | Create a logger object with the given name.
If this is the first time that we call this method, then initialize the
formatter. | [
"Create",
"a",
"logger",
"object",
"with",
"the",
"given",
"name",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/cleverhans/utils.py#L247-L262 |
28,457 | tensorflow/cleverhans | cleverhans/utils.py | deterministic_dict | def deterministic_dict(normal_dict):
"""
Returns a version of `normal_dict` whose iteration order is always the same
"""
out = OrderedDict()
for key in sorted(normal_dict.keys()):
out[key] = normal_dict[key]
return out | python | def deterministic_dict(normal_dict):
"""
Returns a version of `normal_dict` whose iteration order is always the same
"""
out = OrderedDict()
for key in sorted(normal_dict.keys()):
out[key] = normal_dict[key]
return out | [
"def",
"deterministic_dict",
"(",
"normal_dict",
")",
":",
"out",
"=",
"OrderedDict",
"(",
")",
"for",
"key",
"in",
"sorted",
"(",
"normal_dict",
".",
"keys",
"(",
")",
")",
":",
"out",
"[",
"key",
"]",
"=",
"normal_dict",
"[",
"key",
"]",
"return",
... | Returns a version of `normal_dict` whose iteration order is always the same | [
"Returns",
"a",
"version",
"of",
"normal_dict",
"whose",
"iteration",
"order",
"is",
"always",
"the",
"same"
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/cleverhans/utils.py#L265-L272 |
28,458 | tensorflow/cleverhans | cleverhans/utils.py | shell_call | def shell_call(command, **kwargs):
"""Calls shell command with argument substitution.
Args:
command: command represented as a list. Each element of the list is one
token of the command. For example "cp a b" becomes ['cp', 'a', 'b']
If any element of the list looks like '${NAME}' then it will be rep... | python | def shell_call(command, **kwargs):
"""Calls shell command with argument substitution.
Args:
command: command represented as a list. Each element of the list is one
token of the command. For example "cp a b" becomes ['cp', 'a', 'b']
If any element of the list looks like '${NAME}' then it will be rep... | [
"def",
"shell_call",
"(",
"command",
",",
"*",
"*",
"kwargs",
")",
":",
"# Regular expression to find instances of '${NAME}' in a string",
"CMD_VARIABLE_RE",
"=",
"re",
".",
"compile",
"(",
"'^\\\\$\\\\{(\\\\w+)\\\\}$'",
")",
"command",
"=",
"list",
"(",
"command",
")... | Calls shell command with argument substitution.
Args:
command: command represented as a list. Each element of the list is one
token of the command. For example "cp a b" becomes ['cp', 'a', 'b']
If any element of the list looks like '${NAME}' then it will be replaced
by value from **kwargs with ... | [
"Calls",
"shell",
"command",
"with",
"argument",
"substitution",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/cleverhans/utils.py#L304-L339 |
28,459 | tensorflow/cleverhans | cleverhans/utils.py | deep_copy | def deep_copy(numpy_dict):
"""
Returns a copy of a dictionary whose values are numpy arrays.
Copies their values rather than copying references to them.
"""
out = {}
for key in numpy_dict:
out[key] = numpy_dict[key].copy()
return out | python | def deep_copy(numpy_dict):
"""
Returns a copy of a dictionary whose values are numpy arrays.
Copies their values rather than copying references to them.
"""
out = {}
for key in numpy_dict:
out[key] = numpy_dict[key].copy()
return out | [
"def",
"deep_copy",
"(",
"numpy_dict",
")",
":",
"out",
"=",
"{",
"}",
"for",
"key",
"in",
"numpy_dict",
":",
"out",
"[",
"key",
"]",
"=",
"numpy_dict",
"[",
"key",
"]",
".",
"copy",
"(",
")",
"return",
"out"
] | Returns a copy of a dictionary whose values are numpy arrays.
Copies their values rather than copying references to them. | [
"Returns",
"a",
"copy",
"of",
"a",
"dictionary",
"whose",
"values",
"are",
"numpy",
"arrays",
".",
"Copies",
"their",
"values",
"rather",
"than",
"copying",
"references",
"to",
"them",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/cleverhans/utils.py#L341-L349 |
28,460 | tensorflow/cleverhans | scripts/compute_accuracy.py | print_accuracies | def print_accuracies(filepath, train_start=TRAIN_START, train_end=TRAIN_END,
test_start=TEST_START, test_end=TEST_END,
batch_size=BATCH_SIZE, which_set=WHICH_SET,
base_eps_iter=BASE_EPS_ITER,
nb_iter=NB_ITER):
"""
Load a saved model... | python | def print_accuracies(filepath, train_start=TRAIN_START, train_end=TRAIN_END,
test_start=TEST_START, test_end=TEST_END,
batch_size=BATCH_SIZE, which_set=WHICH_SET,
base_eps_iter=BASE_EPS_ITER,
nb_iter=NB_ITER):
"""
Load a saved model... | [
"def",
"print_accuracies",
"(",
"filepath",
",",
"train_start",
"=",
"TRAIN_START",
",",
"train_end",
"=",
"TRAIN_END",
",",
"test_start",
"=",
"TEST_START",
",",
"test_end",
"=",
"TEST_END",
",",
"batch_size",
"=",
"BATCH_SIZE",
",",
"which_set",
"=",
"WHICH_SE... | Load a saved model and print out its accuracy on different data distributions
This function works by running a single attack on each example.
This provides a reasonable estimate of the true failure rate quickly, so
long as the model does not suffer from gradient masking.
However, this estimate is mostly intend... | [
"Load",
"a",
"saved",
"model",
"and",
"print",
"out",
"its",
"accuracy",
"on",
"different",
"data",
"distributions"
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/scripts/compute_accuracy.py#L53-L98 |
28,461 | tensorflow/cleverhans | examples/multigpu_advtrain/trainer.py | TrainerMultiGPU.clone_g0_inputs_on_ngpus | def clone_g0_inputs_on_ngpus(self, inputs, outputs, g0_inputs):
"""
Clone variables unused by the attack on all GPUs. Specifically, the
ground-truth label, y, has to be preserved until the training step.
:param inputs: A list of dictionaries as the inputs to each step.
:param outputs: A list of dic... | python | def clone_g0_inputs_on_ngpus(self, inputs, outputs, g0_inputs):
"""
Clone variables unused by the attack on all GPUs. Specifically, the
ground-truth label, y, has to be preserved until the training step.
:param inputs: A list of dictionaries as the inputs to each step.
:param outputs: A list of dic... | [
"def",
"clone_g0_inputs_on_ngpus",
"(",
"self",
",",
"inputs",
",",
"outputs",
",",
"g0_inputs",
")",
":",
"assert",
"len",
"(",
"inputs",
")",
"==",
"len",
"(",
"outputs",
")",
",",
"(",
"'Inputs and outputs should have the same number of elements.'",
")",
"input... | Clone variables unused by the attack on all GPUs. Specifically, the
ground-truth label, y, has to be preserved until the training step.
:param inputs: A list of dictionaries as the inputs to each step.
:param outputs: A list of dictionaries as the outputs of each step.
:param g0_inputs: Initial variabl... | [
"Clone",
"variables",
"unused",
"by",
"the",
"attack",
"on",
"all",
"GPUs",
".",
"Specifically",
"the",
"ground",
"-",
"truth",
"label",
"y",
"has",
"to",
"be",
"preserved",
"until",
"the",
"training",
"step",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/multigpu_advtrain/trainer.py#L313-L341 |
28,462 | tensorflow/cleverhans | examples/multigpu_advtrain/model.py | MLPnGPU.set_device | def set_device(self, device_name):
"""
Set the device before the next fprop to create a new graph on the
specified device.
"""
device_name = unify_device_name(device_name)
self.device_name = device_name
for layer in self.layers:
layer.device_name = device_name | python | def set_device(self, device_name):
"""
Set the device before the next fprop to create a new graph on the
specified device.
"""
device_name = unify_device_name(device_name)
self.device_name = device_name
for layer in self.layers:
layer.device_name = device_name | [
"def",
"set_device",
"(",
"self",
",",
"device_name",
")",
":",
"device_name",
"=",
"unify_device_name",
"(",
"device_name",
")",
"self",
".",
"device_name",
"=",
"device_name",
"for",
"layer",
"in",
"self",
".",
"layers",
":",
"layer",
".",
"device_name",
"... | Set the device before the next fprop to create a new graph on the
specified device. | [
"Set",
"the",
"device",
"before",
"the",
"next",
"fprop",
"to",
"create",
"a",
"new",
"graph",
"on",
"the",
"specified",
"device",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/multigpu_advtrain/model.py#L206-L214 |
28,463 | tensorflow/cleverhans | examples/multigpu_advtrain/model.py | LayernGPU.set_input_shape_ngpu | def set_input_shape_ngpu(self, new_input_shape):
"""
Create and initialize layer parameters on the device previously set
in self.device_name.
:param new_input_shape: a list or tuple for the shape of the input.
"""
assert self.device_name, "Device name has not been set."
device_name = self.... | python | def set_input_shape_ngpu(self, new_input_shape):
"""
Create and initialize layer parameters on the device previously set
in self.device_name.
:param new_input_shape: a list or tuple for the shape of the input.
"""
assert self.device_name, "Device name has not been set."
device_name = self.... | [
"def",
"set_input_shape_ngpu",
"(",
"self",
",",
"new_input_shape",
")",
":",
"assert",
"self",
".",
"device_name",
",",
"\"Device name has not been set.\"",
"device_name",
"=",
"self",
".",
"device_name",
"if",
"self",
".",
"input_shape",
"is",
"None",
":",
"# Fi... | Create and initialize layer parameters on the device previously set
in self.device_name.
:param new_input_shape: a list or tuple for the shape of the input. | [
"Create",
"and",
"initialize",
"layer",
"parameters",
"on",
"the",
"device",
"previously",
"set",
"in",
"self",
".",
"device_name",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/multigpu_advtrain/model.py#L266-L297 |
28,464 | tensorflow/cleverhans | examples/multigpu_advtrain/model.py | LayernGPU.create_sync_ops | def create_sync_ops(self, host_device):
"""Create an assignment operation for each weight on all devices. The
weight is assigned the value of the copy on the `host_device'.
"""
sync_ops = []
host_params = self.params_device[host_device]
for device, params in (self.params_device).iteritems():
... | python | def create_sync_ops(self, host_device):
"""Create an assignment operation for each weight on all devices. The
weight is assigned the value of the copy on the `host_device'.
"""
sync_ops = []
host_params = self.params_device[host_device]
for device, params in (self.params_device).iteritems():
... | [
"def",
"create_sync_ops",
"(",
"self",
",",
"host_device",
")",
":",
"sync_ops",
"=",
"[",
"]",
"host_params",
"=",
"self",
".",
"params_device",
"[",
"host_device",
"]",
"for",
"device",
",",
"params",
"in",
"(",
"self",
".",
"params_device",
")",
".",
... | Create an assignment operation for each weight on all devices. The
weight is assigned the value of the copy on the `host_device'. | [
"Create",
"an",
"assignment",
"operation",
"for",
"each",
"weight",
"on",
"all",
"devices",
".",
"The",
"weight",
"is",
"assigned",
"the",
"value",
"of",
"the",
"copy",
"on",
"the",
"host_device",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/multigpu_advtrain/model.py#L299-L311 |
28,465 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/eval_lib/cloud_client.py | iterate_with_exp_backoff | def iterate_with_exp_backoff(base_iter,
max_num_tries=6,
max_backoff=300.0,
start_backoff=4.0,
backoff_multiplier=2.0,
frac_random_backoff=0.25):
"""Iterate with exponential... | python | def iterate_with_exp_backoff(base_iter,
max_num_tries=6,
max_backoff=300.0,
start_backoff=4.0,
backoff_multiplier=2.0,
frac_random_backoff=0.25):
"""Iterate with exponential... | [
"def",
"iterate_with_exp_backoff",
"(",
"base_iter",
",",
"max_num_tries",
"=",
"6",
",",
"max_backoff",
"=",
"300.0",
",",
"start_backoff",
"=",
"4.0",
",",
"backoff_multiplier",
"=",
"2.0",
",",
"frac_random_backoff",
"=",
"0.25",
")",
":",
"try_number",
"=",
... | Iterate with exponential backoff on failures.
Useful to wrap results of datastore Query.fetch to avoid 429 error.
Args:
base_iter: basic iterator of generator object
max_num_tries: maximum number of tries for each request
max_backoff: maximum backoff, in seconds
start_backoff: initial value of bac... | [
"Iterate",
"with",
"exponential",
"backoff",
"on",
"failures",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/cloud_client.py#L167-L209 |
28,466 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/eval_lib/cloud_client.py | CompetitionStorageClient.list_blobs | def list_blobs(self, prefix=''):
"""Lists names of all blobs by their prefix."""
return [b.name for b in self.bucket.list_blobs(prefix=prefix)] | python | def list_blobs(self, prefix=''):
"""Lists names of all blobs by their prefix."""
return [b.name for b in self.bucket.list_blobs(prefix=prefix)] | [
"def",
"list_blobs",
"(",
"self",
",",
"prefix",
"=",
"''",
")",
":",
"return",
"[",
"b",
".",
"name",
"for",
"b",
"in",
"self",
".",
"bucket",
".",
"list_blobs",
"(",
"prefix",
"=",
"prefix",
")",
"]"
] | Lists names of all blobs by their prefix. | [
"Lists",
"names",
"of",
"all",
"blobs",
"by",
"their",
"prefix",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/cloud_client.py#L43-L45 |
28,467 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/eval_lib/cloud_client.py | NoTransactionBatch.rollback | def rollback(self):
"""Rolls back pending mutations.
Keep in mind that NoTransactionBatch splits all mutations into smaller
batches and commit them as soon as mutation buffer reaches maximum length.
That's why rollback method will only roll back pending mutations from the
buffer, but won't be able ... | python | def rollback(self):
"""Rolls back pending mutations.
Keep in mind that NoTransactionBatch splits all mutations into smaller
batches and commit them as soon as mutation buffer reaches maximum length.
That's why rollback method will only roll back pending mutations from the
buffer, but won't be able ... | [
"def",
"rollback",
"(",
"self",
")",
":",
"try",
":",
"if",
"self",
".",
"_cur_batch",
":",
"self",
".",
"_cur_batch",
".",
"rollback",
"(",
")",
"except",
"ValueError",
":",
"# ignore \"Batch must be in progress to rollback\" error",
"pass",
"self",
".",
"_cur_... | Rolls back pending mutations.
Keep in mind that NoTransactionBatch splits all mutations into smaller
batches and commit them as soon as mutation buffer reaches maximum length.
That's why rollback method will only roll back pending mutations from the
buffer, but won't be able to rollback already committ... | [
"Rolls",
"back",
"pending",
"mutations",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/cloud_client.py#L107-L122 |
28,468 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/eval_lib/cloud_client.py | NoTransactionBatch.put | def put(self, entity):
"""Adds mutation of the entity to the mutation buffer.
If mutation buffer reaches its capacity then this method commit all pending
mutations from the buffer and emties it.
Args:
entity: entity which should be put into the datastore
"""
self._cur_batch.put(entity)
... | python | def put(self, entity):
"""Adds mutation of the entity to the mutation buffer.
If mutation buffer reaches its capacity then this method commit all pending
mutations from the buffer and emties it.
Args:
entity: entity which should be put into the datastore
"""
self._cur_batch.put(entity)
... | [
"def",
"put",
"(",
"self",
",",
"entity",
")",
":",
"self",
".",
"_cur_batch",
".",
"put",
"(",
"entity",
")",
"self",
".",
"_num_mutations",
"+=",
"1",
"if",
"self",
".",
"_num_mutations",
">=",
"MAX_MUTATIONS_IN_BATCH",
":",
"self",
".",
"commit",
"(",... | Adds mutation of the entity to the mutation buffer.
If mutation buffer reaches its capacity then this method commit all pending
mutations from the buffer and emties it.
Args:
entity: entity which should be put into the datastore | [
"Adds",
"mutation",
"of",
"the",
"entity",
"to",
"the",
"mutation",
"buffer",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/cloud_client.py#L124-L137 |
28,469 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/eval_lib/cloud_client.py | NoTransactionBatch.delete | def delete(self, key):
"""Adds deletion of the entity with given key to the mutation buffer.
If mutation buffer reaches its capacity then this method commit all pending
mutations from the buffer and emties it.
Args:
key: key of the entity which should be deleted
"""
self._cur_batch.delet... | python | def delete(self, key):
"""Adds deletion of the entity with given key to the mutation buffer.
If mutation buffer reaches its capacity then this method commit all pending
mutations from the buffer and emties it.
Args:
key: key of the entity which should be deleted
"""
self._cur_batch.delet... | [
"def",
"delete",
"(",
"self",
",",
"key",
")",
":",
"self",
".",
"_cur_batch",
".",
"delete",
"(",
"key",
")",
"self",
".",
"_num_mutations",
"+=",
"1",
"if",
"self",
".",
"_num_mutations",
">=",
"MAX_MUTATIONS_IN_BATCH",
":",
"self",
".",
"commit",
"(",... | Adds deletion of the entity with given key to the mutation buffer.
If mutation buffer reaches its capacity then this method commit all pending
mutations from the buffer and emties it.
Args:
key: key of the entity which should be deleted | [
"Adds",
"deletion",
"of",
"the",
"entity",
"with",
"given",
"key",
"to",
"the",
"mutation",
"buffer",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/cloud_client.py#L139-L152 |
28,470 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/eval_lib/cloud_client.py | CompetitionDatastoreClient.get | def get(self, key, transaction=None):
"""Retrieves an entity given its key."""
return self._client.get(key, transaction=transaction) | python | def get(self, key, transaction=None):
"""Retrieves an entity given its key."""
return self._client.get(key, transaction=transaction) | [
"def",
"get",
"(",
"self",
",",
"key",
",",
"transaction",
"=",
"None",
")",
":",
"return",
"self",
".",
"_client",
".",
"get",
"(",
"key",
",",
"transaction",
"=",
"transaction",
")"
] | Retrieves an entity given its key. | [
"Retrieves",
"an",
"entity",
"given",
"its",
"key",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/cloud_client.py#L239-L241 |
28,471 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/worker.py | sudo_remove_dirtree | def sudo_remove_dirtree(dir_name):
"""Removes directory tree as a superuser.
Args:
dir_name: name of the directory to remove.
This function is necessary to cleanup directories created from inside a
Docker, since they usually written as a root, thus have to be removed as a
root.
"""
try:
subproce... | python | def sudo_remove_dirtree(dir_name):
"""Removes directory tree as a superuser.
Args:
dir_name: name of the directory to remove.
This function is necessary to cleanup directories created from inside a
Docker, since they usually written as a root, thus have to be removed as a
root.
"""
try:
subproce... | [
"def",
"sudo_remove_dirtree",
"(",
"dir_name",
")",
":",
"try",
":",
"subprocess",
".",
"check_output",
"(",
"[",
"'sudo'",
",",
"'rm'",
",",
"'-rf'",
",",
"dir_name",
"]",
")",
"except",
"subprocess",
".",
"CalledProcessError",
"as",
"e",
":",
"raise",
"W... | Removes directory tree as a superuser.
Args:
dir_name: name of the directory to remove.
This function is necessary to cleanup directories created from inside a
Docker, since they usually written as a root, thus have to be removed as a
root. | [
"Removes",
"directory",
"tree",
"as",
"a",
"superuser",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/worker.py#L116-L129 |
28,472 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/worker.py | main | def main(args):
"""Main function which runs worker."""
title = '## Starting evaluation of round {0} ##'.format(args.round_name)
logging.info('\n'
+ '#' * len(title) + '\n'
+ '#' * len(title) + '\n'
+ '##' + ' ' * (len(title)-2) + '##' + '\n'
+ title + '\... | python | def main(args):
"""Main function which runs worker."""
title = '## Starting evaluation of round {0} ##'.format(args.round_name)
logging.info('\n'
+ '#' * len(title) + '\n'
+ '#' * len(title) + '\n'
+ '##' + ' ' * (len(title)-2) + '##' + '\n'
+ title + '\... | [
"def",
"main",
"(",
"args",
")",
":",
"title",
"=",
"'## Starting evaluation of round {0} ##'",
".",
"format",
"(",
"args",
".",
"round_name",
")",
"logging",
".",
"info",
"(",
"'\\n'",
"+",
"'#'",
"*",
"len",
"(",
"title",
")",
"+",
"'\\n'",
"+",
"'#'",... | Main function which runs worker. | [
"Main",
"function",
"which",
"runs",
"worker",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/worker.py#L900-L929 |
28,473 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/worker.py | ExecutableSubmission.temp_copy_extracted_submission | def temp_copy_extracted_submission(self):
"""Creates a temporary copy of extracted submission.
When executed, submission is allowed to modify it's own directory. So
to ensure that submission does not pass any data between runs, new
copy of the submission is made before each run. After a run temporary c... | python | def temp_copy_extracted_submission(self):
"""Creates a temporary copy of extracted submission.
When executed, submission is allowed to modify it's own directory. So
to ensure that submission does not pass any data between runs, new
copy of the submission is made before each run. After a run temporary c... | [
"def",
"temp_copy_extracted_submission",
"(",
"self",
")",
":",
"tmp_copy_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"submission_dir",
",",
"'tmp_copy'",
")",
"shell_call",
"(",
"[",
"'cp'",
",",
"'-R'",
",",
"os",
".",
"path",
".",
"jo... | Creates a temporary copy of extracted submission.
When executed, submission is allowed to modify it's own directory. So
to ensure that submission does not pass any data between runs, new
copy of the submission is made before each run. After a run temporary copy
of submission is deleted.
Returns:
... | [
"Creates",
"a",
"temporary",
"copy",
"of",
"extracted",
"submission",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/worker.py#L311-L325 |
28,474 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/worker.py | ExecutableSubmission.run_without_time_limit | def run_without_time_limit(self, cmd):
"""Runs docker command without time limit.
Args:
cmd: list with the command line arguments which are passed to docker
binary
Returns:
how long it took to run submission in seconds
Raises:
WorkerError: if error occurred during execution ... | python | def run_without_time_limit(self, cmd):
"""Runs docker command without time limit.
Args:
cmd: list with the command line arguments which are passed to docker
binary
Returns:
how long it took to run submission in seconds
Raises:
WorkerError: if error occurred during execution ... | [
"def",
"run_without_time_limit",
"(",
"self",
",",
"cmd",
")",
":",
"cmd",
"=",
"[",
"DOCKER_BINARY",
",",
"'run'",
",",
"DOCKER_NVIDIA_RUNTIME",
"]",
"+",
"cmd",
"logging",
".",
"info",
"(",
"'Docker command: %s'",
",",
"' '",
".",
"join",
"(",
"cmd",
")"... | Runs docker command without time limit.
Args:
cmd: list with the command line arguments which are passed to docker
binary
Returns:
how long it took to run submission in seconds
Raises:
WorkerError: if error occurred during execution of the submission | [
"Runs",
"docker",
"command",
"without",
"time",
"limit",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/worker.py#L327-L350 |
28,475 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/worker.py | ExecutableSubmission.run_with_time_limit | def run_with_time_limit(self, cmd, time_limit=SUBMISSION_TIME_LIMIT):
"""Runs docker command and enforces time limit.
Args:
cmd: list with the command line arguments which are passed to docker
binary after run
time_limit: time limit, in seconds. Negative value means no limit.
Returns:
... | python | def run_with_time_limit(self, cmd, time_limit=SUBMISSION_TIME_LIMIT):
"""Runs docker command and enforces time limit.
Args:
cmd: list with the command line arguments which are passed to docker
binary after run
time_limit: time limit, in seconds. Negative value means no limit.
Returns:
... | [
"def",
"run_with_time_limit",
"(",
"self",
",",
"cmd",
",",
"time_limit",
"=",
"SUBMISSION_TIME_LIMIT",
")",
":",
"if",
"time_limit",
"<",
"0",
":",
"return",
"self",
".",
"run_without_time_limit",
"(",
"cmd",
")",
"container_name",
"=",
"str",
"(",
"uuid",
... | Runs docker command and enforces time limit.
Args:
cmd: list with the command line arguments which are passed to docker
binary after run
time_limit: time limit, in seconds. Negative value means no limit.
Returns:
how long it took to run submission in seconds
Raises:
Worker... | [
"Runs",
"docker",
"command",
"and",
"enforces",
"time",
"limit",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/worker.py#L352-L388 |
28,476 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/worker.py | DefenseSubmission.run | def run(self, input_dir, output_file_path):
"""Runs defense inside Docker.
Args:
input_dir: directory with input (adversarial images).
output_file_path: path of the output file.
Returns:
how long it took to run submission in seconds
"""
logging.info('Running defense %s', self.sub... | python | def run(self, input_dir, output_file_path):
"""Runs defense inside Docker.
Args:
input_dir: directory with input (adversarial images).
output_file_path: path of the output file.
Returns:
how long it took to run submission in seconds
"""
logging.info('Running defense %s', self.sub... | [
"def",
"run",
"(",
"self",
",",
"input_dir",
",",
"output_file_path",
")",
":",
"logging",
".",
"info",
"(",
"'Running defense %s'",
",",
"self",
".",
"submission_id",
")",
"tmp_run_dir",
"=",
"self",
".",
"temp_copy_extracted_submission",
"(",
")",
"output_dir"... | Runs defense inside Docker.
Args:
input_dir: directory with input (adversarial images).
output_file_path: path of the output file.
Returns:
how long it took to run submission in seconds | [
"Runs",
"defense",
"inside",
"Docker",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/worker.py#L462-L489 |
28,477 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/worker.py | EvaluationWorker.read_dataset_metadata | def read_dataset_metadata(self):
"""Read `dataset_meta` field from bucket"""
if self.dataset_meta:
return
shell_call(['gsutil', 'cp',
'gs://' + self.storage_client.bucket_name + '/'
+ 'dataset/' + self.dataset_name + '_dataset.csv',
LOCAL_DATASET_METADAT... | python | def read_dataset_metadata(self):
"""Read `dataset_meta` field from bucket"""
if self.dataset_meta:
return
shell_call(['gsutil', 'cp',
'gs://' + self.storage_client.bucket_name + '/'
+ 'dataset/' + self.dataset_name + '_dataset.csv',
LOCAL_DATASET_METADAT... | [
"def",
"read_dataset_metadata",
"(",
"self",
")",
":",
"if",
"self",
".",
"dataset_meta",
":",
"return",
"shell_call",
"(",
"[",
"'gsutil'",
",",
"'cp'",
",",
"'gs://'",
"+",
"self",
".",
"storage_client",
".",
"bucket_name",
"+",
"'/'",
"+",
"'dataset/'",
... | Read `dataset_meta` field from bucket | [
"Read",
"dataset_meta",
"field",
"from",
"bucket"
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/worker.py#L556-L565 |
28,478 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/worker.py | EvaluationWorker.fetch_attacks_data | def fetch_attacks_data(self):
"""Initializes data necessary to execute attacks.
This method could be called multiple times, only first call does
initialization, subsequent calls are noop.
"""
if self.attacks_data_initialized:
return
# init data from datastore
self.submissions.init_fro... | python | def fetch_attacks_data(self):
"""Initializes data necessary to execute attacks.
This method could be called multiple times, only first call does
initialization, subsequent calls are noop.
"""
if self.attacks_data_initialized:
return
# init data from datastore
self.submissions.init_fro... | [
"def",
"fetch_attacks_data",
"(",
"self",
")",
":",
"if",
"self",
".",
"attacks_data_initialized",
":",
"return",
"# init data from datastore",
"self",
".",
"submissions",
".",
"init_from_datastore",
"(",
")",
"self",
".",
"dataset_batches",
".",
"init_from_datastore"... | Initializes data necessary to execute attacks.
This method could be called multiple times, only first call does
initialization, subsequent calls are noop. | [
"Initializes",
"data",
"necessary",
"to",
"execute",
"attacks",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/worker.py#L567-L589 |
28,479 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/worker.py | EvaluationWorker.run_attack_work | def run_attack_work(self, work_id):
"""Runs one attack work.
Args:
work_id: ID of the piece of work to run
Returns:
elapsed_time_sec, submission_id - elapsed time and id of the submission
Raises:
WorkerError: if error occurred during execution.
"""
adv_batch_id = (
s... | python | def run_attack_work(self, work_id):
"""Runs one attack work.
Args:
work_id: ID of the piece of work to run
Returns:
elapsed_time_sec, submission_id - elapsed time and id of the submission
Raises:
WorkerError: if error occurred during execution.
"""
adv_batch_id = (
s... | [
"def",
"run_attack_work",
"(",
"self",
",",
"work_id",
")",
":",
"adv_batch_id",
"=",
"(",
"self",
".",
"attack_work",
".",
"work",
"[",
"work_id",
"]",
"[",
"'output_adversarial_batch_id'",
"]",
")",
"adv_batch",
"=",
"self",
".",
"adv_batches",
"[",
"adv_b... | Runs one attack work.
Args:
work_id: ID of the piece of work to run
Returns:
elapsed_time_sec, submission_id - elapsed time and id of the submission
Raises:
WorkerError: if error occurred during execution. | [
"Runs",
"one",
"attack",
"work",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/worker.py#L591-L687 |
28,480 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/worker.py | EvaluationWorker.run_attacks | def run_attacks(self):
"""Method which evaluates all attack work.
In a loop this method queries not completed attack work, picks one
attack work and runs it.
"""
logging.info('******** Start evaluation of attacks ********')
prev_submission_id = None
while True:
# wait until work is av... | python | def run_attacks(self):
"""Method which evaluates all attack work.
In a loop this method queries not completed attack work, picks one
attack work and runs it.
"""
logging.info('******** Start evaluation of attacks ********')
prev_submission_id = None
while True:
# wait until work is av... | [
"def",
"run_attacks",
"(",
"self",
")",
":",
"logging",
".",
"info",
"(",
"'******** Start evaluation of attacks ********'",
")",
"prev_submission_id",
"=",
"None",
"while",
"True",
":",
"# wait until work is available",
"self",
".",
"attack_work",
".",
"read_all_from_d... | Method which evaluates all attack work.
In a loop this method queries not completed attack work, picks one
attack work and runs it. | [
"Method",
"which",
"evaluates",
"all",
"attack",
"work",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/worker.py#L689-L732 |
28,481 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/worker.py | EvaluationWorker.fetch_defense_data | def fetch_defense_data(self):
"""Lazy initialization of data necessary to execute defenses."""
if self.defenses_data_initialized:
return
logging.info('Fetching defense data from datastore')
# init data from datastore
self.submissions.init_from_datastore()
self.dataset_batches.init_from_dat... | python | def fetch_defense_data(self):
"""Lazy initialization of data necessary to execute defenses."""
if self.defenses_data_initialized:
return
logging.info('Fetching defense data from datastore')
# init data from datastore
self.submissions.init_from_datastore()
self.dataset_batches.init_from_dat... | [
"def",
"fetch_defense_data",
"(",
"self",
")",
":",
"if",
"self",
".",
"defenses_data_initialized",
":",
"return",
"logging",
".",
"info",
"(",
"'Fetching defense data from datastore'",
")",
"# init data from datastore",
"self",
".",
"submissions",
".",
"init_from_datas... | Lazy initialization of data necessary to execute defenses. | [
"Lazy",
"initialization",
"of",
"data",
"necessary",
"to",
"execute",
"defenses",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/worker.py#L734-L746 |
28,482 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/worker.py | EvaluationWorker.run_defense_work | def run_defense_work(self, work_id):
"""Runs one defense work.
Args:
work_id: ID of the piece of work to run
Returns:
elapsed_time_sec, submission_id - elapsed time and id of the submission
Raises:
WorkerError: if error occurred during execution.
"""
class_batch_id = (
... | python | def run_defense_work(self, work_id):
"""Runs one defense work.
Args:
work_id: ID of the piece of work to run
Returns:
elapsed_time_sec, submission_id - elapsed time and id of the submission
Raises:
WorkerError: if error occurred during execution.
"""
class_batch_id = (
... | [
"def",
"run_defense_work",
"(",
"self",
",",
"work_id",
")",
":",
"class_batch_id",
"=",
"(",
"self",
".",
"defense_work",
".",
"work",
"[",
"work_id",
"]",
"[",
"'output_classification_batch_id'",
"]",
")",
"class_batch",
"=",
"self",
".",
"class_batches",
".... | Runs one defense work.
Args:
work_id: ID of the piece of work to run
Returns:
elapsed_time_sec, submission_id - elapsed time and id of the submission
Raises:
WorkerError: if error occurred during execution. | [
"Runs",
"one",
"defense",
"work",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/worker.py#L748-L824 |
28,483 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/worker.py | EvaluationWorker.run_defenses | def run_defenses(self):
"""Method which evaluates all defense work.
In a loop this method queries not completed defense work,
picks one defense work and runs it.
"""
logging.info('******** Start evaluation of defenses ********')
prev_submission_id = None
need_reload_work = True
while Tr... | python | def run_defenses(self):
"""Method which evaluates all defense work.
In a loop this method queries not completed defense work,
picks one defense work and runs it.
"""
logging.info('******** Start evaluation of defenses ********')
prev_submission_id = None
need_reload_work = True
while Tr... | [
"def",
"run_defenses",
"(",
"self",
")",
":",
"logging",
".",
"info",
"(",
"'******** Start evaluation of defenses ********'",
")",
"prev_submission_id",
"=",
"None",
"need_reload_work",
"=",
"True",
"while",
"True",
":",
"# wait until work is available",
"if",
"need_re... | Method which evaluates all defense work.
In a loop this method queries not completed defense work,
picks one defense work and runs it. | [
"Method",
"which",
"evaluates",
"all",
"defense",
"work",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/worker.py#L826-L890 |
28,484 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/worker.py | EvaluationWorker.run_work | def run_work(self):
"""Run attacks and defenses"""
if os.path.exists(LOCAL_EVAL_ROOT_DIR):
sudo_remove_dirtree(LOCAL_EVAL_ROOT_DIR)
self.run_attacks()
self.run_defenses() | python | def run_work(self):
"""Run attacks and defenses"""
if os.path.exists(LOCAL_EVAL_ROOT_DIR):
sudo_remove_dirtree(LOCAL_EVAL_ROOT_DIR)
self.run_attacks()
self.run_defenses() | [
"def",
"run_work",
"(",
"self",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"LOCAL_EVAL_ROOT_DIR",
")",
":",
"sudo_remove_dirtree",
"(",
"LOCAL_EVAL_ROOT_DIR",
")",
"self",
".",
"run_attacks",
"(",
")",
"self",
".",
"run_defenses",
"(",
")"
] | Run attacks and defenses | [
"Run",
"attacks",
"and",
"defenses"
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/worker.py#L892-L897 |
28,485 | tensorflow/cleverhans | cleverhans/attacks/attack.py | Attack.construct_graph | def construct_graph(self, fixed, feedable, x_val, hash_key):
"""
Construct the graph required to run the attack through generate_np.
:param fixed: Structural elements that require defining a new graph.
:param feedable: Arguments that can be fed to the same graph when
they take diff... | python | def construct_graph(self, fixed, feedable, x_val, hash_key):
"""
Construct the graph required to run the attack through generate_np.
:param fixed: Structural elements that require defining a new graph.
:param feedable: Arguments that can be fed to the same graph when
they take diff... | [
"def",
"construct_graph",
"(",
"self",
",",
"fixed",
",",
"feedable",
",",
"x_val",
",",
"hash_key",
")",
":",
"# try our very best to create a TF placeholder for each of the",
"# feedable keyword arguments, and check the types are one of",
"# the allowed types",
"class_name",
"=... | Construct the graph required to run the attack through generate_np.
:param fixed: Structural elements that require defining a new graph.
:param feedable: Arguments that can be fed to the same graph when
they take different values.
:param x_val: symbolic adversarial example
:param h... | [
"Construct",
"the",
"graph",
"required",
"to",
"run",
"the",
"attack",
"through",
"generate_np",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/cleverhans/attacks/attack.py#L113-L165 |
28,486 | tensorflow/cleverhans | cleverhans/attacks/attack.py | Attack.construct_variables | def construct_variables(self, kwargs):
"""
Construct the inputs to the attack graph to be used by generate_np.
:param kwargs: Keyword arguments to generate_np.
:return:
Structural arguments
Feedable arguments
Output of `arg_type` describing feedable arguments
A unique key
""... | python | def construct_variables(self, kwargs):
"""
Construct the inputs to the attack graph to be used by generate_np.
:param kwargs: Keyword arguments to generate_np.
:return:
Structural arguments
Feedable arguments
Output of `arg_type` describing feedable arguments
A unique key
""... | [
"def",
"construct_variables",
"(",
"self",
",",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"feedable_kwargs",
",",
"dict",
")",
":",
"warnings",
".",
"warn",
"(",
"\"Using a dict for `feedable_kwargs is deprecated.\"",
"\"Switch to using a tuple.\"",
"\... | Construct the inputs to the attack graph to be used by generate_np.
:param kwargs: Keyword arguments to generate_np.
:return:
Structural arguments
Feedable arguments
Output of `arg_type` describing feedable arguments
A unique key | [
"Construct",
"the",
"inputs",
"to",
"the",
"attack",
"graph",
"to",
"be",
"used",
"by",
"generate_np",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/cleverhans/attacks/attack.py#L202-L258 |
28,487 | tensorflow/cleverhans | examples/multigpu_advtrain/evaluator.py | create_adv_by_name | def create_adv_by_name(model, x, attack_type, sess, dataset, y=None, **kwargs):
"""
Creates the symbolic graph of an adversarial example given the name of
an attack. Simplifies creating the symbolic graph of an attack by defining
dataset-specific parameters.
Dataset-specific default parameters are used unless... | python | def create_adv_by_name(model, x, attack_type, sess, dataset, y=None, **kwargs):
"""
Creates the symbolic graph of an adversarial example given the name of
an attack. Simplifies creating the symbolic graph of an attack by defining
dataset-specific parameters.
Dataset-specific default parameters are used unless... | [
"def",
"create_adv_by_name",
"(",
"model",
",",
"x",
",",
"attack_type",
",",
"sess",
",",
"dataset",
",",
"y",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"# TODO: black box attacks",
"attack_names",
"=",
"{",
"'FGSM'",
":",
"FastGradientMethod",
",",
... | Creates the symbolic graph of an adversarial example given the name of
an attack. Simplifies creating the symbolic graph of an attack by defining
dataset-specific parameters.
Dataset-specific default parameters are used unless a different value is
given in kwargs.
:param model: an object of Model class
:pa... | [
"Creates",
"the",
"symbolic",
"graph",
"of",
"an",
"adversarial",
"example",
"given",
"the",
"name",
"of",
"an",
"attack",
".",
"Simplifies",
"creating",
"the",
"symbolic",
"graph",
"of",
"an",
"attack",
"by",
"defining",
"dataset",
"-",
"specific",
"parameter... | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/multigpu_advtrain/evaluator.py#L16-L66 |
28,488 | tensorflow/cleverhans | examples/multigpu_advtrain/evaluator.py | Evaluator.log_value | def log_value(self, tag, val, desc=''):
"""
Log values to standard output and Tensorflow summary.
:param tag: summary tag.
:param val: (required float or numpy array) value to be logged.
:param desc: (optional) additional description to be printed.
"""
logging.info('%s (%s): %.4f' % (desc, ... | python | def log_value(self, tag, val, desc=''):
"""
Log values to standard output and Tensorflow summary.
:param tag: summary tag.
:param val: (required float or numpy array) value to be logged.
:param desc: (optional) additional description to be printed.
"""
logging.info('%s (%s): %.4f' % (desc, ... | [
"def",
"log_value",
"(",
"self",
",",
"tag",
",",
"val",
",",
"desc",
"=",
"''",
")",
":",
"logging",
".",
"info",
"(",
"'%s (%s): %.4f'",
"%",
"(",
"desc",
",",
"tag",
",",
"val",
")",
")",
"self",
".",
"summary",
".",
"value",
".",
"add",
"(",
... | Log values to standard output and Tensorflow summary.
:param tag: summary tag.
:param val: (required float or numpy array) value to be logged.
:param desc: (optional) additional description to be printed. | [
"Log",
"values",
"to",
"standard",
"output",
"and",
"Tensorflow",
"summary",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/multigpu_advtrain/evaluator.py#L127-L136 |
28,489 | tensorflow/cleverhans | examples/multigpu_advtrain/evaluator.py | Evaluator.eval_advs | def eval_advs(self, x, y, preds_adv, X_test, Y_test, att_type):
"""
Evaluate the accuracy of the model on adversarial examples
:param x: symbolic input to model.
:param y: symbolic variable for the label.
:param preds_adv: symbolic variable for the prediction on an
adversarial... | python | def eval_advs(self, x, y, preds_adv, X_test, Y_test, att_type):
"""
Evaluate the accuracy of the model on adversarial examples
:param x: symbolic input to model.
:param y: symbolic variable for the label.
:param preds_adv: symbolic variable for the prediction on an
adversarial... | [
"def",
"eval_advs",
"(",
"self",
",",
"x",
",",
"y",
",",
"preds_adv",
",",
"X_test",
",",
"Y_test",
",",
"att_type",
")",
":",
"end",
"=",
"(",
"len",
"(",
"X_test",
")",
"//",
"self",
".",
"batch_size",
")",
"*",
"self",
".",
"batch_size",
"if",
... | Evaluate the accuracy of the model on adversarial examples
:param x: symbolic input to model.
:param y: symbolic variable for the label.
:param preds_adv: symbolic variable for the prediction on an
adversarial example.
:param X_test: NumPy array of test set inputs.
:param Y_te... | [
"Evaluate",
"the",
"accuracy",
"of",
"the",
"model",
"on",
"adversarial",
"examples"
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/multigpu_advtrain/evaluator.py#L138-L159 |
28,490 | tensorflow/cleverhans | examples/multigpu_advtrain/evaluator.py | Evaluator.eval_multi | def eval_multi(self, inc_epoch=True):
"""
Run the evaluation on multiple attacks.
"""
sess = self.sess
preds = self.preds
x = self.x_pre
y = self.y
X_train = self.X_train
Y_train = self.Y_train
X_test = self.X_test
Y_test = self.Y_test
writer = self.writer
self.summa... | python | def eval_multi(self, inc_epoch=True):
"""
Run the evaluation on multiple attacks.
"""
sess = self.sess
preds = self.preds
x = self.x_pre
y = self.y
X_train = self.X_train
Y_train = self.Y_train
X_test = self.X_test
Y_test = self.Y_test
writer = self.writer
self.summa... | [
"def",
"eval_multi",
"(",
"self",
",",
"inc_epoch",
"=",
"True",
")",
":",
"sess",
"=",
"self",
".",
"sess",
"preds",
"=",
"self",
".",
"preds",
"x",
"=",
"self",
".",
"x_pre",
"y",
"=",
"self",
".",
"y",
"X_train",
"=",
"self",
".",
"X_train",
"... | Run the evaluation on multiple attacks. | [
"Run",
"the",
"evaluation",
"on",
"multiple",
"attacks",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/multigpu_advtrain/evaluator.py#L161-L215 |
28,491 | tensorflow/cleverhans | cleverhans/compat.py | _wrap | def _wrap(f):
"""
Wraps a callable `f` in a function that warns that the function is deprecated.
"""
def wrapper(*args, **kwargs):
"""
Issues a deprecation warning and passes through the arguments.
"""
warnings.warn(str(f) + " is deprecated. Switch to calling the equivalent function in tensorflo... | python | def _wrap(f):
"""
Wraps a callable `f` in a function that warns that the function is deprecated.
"""
def wrapper(*args, **kwargs):
"""
Issues a deprecation warning and passes through the arguments.
"""
warnings.warn(str(f) + " is deprecated. Switch to calling the equivalent function in tensorflo... | [
"def",
"_wrap",
"(",
"f",
")",
":",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"\"\"\"\n Issues a deprecation warning and passes through the arguments.\n \"\"\"",
"warnings",
".",
"warn",
"(",
"str",
"(",
"f",
")",
"+",
"\" is d... | Wraps a callable `f` in a function that warns that the function is deprecated. | [
"Wraps",
"a",
"callable",
"f",
"in",
"a",
"function",
"that",
"warns",
"that",
"the",
"function",
"is",
"deprecated",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/cleverhans/compat.py#L14-L26 |
28,492 | tensorflow/cleverhans | cleverhans/compat.py | softmax_cross_entropy_with_logits | def softmax_cross_entropy_with_logits(sentinel=None,
labels=None,
logits=None,
dim=-1):
"""
Wrapper around tf.nn.softmax_cross_entropy_with_logits_v2 to handle
deprecated warning
"""
# Make sure t... | python | def softmax_cross_entropy_with_logits(sentinel=None,
labels=None,
logits=None,
dim=-1):
"""
Wrapper around tf.nn.softmax_cross_entropy_with_logits_v2 to handle
deprecated warning
"""
# Make sure t... | [
"def",
"softmax_cross_entropy_with_logits",
"(",
"sentinel",
"=",
"None",
",",
"labels",
"=",
"None",
",",
"logits",
"=",
"None",
",",
"dim",
"=",
"-",
"1",
")",
":",
"# Make sure that all arguments were passed as named arguments.",
"if",
"sentinel",
"is",
"not",
... | Wrapper around tf.nn.softmax_cross_entropy_with_logits_v2 to handle
deprecated warning | [
"Wrapper",
"around",
"tf",
".",
"nn",
".",
"softmax_cross_entropy_with_logits_v2",
"to",
"handle",
"deprecated",
"warning"
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/cleverhans/compat.py#L56-L81 |
28,493 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/eval_lib/dataset_helper.py | enforce_epsilon_and_compute_hash | def enforce_epsilon_and_compute_hash(dataset_batch_dir, adv_dir, output_dir,
epsilon):
"""Enforces size of perturbation on images, and compute hashes for all images.
Args:
dataset_batch_dir: directory with the images of specific dataset batch
adv_dir: directory with gen... | python | def enforce_epsilon_and_compute_hash(dataset_batch_dir, adv_dir, output_dir,
epsilon):
"""Enforces size of perturbation on images, and compute hashes for all images.
Args:
dataset_batch_dir: directory with the images of specific dataset batch
adv_dir: directory with gen... | [
"def",
"enforce_epsilon_and_compute_hash",
"(",
"dataset_batch_dir",
",",
"adv_dir",
",",
"output_dir",
",",
"epsilon",
")",
":",
"dataset_images",
"=",
"[",
"f",
"for",
"f",
"in",
"os",
".",
"listdir",
"(",
"dataset_batch_dir",
")",
"if",
"f",
".",
"endswith"... | Enforces size of perturbation on images, and compute hashes for all images.
Args:
dataset_batch_dir: directory with the images of specific dataset batch
adv_dir: directory with generated adversarial images
output_dir: directory where to copy result
epsilon: size of perturbation
Returns:
dictio... | [
"Enforces",
"size",
"of",
"perturbation",
"on",
"images",
"and",
"compute",
"hashes",
"for",
"all",
"images",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/dataset_helper.py#L81-L124 |
28,494 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/eval_lib/dataset_helper.py | download_dataset | def download_dataset(storage_client, image_batches, target_dir,
local_dataset_copy=None):
"""Downloads dataset, organize it by batches and rename images.
Args:
storage_client: instance of the CompetitionStorageClient
image_batches: subclass of ImageBatchesBase with data about images
... | python | def download_dataset(storage_client, image_batches, target_dir,
local_dataset_copy=None):
"""Downloads dataset, organize it by batches and rename images.
Args:
storage_client: instance of the CompetitionStorageClient
image_batches: subclass of ImageBatchesBase with data about images
... | [
"def",
"download_dataset",
"(",
"storage_client",
",",
"image_batches",
",",
"target_dir",
",",
"local_dataset_copy",
"=",
"None",
")",
":",
"for",
"batch_id",
",",
"batch_value",
"in",
"iteritems",
"(",
"image_batches",
".",
"data",
")",
":",
"batch_dir",
"=",
... | Downloads dataset, organize it by batches and rename images.
Args:
storage_client: instance of the CompetitionStorageClient
image_batches: subclass of ImageBatchesBase with data about images
target_dir: target directory, should exist and be empty
local_dataset_copy: directory with local dataset copy,... | [
"Downloads",
"dataset",
"organize",
"it",
"by",
"batches",
"and",
"rename",
"images",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/dataset_helper.py#L127-L159 |
28,495 | tensorflow/cleverhans | examples/nips17_adversarial_competition/eval_infra/code/eval_lib/dataset_helper.py | DatasetMetadata.save_target_classes_for_batch | def save_target_classes_for_batch(self,
filename,
image_batches,
batch_id):
"""Saves file with target class for given dataset batch.
Args:
filename: output filename
image_batches: instance of... | python | def save_target_classes_for_batch(self,
filename,
image_batches,
batch_id):
"""Saves file with target class for given dataset batch.
Args:
filename: output filename
image_batches: instance of... | [
"def",
"save_target_classes_for_batch",
"(",
"self",
",",
"filename",
",",
"image_batches",
",",
"batch_id",
")",
":",
"images",
"=",
"image_batches",
".",
"data",
"[",
"batch_id",
"]",
"[",
"'images'",
"]",
"with",
"open",
"(",
"filename",
",",
"'w'",
")",
... | Saves file with target class for given dataset batch.
Args:
filename: output filename
image_batches: instance of ImageBatchesBase with dataset batches
batch_id: dataset batch ID | [
"Saves",
"file",
"with",
"target",
"class",
"for",
"given",
"dataset",
"batch",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/dataset_helper.py#L63-L78 |
28,496 | tensorflow/cleverhans | cleverhans/experimental/certification/optimization.py | Optimization.tf_min_eig_vec | def tf_min_eig_vec(self):
"""Function for min eigen vector using tf's full eigen decomposition."""
# Full eigen decomposition requires the explicit psd matrix M
_, matrix_m = self.dual_object.get_full_psd_matrix()
[eig_vals, eig_vectors] = tf.self_adjoint_eig(matrix_m)
index = tf.argmin(eig_vals)
... | python | def tf_min_eig_vec(self):
"""Function for min eigen vector using tf's full eigen decomposition."""
# Full eigen decomposition requires the explicit psd matrix M
_, matrix_m = self.dual_object.get_full_psd_matrix()
[eig_vals, eig_vectors] = tf.self_adjoint_eig(matrix_m)
index = tf.argmin(eig_vals)
... | [
"def",
"tf_min_eig_vec",
"(",
"self",
")",
":",
"# Full eigen decomposition requires the explicit psd matrix M",
"_",
",",
"matrix_m",
"=",
"self",
".",
"dual_object",
".",
"get_full_psd_matrix",
"(",
")",
"[",
"eig_vals",
",",
"eig_vectors",
"]",
"=",
"tf",
".",
... | Function for min eigen vector using tf's full eigen decomposition. | [
"Function",
"for",
"min",
"eigen",
"vector",
"using",
"tf",
"s",
"full",
"eigen",
"decomposition",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/cleverhans/experimental/certification/optimization.py#L56-L63 |
28,497 | tensorflow/cleverhans | cleverhans/experimental/certification/optimization.py | Optimization.tf_smooth_eig_vec | def tf_smooth_eig_vec(self):
"""Function that returns smoothed version of min eigen vector."""
_, matrix_m = self.dual_object.get_full_psd_matrix()
# Easier to think in terms of max so negating the matrix
[eig_vals, eig_vectors] = tf.self_adjoint_eig(-matrix_m)
exp_eig_vals = tf.exp(tf.divide(eig_va... | python | def tf_smooth_eig_vec(self):
"""Function that returns smoothed version of min eigen vector."""
_, matrix_m = self.dual_object.get_full_psd_matrix()
# Easier to think in terms of max so negating the matrix
[eig_vals, eig_vectors] = tf.self_adjoint_eig(-matrix_m)
exp_eig_vals = tf.exp(tf.divide(eig_va... | [
"def",
"tf_smooth_eig_vec",
"(",
"self",
")",
":",
"_",
",",
"matrix_m",
"=",
"self",
".",
"dual_object",
".",
"get_full_psd_matrix",
"(",
")",
"# Easier to think in terms of max so negating the matrix",
"[",
"eig_vals",
",",
"eig_vectors",
"]",
"=",
"tf",
".",
"s... | Function that returns smoothed version of min eigen vector. | [
"Function",
"that",
"returns",
"smoothed",
"version",
"of",
"min",
"eigen",
"vector",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/cleverhans/experimental/certification/optimization.py#L65-L79 |
28,498 | tensorflow/cleverhans | cleverhans/experimental/certification/optimization.py | Optimization.get_min_eig_vec_proxy | def get_min_eig_vec_proxy(self, use_tf_eig=False):
"""Computes the min eigen value and corresponding vector of matrix M.
Args:
use_tf_eig: Whether to use tf's default full eigen decomposition
Returns:
eig_vec: Minimum absolute eigen value
eig_val: Corresponding eigen vector
"""
if... | python | def get_min_eig_vec_proxy(self, use_tf_eig=False):
"""Computes the min eigen value and corresponding vector of matrix M.
Args:
use_tf_eig: Whether to use tf's default full eigen decomposition
Returns:
eig_vec: Minimum absolute eigen value
eig_val: Corresponding eigen vector
"""
if... | [
"def",
"get_min_eig_vec_proxy",
"(",
"self",
",",
"use_tf_eig",
"=",
"False",
")",
":",
"if",
"use_tf_eig",
":",
"# If smoothness parameter is too small, essentially no smoothing",
"# Just output the eigen vector corresponding to min",
"return",
"tf",
".",
"cond",
"(",
"self"... | Computes the min eigen value and corresponding vector of matrix M.
Args:
use_tf_eig: Whether to use tf's default full eigen decomposition
Returns:
eig_vec: Minimum absolute eigen value
eig_val: Corresponding eigen vector | [
"Computes",
"the",
"min",
"eigen",
"value",
"and",
"corresponding",
"vector",
"of",
"matrix",
"M",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/cleverhans/experimental/certification/optimization.py#L81-L109 |
28,499 | tensorflow/cleverhans | cleverhans/experimental/certification/optimization.py | Optimization.get_scipy_eig_vec | def get_scipy_eig_vec(self):
"""Computes scipy estimate of min eigenvalue for matrix M.
Returns:
eig_vec: Minimum absolute eigen value
eig_val: Corresponding eigen vector
"""
if not self.params['has_conv']:
matrix_m = self.sess.run(self.dual_object.matrix_m)
min_eig_vec_val, est... | python | def get_scipy_eig_vec(self):
"""Computes scipy estimate of min eigenvalue for matrix M.
Returns:
eig_vec: Minimum absolute eigen value
eig_val: Corresponding eigen vector
"""
if not self.params['has_conv']:
matrix_m = self.sess.run(self.dual_object.matrix_m)
min_eig_vec_val, est... | [
"def",
"get_scipy_eig_vec",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"params",
"[",
"'has_conv'",
"]",
":",
"matrix_m",
"=",
"self",
".",
"sess",
".",
"run",
"(",
"self",
".",
"dual_object",
".",
"matrix_m",
")",
"min_eig_vec_val",
",",
"estimate... | Computes scipy estimate of min eigenvalue for matrix M.
Returns:
eig_vec: Minimum absolute eigen value
eig_val: Corresponding eigen vector | [
"Computes",
"scipy",
"estimate",
"of",
"min",
"eigenvalue",
"for",
"matrix",
"M",
"."
] | 97488e215760547b81afc53f5e5de8ba7da5bd98 | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/cleverhans/experimental/certification/optimization.py#L111-L138 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.