hexsha stringlengths 40 40 | repo stringlengths 7 114 | path stringlengths 4 124 | license listlengths 1 9 | language stringclasses 1
value | identifier stringlengths 1 71 | return_type stringlengths 1 749 ⌀ | original_string stringlengths 76 22.7k | original_docstring stringlengths 16 7.61k | docstring stringlengths 16 2.47k | docstring_tokens listlengths 6 477 | code stringlengths 14 10.2k | code_tokens listlengths 6 996 | short_docstring stringlengths 2 644 | short_docstring_tokens listlengths 1 116 | comment listlengths 1 89 | parameters listlengths 0 64 | docstring_params dict |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
66dca13bfba4815f397a1bd634b932a34ffadc8e | Livit/Labster.OAuth2Client | oauth2_client/fetcher.py | [
"MIT"
] | Python | fetch_raw_token | <not_specific> | def fetch_raw_token(self):
"""
Fetch token using Client Credentials Flow
Returns:
dict: raw token from provider
"""
client = BackendApplicationClient(client_id=self.app.client_id)
oauth = OAuth2Session(client=client)
return oauth.fetch_token(
... |
Fetch token using Client Credentials Flow
Returns:
dict: raw token from provider
| Fetch token using Client Credentials Flow | [
"Fetch",
"token",
"using",
"Client",
"Credentials",
"Flow"
] | def fetch_raw_token(self):
client = BackendApplicationClient(client_id=self.app.client_id)
oauth = OAuth2Session(client=client)
return oauth.fetch_token(
token_url=self.app.token_uri,
client_id=self.app.client_id,
client_secret=self.app.client_secret,
... | [
"def",
"fetch_raw_token",
"(",
"self",
")",
":",
"client",
"=",
"BackendApplicationClient",
"(",
"client_id",
"=",
"self",
".",
"app",
".",
"client_id",
")",
"oauth",
"=",
"OAuth2Session",
"(",
"client",
"=",
"client",
")",
"return",
"oauth",
".",
"fetch_tok... | Fetch token using Client Credentials Flow | [
"Fetch",
"token",
"using",
"Client",
"Credentials",
"Flow"
] | [
"\"\"\"\n Fetch token using Client Credentials Flow\n\n Returns:\n dict: raw token from provider\n \"\"\""
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [
{
"docstring": "raw token from provider",
"docstring_tokens": [
"raw",
"token",
"from",
"provider"
],
"type": "dict"
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
... |
66dca13bfba4815f397a1bd634b932a34ffadc8e | Livit/Labster.OAuth2Client | oauth2_client/fetcher.py | [
"MIT"
] | Python | expiry_date | <not_specific> | def expiry_date(raw_token):
"""
Determine token's expiry date if available. The RFC isn't strict about this,
so aren't we. JWT Bearer grant type doesn't return expiration info at all.
The preference of the source of this data is:
1. `expires_in`, interpreted as seconds from now
2. `expi... |
Determine token's expiry date if available. The RFC isn't strict about this,
so aren't we. JWT Bearer grant type doesn't return expiration info at all.
The preference of the source of this data is:
1. `expires_in`, interpreted as seconds from now
2. `expires_at`, interpreted as a timestamp... | Determine token's expiry date if available. The RFC isn't strict about this,
so aren't we. JWT Bearer grant type doesn't return expiration info at all.
The preference of the source of this data is:
1. `expires_in`, interpreted as seconds from now
2. `expires_at`, interpreted as a timestamp from epoch in UTC
From RFC:... | [
"Determine",
"token",
"'",
"s",
"expiry",
"date",
"if",
"available",
".",
"The",
"RFC",
"isn",
"'",
"t",
"strict",
"about",
"this",
"so",
"aren",
"'",
"t",
"we",
".",
"JWT",
"Bearer",
"grant",
"type",
"doesn",
"'",
"t",
"return",
"expiration",
"info",
... | def expiry_date(raw_token):
if 'expires_in' in raw_token:
expires = timezone.now() + timedelta(seconds=raw_token['expires_in'])
elif 'expires_at' in raw_token:
expires = float_to_datetime(raw_token['expires_at'], tzinfo=pytz.UTC)
else:
expires = None
if expires and expires <= tim... | [
"def",
"expiry_date",
"(",
"raw_token",
")",
":",
"if",
"'expires_in'",
"in",
"raw_token",
":",
"expires",
"=",
"timezone",
".",
"now",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"raw_token",
"[",
"'expires_in'",
"]",
")",
"elif",
"'expires_at'",
"in... | Determine token's expiry date if available. | [
"Determine",
"token",
"'",
"s",
"expiry",
"date",
"if",
"available",
"."
] | [
"\"\"\"\n Determine token's expiry date if available. The RFC isn't strict about this,\n so aren't we. JWT Bearer grant type doesn't return expiration info at all.\n\n The preference of the source of this data is:\n 1. `expires_in`, interpreted as seconds from now\n 2. `expires_at`, interpret... | [
{
"param": "raw_token",
"type": null
}
] | {
"returns": [
{
"docstring": "a timezone-aware datetime object or None",
"docstring_tokens": [
"a",
"timezone",
"-",
"aware",
"datetime",
"object",
"or",
"None"
],
"type": "datetime"
}
],
"raises": [
{
"docs... |
e752a3a4e3a8b1195b5b257cdc48fd687370fb42 | Livit/Labster.OAuth2Client | tests/test_oauth2maker_cmd.py | [
"MIT"
] | Python | command_type_with_model | <not_specific> | def command_type_with_model(model_type):
"""
Convenience function for testing. Create `oauth2_app_maker` extension
class bound to the specified model type.
"""
from tests.ide_test_compat import AbstractAppMaker
class Command(AbstractAppMaker):
@classmethod
def app_model(cls):
... |
Convenience function for testing. Create `oauth2_app_maker` extension
class bound to the specified model type.
| Convenience function for testing. Create `oauth2_app_maker` extension
class bound to the specified model type. | [
"Convenience",
"function",
"for",
"testing",
".",
"Create",
"`",
"oauth2_app_maker",
"`",
"extension",
"class",
"bound",
"to",
"the",
"specified",
"model",
"type",
"."
] | def command_type_with_model(model_type):
from tests.ide_test_compat import AbstractAppMaker
class Command(AbstractAppMaker):
@classmethod
def app_model(cls):
return model_type
return Command | [
"def",
"command_type_with_model",
"(",
"model_type",
")",
":",
"from",
"tests",
".",
"ide_test_compat",
"import",
"AbstractAppMaker",
"class",
"Command",
"(",
"AbstractAppMaker",
")",
":",
"@",
"classmethod",
"def",
"app_model",
"(",
"cls",
")",
":",
"return",
"... | Convenience function for testing. | [
"Convenience",
"function",
"for",
"testing",
"."
] | [
"\"\"\"\n Convenience function for testing. Create `oauth2_app_maker` extension\n class bound to the specified model type.\n \"\"\""
] | [
{
"param": "model_type",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "model_type",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b5d69f027cd8e7fd4f482b65dabca712a7526ec8 | Livit/Labster.OAuth2Client | oauth2_client/client.py | [
"MIT"
] | Python | request | <not_specific> | def request(self, method, url, *args, **kwargs): # pylint: disable=arguments-differ
"""
Intercepts all requests, transforms relative URL to absolute and add the OAuth 2 token if present.
Any communication issues are indicated by raising `CircuitBreakerError`. In this case communication
... |
Intercepts all requests, transforms relative URL to absolute and add the OAuth 2 token if present.
Any communication issues are indicated by raising `CircuitBreakerError`. In this case communication
can be reattempted in 10s, after the breaker resets.
Arguments:
method (str... | Intercepts all requests, transforms relative URL to absolute and add the OAuth 2 token if present.
Any communication issues are indicated by raising `CircuitBreakerError`. In this case communication
can be reattempted in 10s, after the breaker resets. | [
"Intercepts",
"all",
"requests",
"transforms",
"relative",
"URL",
"to",
"absolute",
"and",
"add",
"the",
"OAuth",
"2",
"token",
"if",
"present",
".",
"Any",
"communication",
"issues",
"are",
"indicated",
"by",
"raising",
"`",
"CircuitBreakerError",
"`",
".",
"... | def request(self, method, url, *args, **kwargs):
absolute_url = urljoin(self.service_host, url)
try:
return self.make_request(method, absolute_url, *args, **kwargs)
except TokenExpiredError:
log.debug("Attempting to fetch a new token for %s", self.app)
new_t... | [
"def",
"request",
"(",
"self",
",",
"method",
",",
"url",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"absolute_url",
"=",
"urljoin",
"(",
"self",
".",
"service_host",
",",
"url",
")",
"try",
":",
"return",
"self",
".",
"make_request",
"(",
"met... | Intercepts all requests, transforms relative URL to absolute and add the OAuth 2 token if present. | [
"Intercepts",
"all",
"requests",
"transforms",
"relative",
"URL",
"to",
"absolute",
"and",
"add",
"the",
"OAuth",
"2",
"token",
"if",
"present",
"."
] | [
"# pylint: disable=arguments-differ",
"\"\"\"\n Intercepts all requests, transforms relative URL to absolute and add the OAuth 2 token if present.\n Any communication issues are indicated by raising `CircuitBreakerError`. In this case communication\n can be reattempted in 10s, after the break... | [
{
"param": "self",
"type": null
},
{
"param": "method",
"type": null
},
{
"param": "url",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [
{
"docstring": "1) token expiry was detected and new token fetched, but we still get errors in\ncommunication upon retrying request\n2) any unexpected error when hand... |
b5d69f027cd8e7fd4f482b65dabca712a7526ec8 | Livit/Labster.OAuth2Client | oauth2_client/client.py | [
"MIT"
] | Python | fetch_and_store_token | <not_specific> | def fetch_and_store_token(app):
"""
Obtain a new token from auth provider and store in database. If unable to
parse received data as an AccessToken - wait 2s and try to fetch again. If
still unable - raise KeyError.
Arguments:
app (oauth2_client.models.Application): oauth application instan... |
Obtain a new token from auth provider and store in database. If unable to
parse received data as an AccessToken - wait 2s and try to fetch again. If
still unable - raise KeyError.
Arguments:
app (oauth2_client.models.Application): oauth application instance
Returns:
oauth2_client.... | Obtain a new token from auth provider and store in database. If unable to
parse received data as an AccessToken - wait 2s and try to fetch again. If
still unable - raise KeyError. | [
"Obtain",
"a",
"new",
"token",
"from",
"auth",
"provider",
"and",
"store",
"in",
"database",
".",
"If",
"unable",
"to",
"parse",
"received",
"data",
"as",
"an",
"AccessToken",
"-",
"wait",
"2s",
"and",
"try",
"to",
"fetch",
"again",
".",
"If",
"still",
... | def fetch_and_store_token(app):
token = fetch_token(app)
token.save()
log.debug('Fetched and stored %s', token)
return token | [
"def",
"fetch_and_store_token",
"(",
"app",
")",
":",
"token",
"=",
"fetch_token",
"(",
"app",
")",
"token",
".",
"save",
"(",
")",
"log",
".",
"debug",
"(",
"'Fetched and stored %s'",
",",
"token",
")",
"return",
"token"
] | Obtain a new token from auth provider and store in database. | [
"Obtain",
"a",
"new",
"token",
"from",
"auth",
"provider",
"and",
"store",
"in",
"database",
"."
] | [
"\"\"\"\n Obtain a new token from auth provider and store in database. If unable to\n parse received data as an AccessToken - wait 2s and try to fetch again. If\n still unable - raise KeyError.\n\n Arguments:\n app (oauth2_client.models.Application): oauth application instance\n\n Returns:\n ... | [
{
"param": "app",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": "oauth2_client.models.AccessToken"
}
],
"raises": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": "KeyError"
}
],
"params": [
{
"... |
ca271a6862a715c8e14362c01bc172799f8e6ef1 | lovesh/indy-agent | test-suite/conftest.py | [
"Apache-2.0"
] | Python | config | null | async def config():
""" Gather configuration and initialize the wallet.
"""
DEFAULT_CONFIG_PATH = 'config.toml'
print('\n\nLoading test configuration from file: {}'.format(DEFAULT_CONFIG_PATH))
config = Config.from_file(DEFAULT_CONFIG_PATH)
parser = Config.get_arg_parser()
args = parser.pa... | Gather configuration and initialize the wallet.
| Gather configuration and initialize the wallet. | [
"Gather",
"configuration",
"and",
"initialize",
"the",
"wallet",
"."
] | async def config():
DEFAULT_CONFIG_PATH = 'config.toml'
print('\n\nLoading test configuration from file: {}'.format(DEFAULT_CONFIG_PATH))
config = Config.from_file(DEFAULT_CONFIG_PATH)
parser = Config.get_arg_parser()
args = parser.parse_args()
if args:
config.update(vars(args))
yiel... | [
"async",
"def",
"config",
"(",
")",
":",
"DEFAULT_CONFIG_PATH",
"=",
"'config.toml'",
"print",
"(",
"'\\n\\nLoading test configuration from file: {}'",
".",
"format",
"(",
"DEFAULT_CONFIG_PATH",
")",
")",
"config",
"=",
"Config",
".",
"from_file",
"(",
"DEFAULT_CONFIG... | Gather configuration and initialize the wallet. | [
"Gather",
"configuration",
"and",
"initialize",
"the",
"wallet",
"."
] | [
"\"\"\" Gather configuration and initialize the wallet.\n \"\"\"",
"# TODO: Cleanup?"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
ca271a6862a715c8e14362c01bc172799f8e6ef1 | lovesh/indy-agent | test-suite/conftest.py | [
"Apache-2.0"
] | Python | transport | <not_specific> | async def transport(config, event_loop, logger):
""" Transport fixture.
Initializes the transport layer.
"""
MSG_Q = asyncio.Queue()
if config.transport == "http":
transport = HTTPTransport(config, logger, MSG_Q)
else:
transport = None
logger.debug("Starting transport")... | Transport fixture.
Initializes the transport layer.
| Transport fixture.
Initializes the transport layer. | [
"Transport",
"fixture",
".",
"Initializes",
"the",
"transport",
"layer",
"."
] | async def transport(config, event_loop, logger):
MSG_Q = asyncio.Queue()
if config.transport == "http":
transport = HTTPTransport(config, logger, MSG_Q)
else:
transport = None
logger.debug("Starting transport")
event_loop.create_task(transport.start_server())
return transport | [
"async",
"def",
"transport",
"(",
"config",
",",
"event_loop",
",",
"logger",
")",
":",
"MSG_Q",
"=",
"asyncio",
".",
"Queue",
"(",
")",
"if",
"config",
".",
"transport",
"==",
"\"http\"",
":",
"transport",
"=",
"HTTPTransport",
"(",
"config",
",",
"logg... | Transport fixture. | [
"Transport",
"fixture",
"."
] | [
"\"\"\" Transport fixture.\n\n Initializes the transport layer.\n \"\"\""
] | [
{
"param": "config",
"type": null
},
{
"param": "event_loop",
"type": null
},
{
"param": "logger",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "config",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "event_loop",
"type": null,
"docstring": null,
"docstring_to... |
ca271a6862a715c8e14362c01bc172799f8e6ef1 | lovesh/indy-agent | test-suite/conftest.py | [
"Apache-2.0"
] | Python | repr_failure | <not_specific> | def repr_failure(self, excinfo):
""" called when self.runtest() raises an exception. """
if not self.parent.test_failed:
self.parent.test_failed = True
if self.parent.test_failed and self.parent.last_child() == self.func:
self.add_report_section(self.feature, "Feature De... | called when self.runtest() raises an exception. | called when self.runtest() raises an exception. | [
"called",
"when",
"self",
".",
"runtest",
"()",
"raises",
"an",
"exception",
"."
] | def repr_failure(self, excinfo):
if not self.parent.test_failed:
self.parent.test_failed = True
if self.parent.test_failed and self.parent.last_child() == self.func:
self.add_report_section(self.feature, "Feature Description:", self.parent.description)
return self._repr_f... | [
"def",
"repr_failure",
"(",
"self",
",",
"excinfo",
")",
":",
"if",
"not",
"self",
".",
"parent",
".",
"test_failed",
":",
"self",
".",
"parent",
".",
"test_failed",
"=",
"True",
"if",
"self",
".",
"parent",
".",
"test_failed",
"and",
"self",
".",
"par... | called when self.runtest() raises an exception. | [
"called",
"when",
"self",
".",
"runtest",
"()",
"raises",
"an",
"exception",
"."
] | [
"\"\"\" called when self.runtest() raises an exception. \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "excinfo",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "excinfo",
"type": null,
"docstring": null,
"docstring_tokens"... |
3066fc64aecb6747b96c2725b1c87e8a724467a9 | mesepulveda/wsnsim | wsnsim/routing/base_routing_protocol.py | [
"MIT"
] | Python | _log_output_queue_message | None | def _log_output_queue_message(self, message: str, destination: str) -> None:
"""Logs the timestamp when a message arrives to output queue."""
self._output_queue_messages.append((self.env.now,
message,
destination)) | Logs the timestamp when a message arrives to output queue. | Logs the timestamp when a message arrives to output queue. | [
"Logs",
"the",
"timestamp",
"when",
"a",
"message",
"arrives",
"to",
"output",
"queue",
"."
] | def _log_output_queue_message(self, message: str, destination: str) -> None:
self._output_queue_messages.append((self.env.now,
message,
destination)) | [
"def",
"_log_output_queue_message",
"(",
"self",
",",
"message",
":",
"str",
",",
"destination",
":",
"str",
")",
"->",
"None",
":",
"self",
".",
"_output_queue_messages",
".",
"append",
"(",
"(",
"self",
".",
"env",
".",
"now",
",",
"message",
",",
"des... | Logs the timestamp when a message arrives to output queue. | [
"Logs",
"the",
"timestamp",
"when",
"a",
"message",
"arrives",
"to",
"output",
"queue",
"."
] | [
"\"\"\"Logs the timestamp when a message arrives to output queue.\"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "message",
"type": "str"
},
{
"param": "destination",
"type": "str"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "message",
"type": "str",
"docstring": null,
"docstring_tokens... |
94786f8bdec21ea53d6e089c9e15169da95d730c | mesepulveda/wsnsim | wsnsim/auxiliary_functions.py | [
"MIT"
] | Python | print_with_asterisks | Callable[..., None] | def print_with_asterisks(function: Callable[..., None]) -> Callable[..., None]:
"""Used as a decorator.
Adds asterisks before and after the execution of a function.
"""
def inner(*args, **kwargs):
"""Adds asterisks before and after the execution of a function."""
number_of_asterisks = 5... | Used as a decorator.
Adds asterisks before and after the execution of a function.
| Used as a decorator.
Adds asterisks before and after the execution of a function. | [
"Used",
"as",
"a",
"decorator",
".",
"Adds",
"asterisks",
"before",
"and",
"after",
"the",
"execution",
"of",
"a",
"function",
"."
] | def print_with_asterisks(function: Callable[..., None]) -> Callable[..., None]:
def inner(*args, **kwargs):
number_of_asterisks = 50
print('*' * number_of_asterisks)
function(*args, **kwargs)
print('*' * number_of_asterisks)
return inner | [
"def",
"print_with_asterisks",
"(",
"function",
":",
"Callable",
"[",
"...",
",",
"None",
"]",
")",
"->",
"Callable",
"[",
"...",
",",
"None",
"]",
":",
"def",
"inner",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"\"\"\"Adds asterisks before and after... | Used as a decorator. | [
"Used",
"as",
"a",
"decorator",
"."
] | [
"\"\"\"Used as a decorator.\n\n Adds asterisks before and after the execution of a function.\n \"\"\"",
"\"\"\"Adds asterisks before and after the execution of a function.\"\"\""
] | [
{
"param": "function",
"type": "Callable[..., None]"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "function",
"type": "Callable[..., None]",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
94786f8bdec21ea53d6e089c9e15169da95d730c | mesepulveda/wsnsim | wsnsim/auxiliary_functions.py | [
"MIT"
] | Python | inner | null | def inner(*args, **kwargs):
"""Adds asterisks before and after the execution of a function."""
number_of_asterisks = 50
print('*' * number_of_asterisks)
function(*args, **kwargs)
print('*' * number_of_asterisks) | Adds asterisks before and after the execution of a function. | Adds asterisks before and after the execution of a function. | [
"Adds",
"asterisks",
"before",
"and",
"after",
"the",
"execution",
"of",
"a",
"function",
"."
] | def inner(*args, **kwargs):
number_of_asterisks = 50
print('*' * number_of_asterisks)
function(*args, **kwargs)
print('*' * number_of_asterisks) | [
"def",
"inner",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"number_of_asterisks",
"=",
"50",
"print",
"(",
"'*'",
"*",
"number_of_asterisks",
")",
"function",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
"print",
"(",
"'*'",
"*",
"number_of_asterisk... | Adds asterisks before and after the execution of a function. | [
"Adds",
"asterisks",
"before",
"and",
"after",
"the",
"execution",
"of",
"a",
"function",
"."
] | [
"\"\"\"Adds asterisks before and after the execution of a function.\"\"\""
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
94786f8bdec21ea53d6e089c9e15169da95d730c | mesepulveda/wsnsim | wsnsim/auxiliary_functions.py | [
"MIT"
] | Python | ensure_positive_value | Callable[..., float] | def ensure_positive_value(function: Callable[..., float]) \
-> Callable[..., float]:
"""Used as a decorator.
Ensures that the value is 0 or positive.
"""
def inner(*args, **kwargs):
"""Ensures that the value is 0 or positive."""
value = function(*args, **kwargs)
if value... | Used as a decorator.
Ensures that the value is 0 or positive.
| Used as a decorator.
Ensures that the value is 0 or positive. | [
"Used",
"as",
"a",
"decorator",
".",
"Ensures",
"that",
"the",
"value",
"is",
"0",
"or",
"positive",
"."
] | def ensure_positive_value(function: Callable[..., float]) \
-> Callable[..., float]:
def inner(*args, **kwargs):
value = function(*args, **kwargs)
if value < 0:
raise ValueError('Value obtained is negative')
return value
return inner | [
"def",
"ensure_positive_value",
"(",
"function",
":",
"Callable",
"[",
"...",
",",
"float",
"]",
")",
"->",
"Callable",
"[",
"...",
",",
"float",
"]",
":",
"def",
"inner",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"\"\"\"Ensures that the value is 0 ... | Used as a decorator. | [
"Used",
"as",
"a",
"decorator",
"."
] | [
"\"\"\"Used as a decorator.\n\n Ensures that the value is 0 or positive.\n \"\"\"",
"\"\"\"Ensures that the value is 0 or positive.\"\"\""
] | [
{
"param": "function",
"type": "Callable[..., float]"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "function",
"type": "Callable[..., float]",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
94786f8bdec21ea53d6e089c9e15169da95d730c | mesepulveda/wsnsim | wsnsim/auxiliary_functions.py | [
"MIT"
] | Python | inner | <not_specific> | def inner(*args, **kwargs):
"""Ensures that the value is 0 or positive."""
value = function(*args, **kwargs)
if value < 0:
raise ValueError('Value obtained is negative')
return value | Ensures that the value is 0 or positive. | Ensures that the value is 0 or positive. | [
"Ensures",
"that",
"the",
"value",
"is",
"0",
"or",
"positive",
"."
] | def inner(*args, **kwargs):
value = function(*args, **kwargs)
if value < 0:
raise ValueError('Value obtained is negative')
return value | [
"def",
"inner",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"value",
"=",
"function",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
"if",
"value",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"'Value obtained is negative'",
")",
"return",
"value"
] | Ensures that the value is 0 or positive. | [
"Ensures",
"that",
"the",
"value",
"is",
"0",
"or",
"positive",
"."
] | [
"\"\"\"Ensures that the value is 0 or positive.\"\"\""
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
94786f8bdec21ea53d6e089c9e15169da95d730c | mesepulveda/wsnsim | wsnsim/auxiliary_functions.py | [
"MIT"
] | Python | is_hello_message | bool | def is_hello_message(message: str) -> bool:
"""Checks if a message is a hello message."""
if "Hello" in message:
return True
return False | Checks if a message is a hello message. | Checks if a message is a hello message. | [
"Checks",
"if",
"a",
"message",
"is",
"a",
"hello",
"message",
"."
] | def is_hello_message(message: str) -> bool:
if "Hello" in message:
return True
return False | [
"def",
"is_hello_message",
"(",
"message",
":",
"str",
")",
"->",
"bool",
":",
"if",
"\"Hello\"",
"in",
"message",
":",
"return",
"True",
"return",
"False"
] | Checks if a message is a hello message. | [
"Checks",
"if",
"a",
"message",
"is",
"a",
"hello",
"message",
"."
] | [
"\"\"\"Checks if a message is a hello message.\"\"\""
] | [
{
"param": "message",
"type": "str"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "message",
"type": "str",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
94786f8bdec21ea53d6e089c9e15169da95d730c | mesepulveda/wsnsim | wsnsim/auxiliary_functions.py | [
"MIT"
] | Python | parse_payload | Iterable[str] | def parse_payload(payload: str) -> Iterable[str]:
"""Parses the payload and returns the three components."""
payload_components = payload.split('/')
source, measurement, measurement_time = payload_components
return source, measurement, float(measurement_time) | Parses the payload and returns the three components. | Parses the payload and returns the three components. | [
"Parses",
"the",
"payload",
"and",
"returns",
"the",
"three",
"components",
"."
] | def parse_payload(payload: str) -> Iterable[str]:
payload_components = payload.split('/')
source, measurement, measurement_time = payload_components
return source, measurement, float(measurement_time) | [
"def",
"parse_payload",
"(",
"payload",
":",
"str",
")",
"->",
"Iterable",
"[",
"str",
"]",
":",
"payload_components",
"=",
"payload",
".",
"split",
"(",
"'/'",
")",
"source",
",",
"measurement",
",",
"measurement_time",
"=",
"payload_components",
"return",
... | Parses the payload and returns the three components. | [
"Parses",
"the",
"payload",
"and",
"returns",
"the",
"three",
"components",
"."
] | [
"\"\"\"Parses the payload and returns the three components.\"\"\""
] | [
{
"param": "payload",
"type": "str"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "payload",
"type": "str",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
94786f8bdec21ea53d6e089c9e15169da95d730c | mesepulveda/wsnsim | wsnsim/auxiliary_functions.py | [
"MIT"
] | Python | is_etx_message | bool | def is_etx_message(message: str) -> bool:
"""Checks if a message contains information about some neighbour ETX."""
if "ETX" in message:
return True
return False | Checks if a message contains information about some neighbour ETX. | Checks if a message contains information about some neighbour ETX. | [
"Checks",
"if",
"a",
"message",
"contains",
"information",
"about",
"some",
"neighbour",
"ETX",
"."
] | def is_etx_message(message: str) -> bool:
if "ETX" in message:
return True
return False | [
"def",
"is_etx_message",
"(",
"message",
":",
"str",
")",
"->",
"bool",
":",
"if",
"\"ETX\"",
"in",
"message",
":",
"return",
"True",
"return",
"False"
] | Checks if a message contains information about some neighbour ETX. | [
"Checks",
"if",
"a",
"message",
"contains",
"information",
"about",
"some",
"neighbour",
"ETX",
"."
] | [
"\"\"\"Checks if a message contains information about some neighbour ETX.\"\"\""
] | [
{
"param": "message",
"type": "str"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "message",
"type": "str",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
94786f8bdec21ea53d6e089c9e15169da95d730c | mesepulveda/wsnsim | wsnsim/auxiliary_functions.py | [
"MIT"
] | Python | find_index_of_delay | int | def find_index_of_delay(sample: float, delay_vector: list) -> int:
"""Returns the corresponding index for a new sample of the delay pdf."""
for index, delay_value in enumerate(delay_vector):
if sample <= delay_value:
return index | Returns the corresponding index for a new sample of the delay pdf. | Returns the corresponding index for a new sample of the delay pdf. | [
"Returns",
"the",
"corresponding",
"index",
"for",
"a",
"new",
"sample",
"of",
"the",
"delay",
"pdf",
"."
] | def find_index_of_delay(sample: float, delay_vector: list) -> int:
for index, delay_value in enumerate(delay_vector):
if sample <= delay_value:
return index | [
"def",
"find_index_of_delay",
"(",
"sample",
":",
"float",
",",
"delay_vector",
":",
"list",
")",
"->",
"int",
":",
"for",
"index",
",",
"delay_value",
"in",
"enumerate",
"(",
"delay_vector",
")",
":",
"if",
"sample",
"<=",
"delay_value",
":",
"return",
"i... | Returns the corresponding index for a new sample of the delay pdf. | [
"Returns",
"the",
"corresponding",
"index",
"for",
"a",
"new",
"sample",
"of",
"the",
"delay",
"pdf",
"."
] | [
"\"\"\"Returns the corresponding index for a new sample of the delay pdf.\"\"\""
] | [
{
"param": "sample",
"type": "float"
},
{
"param": "delay_vector",
"type": "list"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "sample",
"type": "float",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "delay_vector",
"type": "list",
"docstring": null,
"docst... |
94786f8bdec21ea53d6e089c9e15169da95d730c | mesepulveda/wsnsim | wsnsim/auxiliary_functions.py | [
"MIT"
] | Python | is_dap_message | bool | def is_dap_message(message: str) -> bool:
"""Checks if a message contains information about some neighbour DAP."""
if "DAP" in message:
return True
return False | Checks if a message contains information about some neighbour DAP. | Checks if a message contains information about some neighbour DAP. | [
"Checks",
"if",
"a",
"message",
"contains",
"information",
"about",
"some",
"neighbour",
"DAP",
"."
] | def is_dap_message(message: str) -> bool:
if "DAP" in message:
return True
return False | [
"def",
"is_dap_message",
"(",
"message",
":",
"str",
")",
"->",
"bool",
":",
"if",
"\"DAP\"",
"in",
"message",
":",
"return",
"True",
"return",
"False"
] | Checks if a message contains information about some neighbour DAP. | [
"Checks",
"if",
"a",
"message",
"contains",
"information",
"about",
"some",
"neighbour",
"DAP",
"."
] | [
"\"\"\"Checks if a message contains information about some neighbour DAP.\"\"\""
] | [
{
"param": "message",
"type": "str"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "message",
"type": "str",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
185e1e279ee199819cccadb5f0f32575ab46cec3 | mesepulveda/wsnsim | wsnsim/link.py | [
"MIT"
] | Python | convert_to_simulation_links | Iterable[SimulationLink] | def convert_to_simulation_links(links: Iterable[Link], simulation_nodes: Iterable[SimulationNode]) \
-> Iterable[SimulationLink]:
"""Returns simulation links from regular links."""
simulation_links = []
for link in links:
node_1, node_2 = get_equivalent_simulation_node(link.nodes, simulation... | Returns simulation links from regular links. | Returns simulation links from regular links. | [
"Returns",
"simulation",
"links",
"from",
"regular",
"links",
"."
] | def convert_to_simulation_links(links: Iterable[Link], simulation_nodes: Iterable[SimulationNode]) \
-> Iterable[SimulationLink]:
simulation_links = []
for link in links:
node_1, node_2 = get_equivalent_simulation_node(link.nodes, simulation_nodes)
simulation_link = SimulationLink(node_1... | [
"def",
"convert_to_simulation_links",
"(",
"links",
":",
"Iterable",
"[",
"Link",
"]",
",",
"simulation_nodes",
":",
"Iterable",
"[",
"SimulationNode",
"]",
")",
"->",
"Iterable",
"[",
"SimulationLink",
"]",
":",
"simulation_links",
"=",
"[",
"]",
"for",
"link... | Returns simulation links from regular links. | [
"Returns",
"simulation",
"links",
"from",
"regular",
"links",
"."
] | [
"\"\"\"Returns simulation links from regular links.\"\"\"",
"# noinspection PyProtectedMember"
] | [
{
"param": "links",
"type": "Iterable[Link]"
},
{
"param": "simulation_nodes",
"type": "Iterable[SimulationNode]"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "links",
"type": "Iterable[Link]",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "simulation_nodes",
"type": "Iterable[SimulationNode]",
... |
8a5ea660847a162256c83e34c8ae62338840f558 | mesepulveda/wsnsim | wsnsim/node.py | [
"MIT"
] | Python | _send_message | Generator[Event, Any, Any] | def _send_message(self, message: str, destination: str) -> Generator[Event, Any, Any]:
"""Sends a message to sink or neighbour nodes."""
# Pass the message to the routing protocol
event = self.routing_protocol.add_to_output_queue(message, destination)
yield self.env.process(event) | Sends a message to sink or neighbour nodes. | Sends a message to sink or neighbour nodes. | [
"Sends",
"a",
"message",
"to",
"sink",
"or",
"neighbour",
"nodes",
"."
] | def _send_message(self, message: str, destination: str) -> Generator[Event, Any, Any]:
event = self.routing_protocol.add_to_output_queue(message, destination)
yield self.env.process(event) | [
"def",
"_send_message",
"(",
"self",
",",
"message",
":",
"str",
",",
"destination",
":",
"str",
")",
"->",
"Generator",
"[",
"Event",
",",
"Any",
",",
"Any",
"]",
":",
"event",
"=",
"self",
".",
"routing_protocol",
".",
"add_to_output_queue",
"(",
"mess... | Sends a message to sink or neighbour nodes. | [
"Sends",
"a",
"message",
"to",
"sink",
"or",
"neighbour",
"nodes",
"."
] | [
"\"\"\"Sends a message to sink or neighbour nodes.\"\"\"",
"# Pass the message to the routing protocol"
] | [
{
"param": "self",
"type": null
},
{
"param": "message",
"type": "str"
},
{
"param": "destination",
"type": "str"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "message",
"type": "str",
"docstring": null,
"docstring_tokens... |
8a5ea660847a162256c83e34c8ae62338840f558 | mesepulveda/wsnsim | wsnsim/node.py | [
"MIT"
] | Python | _main_routine | Generator[Event, Any, Any] | def _main_routine(self) -> Generator[Event, Any, Any]:
"""Main routine of the nodes."""
self._print_info('is awake')
# Start routing protocol setup routine
self.env.process(self.routing_protocol.setup())
# Wait for the sensing offset
yield self.env.timeout(self.sensing_of... | Main routine of the nodes. | Main routine of the nodes. | [
"Main",
"routine",
"of",
"the",
"nodes",
"."
] | def _main_routine(self) -> Generator[Event, Any, Any]:
self._print_info('is awake')
self.env.process(self.routing_protocol.setup())
yield self.env.timeout(self.sensing_offset)
while True:
event = self._send_message(self._format_measurement('X'), 'sink')
self.env.p... | [
"def",
"_main_routine",
"(",
"self",
")",
"->",
"Generator",
"[",
"Event",
",",
"Any",
",",
"Any",
"]",
":",
"self",
".",
"_print_info",
"(",
"'is awake'",
")",
"self",
".",
"env",
".",
"process",
"(",
"self",
".",
"routing_protocol",
".",
"setup",
"("... | Main routine of the nodes. | [
"Main",
"routine",
"of",
"the",
"nodes",
"."
] | [
"\"\"\"Main routine of the nodes.\"\"\"",
"# Start routing protocol setup routine",
"# Wait for the sensing offset",
"# Sensing every 15 minutes"
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
8a5ea660847a162256c83e34c8ae62338840f558 | mesepulveda/wsnsim | wsnsim/node.py | [
"MIT"
] | Python | _main_routine | Generator[Event, Any, Any] | def _main_routine(self) -> Generator[Event, Any, Any]:
"""Main routine of the nodes."""
self._print_info('is awake')
# Start routing protocol setup routine
self.env.process(self.routing_protocol.setup())
# noinspection PyArgumentEqualDefault
yield self.env.timeout(0) | Main routine of the nodes. | Main routine of the nodes. | [
"Main",
"routine",
"of",
"the",
"nodes",
"."
] | def _main_routine(self) -> Generator[Event, Any, Any]:
self._print_info('is awake')
self.env.process(self.routing_protocol.setup())
yield self.env.timeout(0) | [
"def",
"_main_routine",
"(",
"self",
")",
"->",
"Generator",
"[",
"Event",
",",
"Any",
",",
"Any",
"]",
":",
"self",
".",
"_print_info",
"(",
"'is awake'",
")",
"self",
".",
"env",
".",
"process",
"(",
"self",
".",
"routing_protocol",
".",
"setup",
"("... | Main routine of the nodes. | [
"Main",
"routine",
"of",
"the",
"nodes",
"."
] | [
"\"\"\"Main routine of the nodes.\"\"\"",
"# Start routing protocol setup routine",
"# noinspection PyArgumentEqualDefault"
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
8a5ea660847a162256c83e34c8ae62338840f558 | mesepulveda/wsnsim | wsnsim/node.py | [
"MIT"
] | Python | convert_to_simulation_nodes | Iterable[SimulationNode] | def convert_to_simulation_nodes(
regular_nodes: Iterable[Node],
routing_protocol: str,
deadline: float,
send_data_function: Callable[[str], Generator[Event, Any, Any]],
env: Environment) -> Iterable[SimulationNode]:
"""Returns simulation nodes from regular nodes."""
simul... | Returns simulation nodes from regular nodes. | Returns simulation nodes from regular nodes. | [
"Returns",
"simulation",
"nodes",
"from",
"regular",
"nodes",
"."
] | def convert_to_simulation_nodes(
regular_nodes: Iterable[Node],
routing_protocol: str,
deadline: float,
send_data_function: Callable[[str], Generator[Event, Any, Any]],
env: Environment) -> Iterable[SimulationNode]:
simulation_nodes = []
if routing_protocol == 'min-hop':
... | [
"def",
"convert_to_simulation_nodes",
"(",
"regular_nodes",
":",
"Iterable",
"[",
"Node",
"]",
",",
"routing_protocol",
":",
"str",
",",
"deadline",
":",
"float",
",",
"send_data_function",
":",
"Callable",
"[",
"[",
"str",
"]",
",",
"Generator",
"[",
"Event",... | Returns simulation nodes from regular nodes. | [
"Returns",
"simulation",
"nodes",
"from",
"regular",
"nodes",
"."
] | [
"\"\"\"Returns simulation nodes from regular nodes.\"\"\"",
"# Default routing protocol"
] | [
{
"param": "regular_nodes",
"type": "Iterable[Node]"
},
{
"param": "routing_protocol",
"type": "str"
},
{
"param": "deadline",
"type": "float"
},
{
"param": "send_data_function",
"type": "Callable[[str], Generator[Event, Any, Any]]"
},
{
"param": "env",
"type"... | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "regular_nodes",
"type": "Iterable[Node]",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "routing_protocol",
"type": "str",
"docstring":... |
8a5ea660847a162256c83e34c8ae62338840f558 | mesepulveda/wsnsim | wsnsim/node.py | [
"MIT"
] | Python | _get_equivalent_node | SimulationNode | def _get_equivalent_node(
node: Node,
simulation_nodes: Iterable[SimulationNode]) \
-> SimulationNode:
"""Returns the equivalent simulation node of one node."""
for simulation_node in simulation_nodes:
if node.address == simulation_node.address:
return simulation_node | Returns the equivalent simulation node of one node. | Returns the equivalent simulation node of one node. | [
"Returns",
"the",
"equivalent",
"simulation",
"node",
"of",
"one",
"node",
"."
] | def _get_equivalent_node(
node: Node,
simulation_nodes: Iterable[SimulationNode]) \
-> SimulationNode:
for simulation_node in simulation_nodes:
if node.address == simulation_node.address:
return simulation_node | [
"def",
"_get_equivalent_node",
"(",
"node",
":",
"Node",
",",
"simulation_nodes",
":",
"Iterable",
"[",
"SimulationNode",
"]",
")",
"->",
"SimulationNode",
":",
"for",
"simulation_node",
"in",
"simulation_nodes",
":",
"if",
"node",
".",
"address",
"==",
"simulat... | Returns the equivalent simulation node of one node. | [
"Returns",
"the",
"equivalent",
"simulation",
"node",
"of",
"one",
"node",
"."
] | [
"\"\"\"Returns the equivalent simulation node of one node.\"\"\""
] | [
{
"param": "node",
"type": "Node"
},
{
"param": "simulation_nodes",
"type": "Iterable[SimulationNode]"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "node",
"type": "Node",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "simulation_nodes",
"type": "Iterable[SimulationNode]",
"docstring... |
601149c54dde3ef87df292ff339f32a7af44f9a9 | Aloukik21/tfrecords_to_image | tfviewer.py | [
"MIT"
] | Python | preload_images | <not_specific> | def preload_images(max_images):
"""
Load images to be displayed in the browser gallery.
Args:
max_images (int): Maximum number of images to load.
Returns:
count (int): Number of images loaded.
"""
count = 0
overlay = overlay_factory.get_overlay(args.overlay, args)
try:
tf_record_iterator ... |
Load images to be displayed in the browser gallery.
Args:
max_images (int): Maximum number of images to load.
Returns:
count (int): Number of images loaded.
| Load images to be displayed in the browser gallery. | [
"Load",
"images",
"to",
"be",
"displayed",
"in",
"the",
"browser",
"gallery",
"."
] | def preload_images(max_images):
count = 0
overlay = overlay_factory.get_overlay(args.overlay, args)
try:
tf_record_iterator = tf.python_io.tf_record_iterator
except:
tf_record_iterator = tf.compat.v1.python_io.tf_record_iterator
for tfrecord_path in args.tfrecords:
print("Filename: ", tfrecord_pat... | [
"def",
"preload_images",
"(",
"max_images",
")",
":",
"count",
"=",
"0",
"overlay",
"=",
"overlay_factory",
".",
"get_overlay",
"(",
"args",
".",
"overlay",
",",
"args",
")",
"try",
":",
"tf_record_iterator",
"=",
"tf",
".",
"python_io",
".",
"tf_record_iter... | Load images to be displayed in the browser gallery. | [
"Load",
"images",
"to",
"be",
"displayed",
"in",
"the",
"browser",
"gallery",
"."
] | [
"\"\"\" \n Load images to be displayed in the browser gallery.\n\n Args:\n max_images (int): Maximum number of images to load.\n Returns:\n count (int): Number of images loaded.\n \"\"\""
] | [
{
"param": "max_images",
"type": null
}
] | {
"returns": [
{
"docstring": "count (int): Number of images loaded.",
"docstring_tokens": [
"count",
"(",
"int",
")",
":",
"Number",
"of",
"images",
"loaded",
"."
],
"type": null
}
],
"raises": [],
"... |
5ff9ab1d77eff375c6b3d95cfea6cd0d45ef45c7 | firminoneto11/grocery-store-system | backend/users/permissions.py | [
"MIT"
] | Python | has_permission | <not_specific> | def has_permission(self, req, _view):
"""
This method checks if the user has permission based on the 'is_superuser' attribute.
"""
if req.method != 'GET':
if req.user.is_superuser and req.user.is_active:
return True
return False
return True |
This method checks if the user has permission based on the 'is_superuser' attribute.
| This method checks if the user has permission based on the 'is_superuser' attribute. | [
"This",
"method",
"checks",
"if",
"the",
"user",
"has",
"permission",
"based",
"on",
"the",
"'",
"is_superuser",
"'",
"attribute",
"."
] | def has_permission(self, req, _view):
if req.method != 'GET':
if req.user.is_superuser and req.user.is_active:
return True
return False
return True | [
"def",
"has_permission",
"(",
"self",
",",
"req",
",",
"_view",
")",
":",
"if",
"req",
".",
"method",
"!=",
"'GET'",
":",
"if",
"req",
".",
"user",
".",
"is_superuser",
"and",
"req",
".",
"user",
".",
"is_active",
":",
"return",
"True",
"return",
"Fa... | This method checks if the user has permission based on the 'is_superuser' attribute. | [
"This",
"method",
"checks",
"if",
"the",
"user",
"has",
"permission",
"based",
"on",
"the",
"'",
"is_superuser",
"'",
"attribute",
"."
] | [
"\"\"\"\n This method checks if the user has permission based on the 'is_superuser' attribute.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "req",
"type": null
},
{
"param": "_view",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "req",
"type": null,
"docstring": null,
"docstring_tokens": []... |
bb2fb2e6711f9a82b9ab8e3c7b1bdc083ac1717b | firminoneto11/grocery-store-system | backend/products/views.py | [
"MIT"
] | Python | find_all_products | <not_specific> | def find_all_products(self, _req):
"""
This method is responsible for listing all the Products that are currently registered in the system without pagination.
"""
queryset: Products = self.get_queryset().filter(is_active=True)
products: ProductsSerializer = self.get_serializer(in... |
This method is responsible for listing all the Products that are currently registered in the system without pagination.
| This method is responsible for listing all the Products that are currently registered in the system without pagination. | [
"This",
"method",
"is",
"responsible",
"for",
"listing",
"all",
"the",
"Products",
"that",
"are",
"currently",
"registered",
"in",
"the",
"system",
"without",
"pagination",
"."
] | def find_all_products(self, _req):
queryset: Products = self.get_queryset().filter(is_active=True)
products: ProductsSerializer = self.get_serializer(instance=queryset, many=True)
return res(data=products.data) | [
"def",
"find_all_products",
"(",
"self",
",",
"_req",
")",
":",
"queryset",
":",
"Products",
"=",
"self",
".",
"get_queryset",
"(",
")",
".",
"filter",
"(",
"is_active",
"=",
"True",
")",
"products",
":",
"ProductsSerializer",
"=",
"self",
".",
"get_serial... | This method is responsible for listing all the Products that are currently registered in the system without pagination. | [
"This",
"method",
"is",
"responsible",
"for",
"listing",
"all",
"the",
"Products",
"that",
"are",
"currently",
"registered",
"in",
"the",
"system",
"without",
"pagination",
"."
] | [
"\"\"\"\n This method is responsible for listing all the Products that are currently registered in the system without pagination.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "_req",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "_req",
"type": null,
"docstring": null,
"docstring_tokens": [... |
bb2fb2e6711f9a82b9ab8e3c7b1bdc083ac1717b | firminoneto11/grocery-store-system | backend/products/views.py | [
"MIT"
] | Python | list | <not_specific> | def list(self, _req):
"""
This method is responsible for listing all the Products that are currently registered in the system with pagination.
"""
serializer = self.get_paginated_serializer()
return self.get_paginated_response(data=serializer.data) |
This method is responsible for listing all the Products that are currently registered in the system with pagination.
| This method is responsible for listing all the Products that are currently registered in the system with pagination. | [
"This",
"method",
"is",
"responsible",
"for",
"listing",
"all",
"the",
"Products",
"that",
"are",
"currently",
"registered",
"in",
"the",
"system",
"with",
"pagination",
"."
] | def list(self, _req):
serializer = self.get_paginated_serializer()
return self.get_paginated_response(data=serializer.data) | [
"def",
"list",
"(",
"self",
",",
"_req",
")",
":",
"serializer",
"=",
"self",
".",
"get_paginated_serializer",
"(",
")",
"return",
"self",
".",
"get_paginated_response",
"(",
"data",
"=",
"serializer",
".",
"data",
")"
] | This method is responsible for listing all the Products that are currently registered in the system with pagination. | [
"This",
"method",
"is",
"responsible",
"for",
"listing",
"all",
"the",
"Products",
"that",
"are",
"currently",
"registered",
"in",
"the",
"system",
"with",
"pagination",
"."
] | [
"\"\"\"\n This method is responsible for listing all the Products that are currently registered in the system with pagination.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "_req",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "_req",
"type": null,
"docstring": null,
"docstring_tokens": [... |
bb2fb2e6711f9a82b9ab8e3c7b1bdc083ac1717b | firminoneto11/grocery-store-system | backend/products/views.py | [
"MIT"
] | Python | create | <not_specific> | def create(self, req: Request):
"""
This method is responsible for creating new products and save them in the database.
"""
new_product = self.get_serializer(data=req.data)
new_product.is_valid(raise_exception=True)
new_product.save()
return res(data=new_product.d... |
This method is responsible for creating new products and save them in the database.
| This method is responsible for creating new products and save them in the database. | [
"This",
"method",
"is",
"responsible",
"for",
"creating",
"new",
"products",
"and",
"save",
"them",
"in",
"the",
"database",
"."
] | def create(self, req: Request):
new_product = self.get_serializer(data=req.data)
new_product.is_valid(raise_exception=True)
new_product.save()
return res(data=new_product.data, status=HTTP_201_CREATED) | [
"def",
"create",
"(",
"self",
",",
"req",
":",
"Request",
")",
":",
"new_product",
"=",
"self",
".",
"get_serializer",
"(",
"data",
"=",
"req",
".",
"data",
")",
"new_product",
".",
"is_valid",
"(",
"raise_exception",
"=",
"True",
")",
"new_product",
"."... | This method is responsible for creating new products and save them in the database. | [
"This",
"method",
"is",
"responsible",
"for",
"creating",
"new",
"products",
"and",
"save",
"them",
"in",
"the",
"database",
"."
] | [
"\"\"\"\n This method is responsible for creating new products and save them in the database.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "req",
"type": "Request"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "req",
"type": "Request",
"docstring": null,
"docstring_tokens... |
bb2fb2e6711f9a82b9ab8e3c7b1bdc083ac1717b | firminoneto11/grocery-store-system | backend/products/views.py | [
"MIT"
] | Python | retrieve | <not_specific> | def retrieve(self, _req, pk):
"""
This method is responsible for displaying only one product based on the ID that was provided in the route
params.
"""
product = self.find_element_or_none(model=Products, identifier=pk)
if product is not None:
product = self.g... |
This method is responsible for displaying only one product based on the ID that was provided in the route
params.
| This method is responsible for displaying only one product based on the ID that was provided in the route
params. | [
"This",
"method",
"is",
"responsible",
"for",
"displaying",
"only",
"one",
"product",
"based",
"on",
"the",
"ID",
"that",
"was",
"provided",
"in",
"the",
"route",
"params",
"."
] | def retrieve(self, _req, pk):
product = self.find_element_or_none(model=Products, identifier=pk)
if product is not None:
product = self.get_serializer(instance=product)
return res(data=product.data)
return res(data={"not-found": "Not found"}, status=HTTP_404_NOT_FOUND) | [
"def",
"retrieve",
"(",
"self",
",",
"_req",
",",
"pk",
")",
":",
"product",
"=",
"self",
".",
"find_element_or_none",
"(",
"model",
"=",
"Products",
",",
"identifier",
"=",
"pk",
")",
"if",
"product",
"is",
"not",
"None",
":",
"product",
"=",
"self",
... | This method is responsible for displaying only one product based on the ID that was provided in the route
params. | [
"This",
"method",
"is",
"responsible",
"for",
"displaying",
"only",
"one",
"product",
"based",
"on",
"the",
"ID",
"that",
"was",
"provided",
"in",
"the",
"route",
"params",
"."
] | [
"\"\"\"\n This method is responsible for displaying only one product based on the ID that was provided in the route \n params.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "_req",
"type": null
},
{
"param": "pk",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "_req",
"type": null,
"docstring": null,
"docstring_tokens": [... |
bb2fb2e6711f9a82b9ab8e3c7b1bdc083ac1717b | firminoneto11/grocery-store-system | backend/products/views.py | [
"MIT"
] | Python | update | <not_specific> | def update(self, req, pk):
"""
This method is responsible for updating a single product with the given data based on the ID that was provided
in the route params.
"""
product = self.find_element_or_none(model=Products, identifier=pk)
if product is not None:
p... |
This method is responsible for updating a single product with the given data based on the ID that was provided
in the route params.
| This method is responsible for updating a single product with the given data based on the ID that was provided
in the route params. | [
"This",
"method",
"is",
"responsible",
"for",
"updating",
"a",
"single",
"product",
"with",
"the",
"given",
"data",
"based",
"on",
"the",
"ID",
"that",
"was",
"provided",
"in",
"the",
"route",
"params",
"."
] | def update(self, req, pk):
product = self.find_element_or_none(model=Products, identifier=pk)
if product is not None:
product = self.get_serializer(data=req.data, instance=product, partial=True)
product.is_valid(raise_exception=True)
product.save()
return ... | [
"def",
"update",
"(",
"self",
",",
"req",
",",
"pk",
")",
":",
"product",
"=",
"self",
".",
"find_element_or_none",
"(",
"model",
"=",
"Products",
",",
"identifier",
"=",
"pk",
")",
"if",
"product",
"is",
"not",
"None",
":",
"product",
"=",
"self",
"... | This method is responsible for updating a single product with the given data based on the ID that was provided
in the route params. | [
"This",
"method",
"is",
"responsible",
"for",
"updating",
"a",
"single",
"product",
"with",
"the",
"given",
"data",
"based",
"on",
"the",
"ID",
"that",
"was",
"provided",
"in",
"the",
"route",
"params",
"."
] | [
"\"\"\"\n This method is responsible for updating a single product with the given data based on the ID that was provided \n in the route params.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "req",
"type": null
},
{
"param": "pk",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "req",
"type": null,
"docstring": null,
"docstring_tokens": []... |
bb2fb2e6711f9a82b9ab8e3c7b1bdc083ac1717b | firminoneto11/grocery-store-system | backend/products/views.py | [
"MIT"
] | Python | destroy | <not_specific> | def destroy(self, _req, pk):
"""
This method is responsible for deleting a single product from the database.
"""
product = self.find_element_or_none(model=Products, identifier=pk)
if product is not None:
product.delete()
return res(status=HTTP_204_NO_CONTE... |
This method is responsible for deleting a single product from the database.
| This method is responsible for deleting a single product from the database. | [
"This",
"method",
"is",
"responsible",
"for",
"deleting",
"a",
"single",
"product",
"from",
"the",
"database",
"."
] | def destroy(self, _req, pk):
product = self.find_element_or_none(model=Products, identifier=pk)
if product is not None:
product.delete()
return res(status=HTTP_204_NO_CONTENT)
return res(status=HTTP_404_NOT_FOUND) | [
"def",
"destroy",
"(",
"self",
",",
"_req",
",",
"pk",
")",
":",
"product",
"=",
"self",
".",
"find_element_or_none",
"(",
"model",
"=",
"Products",
",",
"identifier",
"=",
"pk",
")",
"if",
"product",
"is",
"not",
"None",
":",
"product",
".",
"delete",... | This method is responsible for deleting a single product from the database. | [
"This",
"method",
"is",
"responsible",
"for",
"deleting",
"a",
"single",
"product",
"from",
"the",
"database",
"."
] | [
"\"\"\"\n This method is responsible for deleting a single product from the database.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "_req",
"type": null
},
{
"param": "pk",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "_req",
"type": null,
"docstring": null,
"docstring_tokens": [... |
6db8b856fe3eccb167ea2ecdcab0d354366f6377 | firminoneto11/grocery-store-system | backend/users/models.py | [
"MIT"
] | Python | _create_user | <not_specific> | def _create_user(self, email=None, password=None, **extra_fields):
"""
Create and save a user with the given email and password.
"""
if not email:
raise ValueError('The given email must be set')
email = self.normalize_email(email)
user = self.model(email=email... |
Create and save a user with the given email and password.
| Create and save a user with the given email and password. | [
"Create",
"and",
"save",
"a",
"user",
"with",
"the",
"given",
"email",
"and",
"password",
"."
] | def _create_user(self, email=None, password=None, **extra_fields):
if not email:
raise ValueError('The given email must be set')
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save(using=self._db)
... | [
"def",
"_create_user",
"(",
"self",
",",
"email",
"=",
"None",
",",
"password",
"=",
"None",
",",
"**",
"extra_fields",
")",
":",
"if",
"not",
"email",
":",
"raise",
"ValueError",
"(",
"'The given email must be set'",
")",
"email",
"=",
"self",
".",
"norma... | Create and save a user with the given email and password. | [
"Create",
"and",
"save",
"a",
"user",
"with",
"the",
"given",
"email",
"and",
"password",
"."
] | [
"\"\"\"\n Create and save a user with the given email and password.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "email",
"type": null
},
{
"param": "password",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "email",
"type": null,
"docstring": null,
"docstring_tokens": ... |
a00144a4b0e54658b6e94c33ff2f3773b038c705 | firminoneto11/grocery-store-system | backend/__db_management__/create_products.py | [
"MIT"
] | Python | check_sql_file | null | def check_sql_file(cls):
"""
This method checks if the sql file exists and it creates a new one if it doesn't.
"""
if not exists(cls.sql_file):
with open(file=cls.sql_file, mode="w", encoding="utf-8"):
pass |
This method checks if the sql file exists and it creates a new one if it doesn't.
| This method checks if the sql file exists and it creates a new one if it doesn't. | [
"This",
"method",
"checks",
"if",
"the",
"sql",
"file",
"exists",
"and",
"it",
"creates",
"a",
"new",
"one",
"if",
"it",
"doesn",
"'",
"t",
"."
] | def check_sql_file(cls):
if not exists(cls.sql_file):
with open(file=cls.sql_file, mode="w", encoding="utf-8"):
pass | [
"def",
"check_sql_file",
"(",
"cls",
")",
":",
"if",
"not",
"exists",
"(",
"cls",
".",
"sql_file",
")",
":",
"with",
"open",
"(",
"file",
"=",
"cls",
".",
"sql_file",
",",
"mode",
"=",
"\"w\"",
",",
"encoding",
"=",
"\"utf-8\"",
")",
":",
"pass"
] | This method checks if the sql file exists and it creates a new one if it doesn't. | [
"This",
"method",
"checks",
"if",
"the",
"sql",
"file",
"exists",
"and",
"it",
"creates",
"a",
"new",
"one",
"if",
"it",
"doesn",
"'",
"t",
"."
] | [
"\"\"\"\n This method checks if the sql file exists and it creates a new one if it doesn't.\n \"\"\""
] | [
{
"param": "cls",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cls",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
a00144a4b0e54658b6e94c33ff2f3773b038c705 | firminoneto11/grocery-store-system | backend/__db_management__/create_products.py | [
"MIT"
] | Python | treat_data | null | def treat_data(cls):
"""
This method treats the data mocked by mockaroo by eleminating the repeated name products.
"""
with open(file=cls.data, mode="r", encoding="utf-8") as file:
# Saving the product names into a list
product_names = []
data = []
... |
This method treats the data mocked by mockaroo by eleminating the repeated name products.
| This method treats the data mocked by mockaroo by eleminating the repeated name products. | [
"This",
"method",
"treats",
"the",
"data",
"mocked",
"by",
"mockaroo",
"by",
"eleminating",
"the",
"repeated",
"name",
"products",
"."
] | def treat_data(cls):
with open(file=cls.data, mode="r", encoding="utf-8") as file:
product_names = []
data = []
reader = DictReader(f=file, fieldnames=cls.headers)
next(reader)
for row in reader:
product_names.append(row.get(cls.headers... | [
"def",
"treat_data",
"(",
"cls",
")",
":",
"with",
"open",
"(",
"file",
"=",
"cls",
".",
"data",
",",
"mode",
"=",
"\"r\"",
",",
"encoding",
"=",
"\"utf-8\"",
")",
"as",
"file",
":",
"product_names",
"=",
"[",
"]",
"data",
"=",
"[",
"]",
"reader",
... | This method treats the data mocked by mockaroo by eleminating the repeated name products. | [
"This",
"method",
"treats",
"the",
"data",
"mocked",
"by",
"mockaroo",
"by",
"eleminating",
"the",
"repeated",
"name",
"products",
"."
] | [
"\"\"\"\n This method treats the data mocked by mockaroo by eleminating the repeated name products.\n \"\"\"",
"# Saving the product names into a list",
"# Defining the dict reader for the names",
"# Algorithm to separate repeated from the not repeated",
"# Instanciating the DictWriter and wri... | [
{
"param": "cls",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cls",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
a00144a4b0e54658b6e94c33ff2f3773b038c705 | firminoneto11/grocery-store-system | backend/__db_management__/create_products.py | [
"MIT"
] | Python | create_sql_file | null | def create_sql_file(cls):
"""
This method created a set of sql commands in order to populate the database. The data was mocked by:
-> https://www.mockaroo.com/
"""
# Checking if the sql file exists
cls.check_sql_file()
# Eliminating repeated products
cls... |
This method created a set of sql commands in order to populate the database. The data was mocked by:
-> https://www.mockaroo.com/
| This method created a set of sql commands in order to populate the database. | [
"This",
"method",
"created",
"a",
"set",
"of",
"sql",
"commands",
"in",
"order",
"to",
"populate",
"the",
"database",
"."
] | def create_sql_file(cls):
cls.check_sql_file()
cls.treat_data()
with open(file=cls.data, mode="r", encoding="utf-8") as data:
with open(file=cls.sql_file, mode="w", encoding="utf-8") as sql:
data = DictReader(f=data, fieldnames=cls.headers)
next(data)
... | [
"def",
"create_sql_file",
"(",
"cls",
")",
":",
"cls",
".",
"check_sql_file",
"(",
")",
"cls",
".",
"treat_data",
"(",
")",
"with",
"open",
"(",
"file",
"=",
"cls",
".",
"data",
",",
"mode",
"=",
"\"r\"",
",",
"encoding",
"=",
"\"utf-8\"",
")",
"as",... | This method created a set of sql commands in order to populate the database. | [
"This",
"method",
"created",
"a",
"set",
"of",
"sql",
"commands",
"in",
"order",
"to",
"populate",
"the",
"database",
"."
] | [
"\"\"\"\n This method created a set of sql commands in order to populate the database. The data was mocked by:\n -> https://www.mockaroo.com/\n \"\"\"",
"# Checking if the sql file exists",
"# Eliminating repeated products",
"# Script Generation"
] | [
{
"param": "cls",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cls",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
3433437712be649a1a3438c6832073b949de1180 | firminoneto11/grocery-store-system | backend/users/serializers.py | [
"MIT"
] | Python | create | <not_specific> | def create(self, validated_data):
"""
This method is responsible for encrypting the user's password before inserting it in the database.
"""
validated_data['password'] = make_password(validated_data['password'])
return super(UsersSerializer, self).create(validated_data) |
This method is responsible for encrypting the user's password before inserting it in the database.
| This method is responsible for encrypting the user's password before inserting it in the database. | [
"This",
"method",
"is",
"responsible",
"for",
"encrypting",
"the",
"user",
"'",
"s",
"password",
"before",
"inserting",
"it",
"in",
"the",
"database",
"."
] | def create(self, validated_data):
validated_data['password'] = make_password(validated_data['password'])
return super(UsersSerializer, self).create(validated_data) | [
"def",
"create",
"(",
"self",
",",
"validated_data",
")",
":",
"validated_data",
"[",
"'password'",
"]",
"=",
"make_password",
"(",
"validated_data",
"[",
"'password'",
"]",
")",
"return",
"super",
"(",
"UsersSerializer",
",",
"self",
")",
".",
"create",
"("... | This method is responsible for encrypting the user's password before inserting it in the database. | [
"This",
"method",
"is",
"responsible",
"for",
"encrypting",
"the",
"user",
"'",
"s",
"password",
"before",
"inserting",
"it",
"in",
"the",
"database",
"."
] | [
"\"\"\"\n This method is responsible for encrypting the user's password before inserting it in the database.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "validated_data",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "validated_data",
"type": null,
"docstring": null,
"docstring_... |
3433437712be649a1a3438c6832073b949de1180 | firminoneto11/grocery-store-system | backend/users/serializers.py | [
"MIT"
] | Python | update | <not_specific> | def update(self, instance, validated_data):
"""
This method is responsible for encrypting the user's password before a update in the password field.
"""
if validated_data.get('password') is not None:
validated_data['password'] = make_password(validated_data['password'])
... |
This method is responsible for encrypting the user's password before a update in the password field.
| This method is responsible for encrypting the user's password before a update in the password field. | [
"This",
"method",
"is",
"responsible",
"for",
"encrypting",
"the",
"user",
"'",
"s",
"password",
"before",
"a",
"update",
"in",
"the",
"password",
"field",
"."
] | def update(self, instance, validated_data):
if validated_data.get('password') is not None:
validated_data['password'] = make_password(validated_data['password'])
return super(UsersSerializer, self).update(instance, validated_data) | [
"def",
"update",
"(",
"self",
",",
"instance",
",",
"validated_data",
")",
":",
"if",
"validated_data",
".",
"get",
"(",
"'password'",
")",
"is",
"not",
"None",
":",
"validated_data",
"[",
"'password'",
"]",
"=",
"make_password",
"(",
"validated_data",
"[",
... | This method is responsible for encrypting the user's password before a update in the password field. | [
"This",
"method",
"is",
"responsible",
"for",
"encrypting",
"the",
"user",
"'",
"s",
"password",
"before",
"a",
"update",
"in",
"the",
"password",
"field",
"."
] | [
"\"\"\"\n This method is responsible for encrypting the user's password before a update in the password field.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "instance",
"type": null
},
{
"param": "validated_data",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "instance",
"type": null,
"docstring": null,
"docstring_tokens... |
4d01bfd1fa25a306018a80adffffb261d58a6b11 | firminoneto11/grocery-store-system | backend/utils.py | [
"MIT"
] | Python | find_element_or_none | <not_specific> | def find_element_or_none(self, model, identifier):
"""
This function will try to get the element in the database by it's id, based on the model that is passed in the 'model'
param. Returns None if it doesn't find any.
"""
try:
element = model.objects.get(pk=int(identi... |
This function will try to get the element in the database by it's id, based on the model that is passed in the 'model'
param. Returns None if it doesn't find any.
| This function will try to get the element in the database by it's id, based on the model that is passed in the 'model'
param. Returns None if it doesn't find any. | [
"This",
"function",
"will",
"try",
"to",
"get",
"the",
"element",
"in",
"the",
"database",
"by",
"it",
"'",
"s",
"id",
"based",
"on",
"the",
"model",
"that",
"is",
"passed",
"in",
"the",
"'",
"model",
"'",
"param",
".",
"Returns",
"None",
"if",
"it",... | def find_element_or_none(self, model, identifier):
try:
element = model.objects.get(pk=int(identifier))
except Exception:
return None
else:
return element | [
"def",
"find_element_or_none",
"(",
"self",
",",
"model",
",",
"identifier",
")",
":",
"try",
":",
"element",
"=",
"model",
".",
"objects",
".",
"get",
"(",
"pk",
"=",
"int",
"(",
"identifier",
")",
")",
"except",
"Exception",
":",
"return",
"None",
"e... | This function will try to get the element in the database by it's id, based on the model that is passed in the 'model'
param. | [
"This",
"function",
"will",
"try",
"to",
"get",
"the",
"element",
"in",
"the",
"database",
"by",
"it",
"'",
"s",
"id",
"based",
"on",
"the",
"model",
"that",
"is",
"passed",
"in",
"the",
"'",
"model",
"'",
"param",
"."
] | [
"\"\"\"\n This function will try to get the element in the database by it's id, based on the model that is passed in the 'model'\n param. Returns None if it doesn't find any.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "model",
"type": null
},
{
"param": "identifier",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "model",
"type": null,
"docstring": null,
"docstring_tokens": ... |
ecd7d7a3d06ca47147ab00dd03a4bd6fdf3a9578 | firminoneto11/grocery-store-system | backend/users/views.py | [
"MIT"
] | Python | create | <not_specific> | def create(self, request):
"""
This method is responsible for registering new users in the system.
"""
new_user = self.get_serializer(data=request.data)
new_user.is_valid(raise_exception=True)
new_user.save()
return res(data=new_user.data, status=HTTP_201_CREATED) |
This method is responsible for registering new users in the system.
| This method is responsible for registering new users in the system. | [
"This",
"method",
"is",
"responsible",
"for",
"registering",
"new",
"users",
"in",
"the",
"system",
"."
] | def create(self, request):
new_user = self.get_serializer(data=request.data)
new_user.is_valid(raise_exception=True)
new_user.save()
return res(data=new_user.data, status=HTTP_201_CREATED) | [
"def",
"create",
"(",
"self",
",",
"request",
")",
":",
"new_user",
"=",
"self",
".",
"get_serializer",
"(",
"data",
"=",
"request",
".",
"data",
")",
"new_user",
".",
"is_valid",
"(",
"raise_exception",
"=",
"True",
")",
"new_user",
".",
"save",
"(",
... | This method is responsible for registering new users in the system. | [
"This",
"method",
"is",
"responsible",
"for",
"registering",
"new",
"users",
"in",
"the",
"system",
"."
] | [
"\"\"\"\n This method is responsible for registering new users in the system.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "request",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "request",
"type": null,
"docstring": null,
"docstring_tokens"... |
ecd7d7a3d06ca47147ab00dd03a4bd6fdf3a9578 | firminoneto11/grocery-store-system | backend/users/views.py | [
"MIT"
] | Python | retrieve | <not_specific> | def retrieve(self, _request, pk):
"""
This method is responsible for retrieving a single user that is registered in the system.
"""
user = self.find_element_or_none(model=Users, identifier=pk)
if user is not None:
user = self.get_serializer(instance=user)
... |
This method is responsible for retrieving a single user that is registered in the system.
| This method is responsible for retrieving a single user that is registered in the system. | [
"This",
"method",
"is",
"responsible",
"for",
"retrieving",
"a",
"single",
"user",
"that",
"is",
"registered",
"in",
"the",
"system",
"."
] | def retrieve(self, _request, pk):
user = self.find_element_or_none(model=Users, identifier=pk)
if user is not None:
user = self.get_serializer(instance=user)
return res(data=user.data)
return res(status=HTTP_404_NOT_FOUND) | [
"def",
"retrieve",
"(",
"self",
",",
"_request",
",",
"pk",
")",
":",
"user",
"=",
"self",
".",
"find_element_or_none",
"(",
"model",
"=",
"Users",
",",
"identifier",
"=",
"pk",
")",
"if",
"user",
"is",
"not",
"None",
":",
"user",
"=",
"self",
".",
... | This method is responsible for retrieving a single user that is registered in the system. | [
"This",
"method",
"is",
"responsible",
"for",
"retrieving",
"a",
"single",
"user",
"that",
"is",
"registered",
"in",
"the",
"system",
"."
] | [
"\"\"\"\n This method is responsible for retrieving a single user that is registered in the system.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "_request",
"type": null
},
{
"param": "pk",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "_request",
"type": null,
"docstring": null,
"docstring_tokens... |
ecd7d7a3d06ca47147ab00dd03a4bd6fdf3a9578 | firminoneto11/grocery-store-system | backend/users/views.py | [
"MIT"
] | Python | update | <not_specific> | def update(self, req, pk):
"""
This method is responsible for updating the user's info in at least one of the fields with the given data based on the ID
that was provided in the route params.
"""
user = self.find_element_or_none(model=Users, identifier=pk)
if user is not... |
This method is responsible for updating the user's info in at least one of the fields with the given data based on the ID
that was provided in the route params.
| This method is responsible for updating the user's info in at least one of the fields with the given data based on the ID
that was provided in the route params. | [
"This",
"method",
"is",
"responsible",
"for",
"updating",
"the",
"user",
"'",
"s",
"info",
"in",
"at",
"least",
"one",
"of",
"the",
"fields",
"with",
"the",
"given",
"data",
"based",
"on",
"the",
"ID",
"that",
"was",
"provided",
"in",
"the",
"route",
"... | def update(self, req, pk):
user = self.find_element_or_none(model=Users, identifier=pk)
if user is not None:
user = self.get_serializer(instance=user, data=req.data, partial=True)
user.is_valid(raise_exception=True)
user.save()
return res(data=user.data)
... | [
"def",
"update",
"(",
"self",
",",
"req",
",",
"pk",
")",
":",
"user",
"=",
"self",
".",
"find_element_or_none",
"(",
"model",
"=",
"Users",
",",
"identifier",
"=",
"pk",
")",
"if",
"user",
"is",
"not",
"None",
":",
"user",
"=",
"self",
".",
"get_s... | This method is responsible for updating the user's info in at least one of the fields with the given data based on the ID
that was provided in the route params. | [
"This",
"method",
"is",
"responsible",
"for",
"updating",
"the",
"user",
"'",
"s",
"info",
"in",
"at",
"least",
"one",
"of",
"the",
"fields",
"with",
"the",
"given",
"data",
"based",
"on",
"the",
"ID",
"that",
"was",
"provided",
"in",
"the",
"route",
"... | [
"\"\"\"\n This method is responsible for updating the user's info in at least one of the fields with the given data based on the ID \n that was provided in the route params.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "req",
"type": null
},
{
"param": "pk",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "req",
"type": null,
"docstring": null,
"docstring_tokens": []... |
ecd7d7a3d06ca47147ab00dd03a4bd6fdf3a9578 | firminoneto11/grocery-store-system | backend/users/views.py | [
"MIT"
] | Python | destroy | <not_specific> | def destroy(self, _request, pk):
"""
This method is responsible for deleting a user from the system. It's a soft deletion, so it just changes the 'is_active'
attribute to False.
"""
user = self.find_element_or_none(model=Users, identifier=pk)
if user is not None:
... |
This method is responsible for deleting a user from the system. It's a soft deletion, so it just changes the 'is_active'
attribute to False.
| This method is responsible for deleting a user from the system. It's a soft deletion, so it just changes the 'is_active'
attribute to False. | [
"This",
"method",
"is",
"responsible",
"for",
"deleting",
"a",
"user",
"from",
"the",
"system",
".",
"It",
"'",
"s",
"a",
"soft",
"deletion",
"so",
"it",
"just",
"changes",
"the",
"'",
"is_active",
"'",
"attribute",
"to",
"False",
"."
] | def destroy(self, _request, pk):
user = self.find_element_or_none(model=Users, identifier=pk)
if user is not None:
if user.is_active:
user.is_active = 0
user.save()
return res(status=HTTP_204_NO_CONTENT)
return res(status=HTTP_404_NOT_FOUND... | [
"def",
"destroy",
"(",
"self",
",",
"_request",
",",
"pk",
")",
":",
"user",
"=",
"self",
".",
"find_element_or_none",
"(",
"model",
"=",
"Users",
",",
"identifier",
"=",
"pk",
")",
"if",
"user",
"is",
"not",
"None",
":",
"if",
"user",
".",
"is_activ... | This method is responsible for deleting a user from the system. | [
"This",
"method",
"is",
"responsible",
"for",
"deleting",
"a",
"user",
"from",
"the",
"system",
"."
] | [
"\"\"\"\n This method is responsible for deleting a user from the system. It's a soft deletion, so it just changes the 'is_active' \n attribute to False.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "_request",
"type": null
},
{
"param": "pk",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "_request",
"type": null,
"docstring": null,
"docstring_tokens... |
07a2dce44f7e7e063221b766ef5994a10b9600fa | bohaohuang/ersa | collection/collectionEditor.py | [
"MIT"
] | Python | process | null | def process(self, **kwargs):
"""
process to make the new field
:param kwargs:
file_list: the list of the files, if not given, use all the files with selected field extension
file_ext: the new file extension, if not given, use the same as the old one
d_type: th... |
process to make the new field
:param kwargs:
file_list: the list of the files, if not given, use all the files with selected field extension
file_ext: the new file extension, if not given, use the same as the old one
d_type: the new data type, if not given, use the s... | process to make the new field | [
"process",
"to",
"make",
"the",
"new",
"field"
] | def process(self, **kwargs):
if 'file_list' not in kwargs:
file_list = self.clc.load_files(','.join(self.clc.field_name), ','.join(self.clc.field_id),
self.field_ext_pair[0])
else:
file_list = kwargs['file_list']
assert len(file... | [
"def",
"process",
"(",
"self",
",",
"**",
"kwargs",
")",
":",
"if",
"'file_list'",
"not",
"in",
"kwargs",
":",
"file_list",
"=",
"self",
".",
"clc",
".",
"load_files",
"(",
"','",
".",
"join",
"(",
"self",
".",
"clc",
".",
"field_name",
")",
",",
"... | process to make the new field | [
"process",
"to",
"make",
"the",
"new",
"field"
] | [
"\"\"\"\n process to make the new field\n :param kwargs:\n file_list: the list of the files, if not given, use all the files with selected field extension\n file_ext: the new file extension, if not given, use the same as the old one\n d_type: the new data type, if not ... | [
{
"param": "self",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
... |
07a2dce44f7e7e063221b766ef5994a10b9600fa | bohaohuang/ersa | collection/collectionEditor.py | [
"MIT"
] | Python | process | null | def process(self, **kwargs):
"""
process to make the new field
:param kwargs:
file_list: the list of the files, if not given, use all the files with selected field extension
file_ext: the new file extension, if not given, use the same as the old one
d_type: th... |
process to make the new field
:param kwargs:
file_list: the list of the files, if not given, use all the files with selected field extension
file_ext: the new file extension, if not given, use the same as the old one
d_type: the new data type, if not given, use the s... | process to make the new field | [
"process",
"to",
"make",
"the",
"new",
"field"
] | def process(self, **kwargs):
if 'file_list' not in kwargs:
file_list = self.clc.load_files(','.join(self.clc.field_name), ','.join(self.clc.field_id),
self.field_ext_pair[0])
else:
file_list = kwargs['file_list']
assert len(file... | [
"def",
"process",
"(",
"self",
",",
"**",
"kwargs",
")",
":",
"if",
"'file_list'",
"not",
"in",
"kwargs",
":",
"file_list",
"=",
"self",
".",
"clc",
".",
"load_files",
"(",
"','",
".",
"join",
"(",
"self",
".",
"clc",
".",
"field_name",
")",
",",
"... | process to make the new field | [
"process",
"to",
"make",
"the",
"new",
"field"
] | [
"\"\"\"\n process to make the new field\n :param kwargs:\n file_list: the list of the files, if not given, use all the files with selected field extension\n file_ext: the new file extension, if not given, use the same as the old one\n d_type: the new data type, if not ... | [
{
"param": "self",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
... |
2f034a6be63677693d6d8b133adca11441c61e6f | bohaohuang/ersa | collection/collectionMaker.py | [
"MIT"
] | Python | read_collection | <not_specific> | def read_collection(clc_name=None, clc_dir=None, raw_data_path=None, field_name=None, field_id=None, rgb_ext=None,
gt_ext=None, file_ext=None, files=None, force_run=False):
"""
Read and initialize a collection from a directory, try to create one if it does not exists
:param clc_name: nam... |
Read and initialize a collection from a directory, try to create one if it does not exists
:param clc_name: name of the collection
:param clc_dir: directory to the collection
:return: the collection object, assertion error if no process hasn't completed
:param raw_data_path: path to where the data... | Read and initialize a collection from a directory, try to create one if it does not exists | [
"Read",
"and",
"initialize",
"a",
"collection",
"from",
"a",
"directory",
"try",
"to",
"create",
"one",
"if",
"it",
"does",
"not",
"exists"
] | def read_collection(clc_name=None, clc_dir=None, raw_data_path=None, field_name=None, field_id=None, rgb_ext=None,
gt_ext=None, file_ext=None, files=None, force_run=False):
if clc_dir is None:
assert clc_name is not None
clc_dir = ersa_utils.get_block_dir('data', ['collection', c... | [
"def",
"read_collection",
"(",
"clc_name",
"=",
"None",
",",
"clc_dir",
"=",
"None",
",",
"raw_data_path",
"=",
"None",
",",
"field_name",
"=",
"None",
",",
"field_id",
"=",
"None",
",",
"rgb_ext",
"=",
"None",
",",
"gt_ext",
"=",
"None",
",",
"file_ext"... | Read and initialize a collection from a directory, try to create one if it does not exists | [
"Read",
"and",
"initialize",
"a",
"collection",
"from",
"a",
"directory",
"try",
"to",
"create",
"one",
"if",
"it",
"does",
"not",
"exists"
] | [
"\"\"\"\n Read and initialize a collection from a directory, try to create one if it does not exists\n :param clc_name: name of the collection\n :param clc_dir: directory to the collection\n :return: the collection object, assertion error if no process hasn't completed\n\n :param raw_data_path: path ... | [
{
"param": "clc_name",
"type": null
},
{
"param": "clc_dir",
"type": null
},
{
"param": "raw_data_path",
"type": null
},
{
"param": "field_name",
"type": null
},
{
"param": "field_id",
"type": null
},
{
"param": "rgb_ext",
"type": null
},
{
... | {
"returns": [
{
"docstring": "the collection object, assertion error if no process hasn't completed",
"docstring_tokens": [
"the",
"collection",
"object",
"assertion",
"error",
"if",
"no",
"process",
"hasn",
"'",
... |
2f034a6be63677693d6d8b133adca11441c61e6f | bohaohuang/ersa | collection/collectionMaker.py | [
"MIT"
] | Python | make_regexp | <not_specific> | def make_regexp(field_name, field_id, field_txt, file_ext):
"""
make regex pattern for filter out the selected files
:param field_name: name of the 'cities' to include in the collection
:param field_id: id of the 'cities' to include in the collection
:param field_txt: extension o... |
make regex pattern for filter out the selected files
:param field_name: name of the 'cities' to include in the collection
:param field_id: id of the 'cities' to include in the collection
:param field_txt: extension of the field, e.g. 'GT' or 'RGB
:param file_ext: extension of th... | make regex pattern for filter out the selected files | [
"make",
"regex",
"pattern",
"for",
"filter",
"out",
"the",
"selected",
"files"
] | def make_regexp(field_name, field_id, field_txt, file_ext):
regexp = r'.*({})[\D]*({})[\D]{}.*.{}'.format('|'.join(field_name), '|'.join(field_id), field_txt, file_ext)
return regexp | [
"def",
"make_regexp",
"(",
"field_name",
",",
"field_id",
",",
"field_txt",
",",
"file_ext",
")",
":",
"regexp",
"=",
"r'.*({})[\\D]*({})[\\D]{}.*.{}'",
".",
"format",
"(",
"'|'",
".",
"join",
"(",
"field_name",
")",
",",
"'|'",
".",
"join",
"(",
"field_id",... | make regex pattern for filter out the selected files | [
"make",
"regex",
"pattern",
"for",
"filter",
"out",
"the",
"selected",
"files"
] | [
"\"\"\"\n make regex pattern for filter out the selected files\n :param field_name: name of the 'cities' to include in the collection\n :param field_id: id of the 'cities' to include in the collection\n :param field_txt: extension of the field, e.g. 'GT' or 'RGB\n :param file_ext:... | [
{
"param": "field_name",
"type": null
},
{
"param": "field_id",
"type": null
},
{
"param": "field_txt",
"type": null
},
{
"param": "file_ext",
"type": null
}
] | {
"returns": [
{
"docstring": "regex pattern string",
"docstring_tokens": [
"regex",
"pattern",
"string"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "field_name",
"type": null,
"docstring": "name of the 'cities' to ... |
2f034a6be63677693d6d8b133adca11441c61e6f | bohaohuang/ersa | collection/collectionMaker.py | [
"MIT"
] | Python | make_collection | null | def make_collection(self):
"""
Make meta data of the collection, including tile dimension, ground truth and rgb files list
means of all channels in rgb files
:return:
"""
# collect files selection
gt_regexp = self.make_regexp(self.field_name, self.field_id, self.g... |
Make meta data of the collection, including tile dimension, ground truth and rgb files list
means of all channels in rgb files
:return:
| Make meta data of the collection, including tile dimension, ground truth and rgb files list
means of all channels in rgb files | [
"Make",
"meta",
"data",
"of",
"the",
"collection",
"including",
"tile",
"dimension",
"ground",
"truth",
"and",
"rgb",
"files",
"list",
"means",
"of",
"all",
"channels",
"in",
"rgb",
"files"
] | def make_collection(self):
gt_regexp = self.make_regexp(self.field_name, self.field_id, self.gt_ext, self.file_ext[-1])
gt_files = self.get_files(gt_regexp, full_path=True)
rgb_files = []
for cnt, ext in enumerate(self.rgb_ext):
rgb_regexp = self.make_regexp(self.field_name, ... | [
"def",
"make_collection",
"(",
"self",
")",
":",
"gt_regexp",
"=",
"self",
".",
"make_regexp",
"(",
"self",
".",
"field_name",
",",
"self",
".",
"field_id",
",",
"self",
".",
"gt_ext",
",",
"self",
".",
"file_ext",
"[",
"-",
"1",
"]",
")",
"gt_files",
... | Make meta data of the collection, including tile dimension, ground truth and rgb files list
means of all channels in rgb files | [
"Make",
"meta",
"data",
"of",
"the",
"collection",
"including",
"tile",
"dimension",
"ground",
"truth",
"and",
"rgb",
"files",
"list",
"means",
"of",
"all",
"channels",
"in",
"rgb",
"files"
] | [
"\"\"\"\n Make meta data of the collection, including tile dimension, ground truth and rgb files list\n means of all channels in rgb files\n :return:\n \"\"\"",
"# collect files selection",
"# rgb data can have multiple channels and be stored in multiple files",
"# make meta_data"
... | [
{
"param": "self",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
... |
2f034a6be63677693d6d8b133adca11441c61e6f | bohaohuang/ersa | collection/collectionMaker.py | [
"MIT"
] | Python | read_meta_data | <not_specific> | def read_meta_data(self):
"""
Read meta data of the collection
:return:
"""
meta_data = ersa_utils.load_file(os.path.join(self.clc_dir, 'meta.pkl'))
return meta_data |
Read meta data of the collection
:return:
| Read meta data of the collection | [
"Read",
"meta",
"data",
"of",
"the",
"collection"
] | def read_meta_data(self):
meta_data = ersa_utils.load_file(os.path.join(self.clc_dir, 'meta.pkl'))
return meta_data | [
"def",
"read_meta_data",
"(",
"self",
")",
":",
"meta_data",
"=",
"ersa_utils",
".",
"load_file",
"(",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"clc_dir",
",",
"'meta.pkl'",
")",
")",
"return",
"meta_data"
] | Read meta data of the collection | [
"Read",
"meta",
"data",
"of",
"the",
"collection"
] | [
"\"\"\"\n Read meta data of the collection\n :return:\n \"\"\""
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
... |
2f034a6be63677693d6d8b133adca11441c61e6f | bohaohuang/ersa | collection/collectionMaker.py | [
"MIT"
] | Python | print_meta_data | null | def print_meta_data(self):
"""
Print the meta data in a human readable format
:return:
"""
print(ersa_utils.make_center_string('=', 88, self.clc_name))
skip_keys = ['gt_files', 'rgb_files', 'rgb_ext', 'gt_ext', 'file_ext', 'files']
for key, val in self.meta_data.i... |
Print the meta data in a human readable format
:return:
| Print the meta data in a human readable format | [
"Print",
"the",
"meta",
"data",
"in",
"a",
"human",
"readable",
"format"
] | def print_meta_data(self):
print(ersa_utils.make_center_string('=', 88, self.clc_name))
skip_keys = ['gt_files', 'rgb_files', 'rgb_ext', 'gt_ext', 'file_ext', 'files']
for key, val in self.meta_data.items():
if key in skip_keys:
continue
if type(val) is li... | [
"def",
"print_meta_data",
"(",
"self",
")",
":",
"print",
"(",
"ersa_utils",
".",
"make_center_string",
"(",
"'='",
",",
"88",
",",
"self",
".",
"clc_name",
")",
")",
"skip_keys",
"=",
"[",
"'gt_files'",
",",
"'rgb_files'",
",",
"'rgb_ext'",
",",
"'gt_ext'... | Print the meta data in a human readable format | [
"Print",
"the",
"meta",
"data",
"in",
"a",
"human",
"readable",
"format"
] | [
"\"\"\"\n Print the meta data in a human readable format\n :return:\n \"\"\""
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
... |
2f034a6be63677693d6d8b133adca11441c61e6f | bohaohuang/ersa | collection/collectionMaker.py | [
"MIT"
] | Python | replace_channel | <not_specific> | def replace_channel(self, files, is_gt, field_ext_pair, new_file_ext=None):
"""
Replace a channel in the collection, then remake the meta data
:param files: files correspond to the replaced channel
:param is_gt: is replacing ground truth or not
:param field_ext_pair: old filed ex... |
Replace a channel in the collection, then remake the meta data
:param files: files correspond to the replaced channel
:param is_gt: is replacing ground truth or not
:param field_ext_pair: old filed extension and new field extension, should be a list
:param new_file_ext: new file... | Replace a channel in the collection, then remake the meta data | [
"Replace",
"a",
"channel",
"in",
"the",
"collection",
"then",
"remake",
"the",
"meta",
"data"
] | def replace_channel(self, files, is_gt, field_ext_pair, new_file_ext=None):
if new_file_ext is None:
try:
new_file_ext = files[0].split('.')[-1]
except IndexError:
print('{} might already exist, skip replacement'.format(field_ext_pair[1]))
... | [
"def",
"replace_channel",
"(",
"self",
",",
"files",
",",
"is_gt",
",",
"field_ext_pair",
",",
"new_file_ext",
"=",
"None",
")",
":",
"if",
"new_file_ext",
"is",
"None",
":",
"try",
":",
"new_file_ext",
"=",
"files",
"[",
"0",
"]",
".",
"split",
"(",
"... | Replace a channel in the collection, then remake the meta data | [
"Replace",
"a",
"channel",
"in",
"the",
"collection",
"then",
"remake",
"the",
"meta",
"data"
] | [
"\"\"\"\n Replace a channel in the collection, then remake the meta data\n :param files: files correspond to the replaced channel\n :param is_gt: is replacing ground truth or not\n :param field_ext_pair: old filed extension and new field extension, should be a list\n :param new_fi... | [
{
"param": "self",
"type": null
},
{
"param": "files",
"type": null
},
{
"param": "is_gt",
"type": null
},
{
"param": "field_ext_pair",
"type": null
},
{
"param": "new_file_ext",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
... |
2f034a6be63677693d6d8b133adca11441c61e6f | bohaohuang/ersa | collection/collectionMaker.py | [
"MIT"
] | Python | add_channel | <not_specific> | def add_channel(self, files, new_field_ext):
"""
Add a channel to the collection, then remake the meta data
:param files: files correspond to the added channel
:param new_field_ext: new field extension
:return:
"""
if new_field_ext in self.rgb_ext:
pri... |
Add a channel to the collection, then remake the meta data
:param files: files correspond to the added channel
:param new_field_ext: new field extension
:return:
| Add a channel to the collection, then remake the meta data | [
"Add",
"a",
"channel",
"to",
"the",
"collection",
"then",
"remake",
"the",
"meta",
"data"
] | def add_channel(self, files, new_field_ext):
if new_field_ext in self.rgb_ext:
print('{} already exits!'.format(new_field_ext))
return
new_file_ext = files[0].split('.')[-1]
self.rgb_ext.append(new_field_ext)
if len(self.gt_ext) == 0:
self.file_ext.app... | [
"def",
"add_channel",
"(",
"self",
",",
"files",
",",
"new_field_ext",
")",
":",
"if",
"new_field_ext",
"in",
"self",
".",
"rgb_ext",
":",
"print",
"(",
"'{} already exits!'",
".",
"format",
"(",
"new_field_ext",
")",
")",
"return",
"new_file_ext",
"=",
"fil... | Add a channel to the collection, then remake the meta data | [
"Add",
"a",
"channel",
"to",
"the",
"collection",
"then",
"remake",
"the",
"meta",
"data"
] | [
"\"\"\"\n Add a channel to the collection, then remake the meta data\n :param files: files correspond to the added channel\n :param new_field_ext: new field extension\n :return:\n \"\"\"",
"# update files, then re-make meta data",
"# need to re-compute mean here, can be improv... | [
{
"param": "self",
"type": null
},
{
"param": "files",
"type": null
},
{
"param": "new_field_ext",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
... |
2f034a6be63677693d6d8b133adca11441c61e6f | bohaohuang/ersa | collection/collectionMaker.py | [
"MIT"
] | Python | load_files | <not_specific> | def load_files(self, field_name=None, field_id=None, field_ext=None):
"""
Load all files meet the given filters, each one above can be left blank
:param field_name: name of the field
:param field_id: name of the id
:param field_ext: name of the field extension
:return:
... |
Load all files meet the given filters, each one above can be left blank
:param field_name: name of the field
:param field_id: name of the id
:param field_ext: name of the field extension
:return:
| Load all files meet the given filters, each one above can be left blank | [
"Load",
"all",
"files",
"meet",
"the",
"given",
"filters",
"each",
"one",
"above",
"can",
"be",
"left",
"blank"
] | def load_files(self, field_name=None, field_id=None, field_ext=None):
if field_name is None:
field_name = self.field_name
if field_id is None:
field_id = self.field_id
field_ext = ersa_utils.str2list(field_ext, d_type=str)
files = []
for fe in field_ext:
... | [
"def",
"load_files",
"(",
"self",
",",
"field_name",
"=",
"None",
",",
"field_id",
"=",
"None",
",",
"field_ext",
"=",
"None",
")",
":",
"if",
"field_name",
"is",
"None",
":",
"field_name",
"=",
"self",
".",
"field_name",
"if",
"field_id",
"is",
"None",
... | Load all files meet the given filters, each one above can be left blank | [
"Load",
"all",
"files",
"meet",
"the",
"given",
"filters",
"each",
"one",
"above",
"can",
"be",
"left",
"blank"
] | [
"\"\"\"\n Load all files meet the given filters, each one above can be left blank\n :param field_name: name of the field\n :param field_id: name of the id\n :param field_ext: name of the field extension\n :return:\n \"\"\"",
"# only one file been requested"
] | [
{
"param": "self",
"type": null
},
{
"param": "field_name",
"type": null
},
{
"param": "field_id",
"type": null
},
{
"param": "field_ext",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
... |
536e9bc726cdb708cbae7fce4228b47764e5d649 | bohaohuang/ersa | preprocess/gammaAdjust.py | [
"MIT"
] | Python | adjust_gamma | <not_specific> | def adjust_gamma(img, gamma):
"""
Adjust the gamma for given image
:param img:
:param gamma:
:return:
"""
inv_gamma = 1.0 / gamma
table = np.array([((i / 255.0) ** inv_gamma) * 255 for i in np.arange(0, 256)]).astype('uint8')
img_adjust = cv2.LUT(i... |
Adjust the gamma for given image
:param img:
:param gamma:
:return:
| Adjust the gamma for given image | [
"Adjust",
"the",
"gamma",
"for",
"given",
"image"
] | def adjust_gamma(img, gamma):
inv_gamma = 1.0 / gamma
table = np.array([((i / 255.0) ** inv_gamma) * 255 for i in np.arange(0, 256)]).astype('uint8')
img_adjust = cv2.LUT(img, table)
return img_adjust | [
"def",
"adjust_gamma",
"(",
"img",
",",
"gamma",
")",
":",
"inv_gamma",
"=",
"1.0",
"/",
"gamma",
"table",
"=",
"np",
".",
"array",
"(",
"[",
"(",
"(",
"i",
"/",
"255.0",
")",
"**",
"inv_gamma",
")",
"*",
"255",
"for",
"i",
"in",
"np",
".",
"ar... | Adjust the gamma for given image | [
"Adjust",
"the",
"gamma",
"for",
"given",
"image"
] | [
"\"\"\"\n Adjust the gamma for given image\n :param img:\n :param gamma:\n :return:\n \"\"\""
] | [
{
"param": "img",
"type": null
},
{
"param": "gamma",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "img",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
"... |
baa832995edd893ba4823ae33f670eb15383284d | bohaohuang/ersa | nn/nn_processor.py | [
"MIT"
] | Python | load_results | <not_specific> | def load_results(self):
"""
load all the results computed by this process
:return: tile based iou, field based iou and overall iou
"""
print('Summary of results:')
result_name = os.path.join(self.score_save_dir, 'result.txt')
result = ersa_utils.load_file(result_n... |
load all the results computed by this process
:return: tile based iou, field based iou and overall iou
| load all the results computed by this process | [
"load",
"all",
"the",
"results",
"computed",
"by",
"this",
"process"
] | def load_results(self):
print('Summary of results:')
result_name = os.path.join(self.score_save_dir, 'result.txt')
result = ersa_utils.load_file(result_name)
tile_dict, field_dict, overall = nn_utils.read_iou_from_file(result)
for key, val in field_dict.items():
field... | [
"def",
"load_results",
"(",
"self",
")",
":",
"print",
"(",
"'Summary of results:'",
")",
"result_name",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"score_save_dir",
",",
"'result.txt'",
")",
"result",
"=",
"ersa_utils",
".",
"load_file",
"(",
... | load all the results computed by this process | [
"load",
"all",
"the",
"results",
"computed",
"by",
"this",
"process"
] | [
"\"\"\"\n load all the results computed by this process\n :return: tile based iou, field based iou and overall iou\n \"\"\""
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
... |
8479b2ad4b9e98598cd389de96a76240959136c9 | bohaohuang/ersa | nn/basicNetwork.py | [
"MIT"
] | Python | make_ckdir | null | def make_ckdir(self, ckdir, patch_size, par_dir=None):
"""
Made checkpoint directory for the neural network
:param ckdir: base directory of the ckpt
:param patch_size: size of the input patch, could be a single number of tuple
:param par_dir: if not None, the ckpt will be stored ... |
Made checkpoint directory for the neural network
:param ckdir: base directory of the ckpt
:param patch_size: size of the input patch, could be a single number of tuple
:param par_dir: if not None, the ckpt will be stored in ckdir/par_dir
:return:
| Made checkpoint directory for the neural network | [
"Made",
"checkpoint",
"directory",
"for",
"the",
"neural",
"network"
] | def make_ckdir(self, ckdir, patch_size, par_dir=None):
if type(patch_size) is list:
patch_size = patch_size[0]
dir_name = '{}_PS{}_BS{}_EP{}_LR{}_DS{}_DR{}'.\
format(self.model_name, patch_size, self.bs, self.epochs, self.lr, self.ds, self.dr)
if par_dir is None:
... | [
"def",
"make_ckdir",
"(",
"self",
",",
"ckdir",
",",
"patch_size",
",",
"par_dir",
"=",
"None",
")",
":",
"if",
"type",
"(",
"patch_size",
")",
"is",
"list",
":",
"patch_size",
"=",
"patch_size",
"[",
"0",
"]",
"dir_name",
"=",
"'{}_PS{}_BS{}_EP{}_LR{}_DS{... | Made checkpoint directory for the neural network | [
"Made",
"checkpoint",
"directory",
"for",
"the",
"neural",
"network"
] | [
"\"\"\"\n Made checkpoint directory for the neural network\n :param ckdir: base directory of the ckpt\n :param patch_size: size of the input patch, could be a single number of tuple\n :param par_dir: if not None, the ckpt will be stored in ckdir/par_dir\n :return:\n \"\"\""... | [
{
"param": "self",
"type": null
},
{
"param": "ckdir",
"type": null
},
{
"param": "patch_size",
"type": null
},
{
"param": "par_dir",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
... |
8479b2ad4b9e98598cd389de96a76240959136c9 | bohaohuang/ersa | nn/basicNetwork.py | [
"MIT"
] | Python | make_optimizer | null | def make_optimizer(self, train_var_filter):
"""
Make optimizer fot the network, Adam is used
:param train_var_filter: if not None, only optimize variables in train_var_filter
:return:
"""
with tf.control_dependencies(self.update_ops):
if train_var_filter is No... |
Make optimizer fot the network, Adam is used
:param train_var_filter: if not None, only optimize variables in train_var_filter
:return:
| Make optimizer fot the network, Adam is used | [
"Make",
"optimizer",
"fot",
"the",
"network",
"Adam",
"is",
"used"
] | def make_optimizer(self, train_var_filter):
with tf.control_dependencies(self.update_ops):
if train_var_filter is None:
self.optimizer = tf.train.AdamOptimizer(self.lr_op).minimize(self.loss, global_step=self.global_step)
else:
print('Train parameters in s... | [
"def",
"make_optimizer",
"(",
"self",
",",
"train_var_filter",
")",
":",
"with",
"tf",
".",
"control_dependencies",
"(",
"self",
".",
"update_ops",
")",
":",
"if",
"train_var_filter",
"is",
"None",
":",
"self",
".",
"optimizer",
"=",
"tf",
".",
"train",
".... | Make optimizer fot the network, Adam is used | [
"Make",
"optimizer",
"fot",
"the",
"network",
"Adam",
"is",
"used"
] | [
"\"\"\"\n Make optimizer fot the network, Adam is used\n :param train_var_filter: if not None, only optimize variables in train_var_filter\n :return:\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "train_var_filter",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
... |
8479b2ad4b9e98598cd389de96a76240959136c9 | bohaohuang/ersa | nn/basicNetwork.py | [
"MIT"
] | Python | make_loss | null | def make_loss(self, label, loss_type='xent'):
"""
Make loss to optimize for the network
:param label: input labels, can be generated by tf.data.Dataset
:param loss_type:
xent: cross entropy loss
:return:
"""
with tf.variable_scope('loss'):
... |
Make loss to optimize for the network
:param label: input labels, can be generated by tf.data.Dataset
:param loss_type:
xent: cross entropy loss
:return:
| Make loss to optimize for the network | [
"Make",
"loss",
"to",
"optimize",
"for",
"the",
"network"
] | def make_loss(self, label, loss_type='xent'):
with tf.variable_scope('loss'):
pred_flat = tf.reshape(self.pred, [-1, self.class_num])
y_flat = tf.reshape(tf.squeeze(label, axis=[3]), [-1, ])
indices = tf.squeeze(tf.where(tf.less_equal(y_flat, self.class_num - 1)), 1)
... | [
"def",
"make_loss",
"(",
"self",
",",
"label",
",",
"loss_type",
"=",
"'xent'",
")",
":",
"with",
"tf",
".",
"variable_scope",
"(",
"'loss'",
")",
":",
"pred_flat",
"=",
"tf",
".",
"reshape",
"(",
"self",
".",
"pred",
",",
"[",
"-",
"1",
",",
"self... | Make loss to optimize for the network | [
"Make",
"loss",
"to",
"optimize",
"for",
"the",
"network"
] | [
"\"\"\"\n Make loss to optimize for the network\n :param label: input labels, can be generated by tf.data.Dataset\n :param loss_type:\n xent: cross entropy loss\n :return:\n \"\"\"",
"# TODO focal loss:",
"# https://github.com/ailias/Focal-Loss-implement-on-Tensorfl... | [
{
"param": "self",
"type": null
},
{
"param": "label",
"type": null
},
{
"param": "loss_type",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
... |
8479b2ad4b9e98598cd389de96a76240959136c9 | bohaohuang/ersa | nn/basicNetwork.py | [
"MIT"
] | Python | evaluate | <not_specific> | def evaluate(self, file_list, input_size, tile_size, batch_size, img_mean,
model_dir, gpu=None, save_result_parent_dir=None, name='nn_estimator_segment',
verb=True, ds_name='default', load_epoch_num=None, best_model=False,
truth_val=1, force_run=False, score_results=Tr... |
Evaluate model on given validation set
:param file_list: evaluation file list
:param input_size: dimension of the input to the network
:param tile_size: dimension of the single evaluation file
:param batch_size: batch size
:param img_mean: mean of each channel
:p... | Evaluate model on given validation set | [
"Evaluate",
"model",
"on",
"given",
"validation",
"set"
] | def evaluate(self, file_list, input_size, tile_size, batch_size, img_mean,
model_dir, gpu=None, save_result_parent_dir=None, name='nn_estimator_segment',
verb=True, ds_name='default', load_epoch_num=None, best_model=False,
truth_val=1, force_run=False, score_results=Tr... | [
"def",
"evaluate",
"(",
"self",
",",
"file_list",
",",
"input_size",
",",
"tile_size",
",",
"batch_size",
",",
"img_mean",
",",
"model_dir",
",",
"gpu",
"=",
"None",
",",
"save_result_parent_dir",
"=",
"None",
",",
"name",
"=",
"'nn_estimator_segment'",
",",
... | Evaluate model on given validation set | [
"Evaluate",
"model",
"on",
"given",
"validation",
"set"
] | [
"\"\"\"\n Evaluate model on given validation set\n :param file_list: evaluation file list\n :param input_size: dimension of the input to the network\n :param tile_size: dimension of the single evaluation file\n :param batch_size: batch size\n :param img_mean: mean of each c... | [
{
"param": "self",
"type": null
},
{
"param": "file_list",
"type": null
},
{
"param": "input_size",
"type": null
},
{
"param": "tile_size",
"type": null
},
{
"param": "batch_size",
"type": null
},
{
"param": "img_mean",
"type": null
},
{
"p... | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
... |
8479b2ad4b9e98598cd389de96a76240959136c9 | bohaohuang/ersa | nn/basicNetwork.py | [
"MIT"
] | Python | create_resetable_metric | <not_specific> | def create_resetable_metric(metric, var_name, scope=tf.get_variable_scope().name, **kwargs):
"""
Create resetable operations for a streaming metric
:param metric: streaming metric function
:param var_name: name of the metric variable
:param scope: default to current scope name
... |
Create resetable operations for a streaming metric
:param metric: streaming metric function
:param var_name: name of the metric variable
:param scope: default to current scope name
:param kwargs:
:return:
| Create resetable operations for a streaming metric | [
"Create",
"resetable",
"operations",
"for",
"a",
"streaming",
"metric"
] | def create_resetable_metric(metric, var_name, scope=tf.get_variable_scope().name, **kwargs):
metric_op, update_op = metric(**kwargs)
vars = tf.get_collection(tf.GraphKeys.LOCAL_VARIABLES, scope='{}/{}'.format(scope, var_name))
reset_op = tf.variables_initializer(vars)
return metric_op, u... | [
"def",
"create_resetable_metric",
"(",
"metric",
",",
"var_name",
",",
"scope",
"=",
"tf",
".",
"get_variable_scope",
"(",
")",
".",
"name",
",",
"**",
"kwargs",
")",
":",
"metric_op",
",",
"update_op",
"=",
"metric",
"(",
"**",
"kwargs",
")",
"vars",
"=... | Create resetable operations for a streaming metric | [
"Create",
"resetable",
"operations",
"for",
"a",
"streaming",
"metric"
] | [
"\"\"\"\n Create resetable operations for a streaming metric\n :param metric: streaming metric function\n :param var_name: name of the metric variable\n :param scope: default to current scope name\n :param kwargs:\n :return:\n \"\"\""
] | [
{
"param": "metric",
"type": null
},
{
"param": "var_name",
"type": null
},
{
"param": "scope",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "metric",
"type": null,
"docstring": "streaming metric function",
"docstring_tokens": [
"streaming",
... |
8479b2ad4b9e98598cd389de96a76240959136c9 | bohaohuang/ersa | nn/basicNetwork.py | [
"MIT"
] | Python | create_resetable_metric_single_iou | <not_specific> | def create_resetable_metric_single_iou(scope=tf.get_variable_scope().name, **kwargs):
"""
Create resetable operations for iou metric, this metric will noly calculate iou for class 1
:param metric: streaming metric function
:param var_name: name of the metric variable
:param scope... |
Create resetable operations for iou metric, this metric will noly calculate iou for class 1
:param metric: streaming metric function
:param var_name: name of the metric variable
:param scope: default to current scope name
:param kwargs:
:return:
| Create resetable operations for iou metric, this metric will noly calculate iou for class 1 | [
"Create",
"resetable",
"operations",
"for",
"iou",
"metric",
"this",
"metric",
"will",
"noly",
"calculate",
"iou",
"for",
"class",
"1"
] | def create_resetable_metric_single_iou(scope=tf.get_variable_scope().name, **kwargs):
def single_class_metric_fn(predictions=None, labels=None):
vars = []
tp, update_tp = tf.metrics.true_positives(labels=labels, predictions=predictions, name='tp')
vars.append(tf.get_collectio... | [
"def",
"create_resetable_metric_single_iou",
"(",
"scope",
"=",
"tf",
".",
"get_variable_scope",
"(",
")",
".",
"name",
",",
"**",
"kwargs",
")",
":",
"def",
"single_class_metric_fn",
"(",
"predictions",
"=",
"None",
",",
"labels",
"=",
"None",
")",
":",
"va... | Create resetable operations for iou metric, this metric will noly calculate iou for class 1 | [
"Create",
"resetable",
"operations",
"for",
"iou",
"metric",
"this",
"metric",
"will",
"noly",
"calculate",
"iou",
"for",
"class",
"1"
] | [
"\"\"\"\n Create resetable operations for iou metric, this metric will noly calculate iou for class 1\n :param metric: streaming metric function\n :param var_name: name of the metric variable\n :param scope: default to current scope name\n :param kwargs:\n :return:\n ... | [
{
"param": "scope",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "scope",
"type": null,
"docstring": "default to current scope name",
"docstring_tokens": [
"default",
... |
cb7c43b7e0a6c43c823846ff2e3f508d9a85262e | bohaohuang/ersa | preprocess/patchExtractor.py | [
"MIT"
] | Python | patch_block | null | def patch_block(block, pad, grid_list, patch_size, return_coord=False):
"""
make a data block into patches
:param block: data block to be patched, shold be h*w*c
:param pad: #pixels to pad around
:param grid_list: list of grids
:param patch_size: size of the patch
:param return_coord: if Tru... |
make a data block into patches
:param block: data block to be patched, shold be h*w*c
:param pad: #pixels to pad around
:param grid_list: list of grids
:param patch_size: size of the patch
:param return_coord: if True, coordinates of x and y will be returned
:return: yields patches or as we... | make a data block into patches | [
"make",
"a",
"data",
"block",
"into",
"patches"
] | def patch_block(block, pad, grid_list, patch_size, return_coord=False):
if pad > 0:
block = ersa_utils.pad_image(block, pad)
for y, x in grid_list:
patch = ersa_utils.crop_image(block, y, x, patch_size[0], patch_size[1])
if return_coord:
yield patch, y, x
else:
... | [
"def",
"patch_block",
"(",
"block",
",",
"pad",
",",
"grid_list",
",",
"patch_size",
",",
"return_coord",
"=",
"False",
")",
":",
"if",
"pad",
">",
"0",
":",
"block",
"=",
"ersa_utils",
".",
"pad_image",
"(",
"block",
",",
"pad",
")",
"for",
"y",
","... | make a data block into patches | [
"make",
"a",
"data",
"block",
"into",
"patches"
] | [
"\"\"\"\n make a data block into patches\n :param block: data block to be patched, shold be h*w*c\n :param pad: #pixels to pad around\n :param grid_list: list of grids\n :param patch_size: size of the patch\n :param return_coord: if True, coordinates of x and y will be returned\n :return: yield... | [
{
"param": "block",
"type": null
},
{
"param": "pad",
"type": null
},
{
"param": "grid_list",
"type": null
},
{
"param": "patch_size",
"type": null
},
{
"param": "return_coord",
"type": null
}
] | {
"returns": [
{
"docstring": "yields patches or as well as x and y coordinates",
"docstring_tokens": [
"yields",
"patches",
"or",
"as",
"well",
"as",
"x",
"and",
"y",
"coordinates"
],
"type": null
}
],
... |
cb7c43b7e0a6c43c823846ff2e3f508d9a85262e | bohaohuang/ersa | preprocess/patchExtractor.py | [
"MIT"
] | Python | unpatch_block | <not_specific> | def unpatch_block(blocks, tile_dim, patch_size, tile_dim_output=None, patch_size_output=None, overlap=0):
"""
Unpatch a block, set tile_dim_output and patch_size_output to a proper number if padding exits
:param blocks: data blocks, should be n*h*w*c
:param tile_dim: input tile dimension, if padding exi... |
Unpatch a block, set tile_dim_output and patch_size_output to a proper number if padding exits
:param blocks: data blocks, should be n*h*w*c
:param tile_dim: input tile dimension, if padding exits should be h+2*pad, w+2*pad
:param patch_size: input patch size
:param tile_dim_output: output tile dim... | Unpatch a block, set tile_dim_output and patch_size_output to a proper number if padding exits | [
"Unpatch",
"a",
"block",
"set",
"tile_dim_output",
"and",
"patch_size_output",
"to",
"a",
"proper",
"number",
"if",
"padding",
"exits"
] | def unpatch_block(blocks, tile_dim, patch_size, tile_dim_output=None, patch_size_output=None, overlap=0):
if tile_dim_output is None:
tile_dim_output = tile_dim
if patch_size_output is None:
patch_size_output = patch_size
_, _, _, c = blocks.shape
image = np.zeros((tile_dim_output[0], ti... | [
"def",
"unpatch_block",
"(",
"blocks",
",",
"tile_dim",
",",
"patch_size",
",",
"tile_dim_output",
"=",
"None",
",",
"patch_size_output",
"=",
"None",
",",
"overlap",
"=",
"0",
")",
":",
"if",
"tile_dim_output",
"is",
"None",
":",
"tile_dim_output",
"=",
"ti... | Unpatch a block, set tile_dim_output and patch_size_output to a proper number if padding exits | [
"Unpatch",
"a",
"block",
"set",
"tile_dim_output",
"and",
"patch_size_output",
"to",
"a",
"proper",
"number",
"if",
"padding",
"exits"
] | [
"\"\"\"\n Unpatch a block, set tile_dim_output and patch_size_output to a proper number if padding exits\n :param blocks: data blocks, should be n*h*w*c\n :param tile_dim: input tile dimension, if padding exits should be h+2*pad, w+2*pad\n :param patch_size: input patch size\n :param tile_dim_output:... | [
{
"param": "blocks",
"type": null
},
{
"param": "tile_dim",
"type": null
},
{
"param": "patch_size",
"type": null
},
{
"param": "tile_dim_output",
"type": null
},
{
"param": "patch_size_output",
"type": null
},
{
"param": "overlap",
"type": null
... | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "blocks",
"type": null,
"docstring": "data blocks, should be n*h*w*c",
"docstring_tokens": [
"data",
... |
f2891e8db93e96da0a0f778b9e33473f6b6eb59c | bohaohuang/ersa | ersa_utils.py | [
"MIT"
] | Python | make_dir_if_not_exist | null | def make_dir_if_not_exist(dir_path):
"""
Make the directory if it does not exists
:param dir_path: absolute path to the directory
:return:
"""
if not os.path.exists(dir_path):
os.makedirs(dir_path) |
Make the directory if it does not exists
:param dir_path: absolute path to the directory
:return:
| Make the directory if it does not exists | [
"Make",
"the",
"directory",
"if",
"it",
"does",
"not",
"exists"
] | def make_dir_if_not_exist(dir_path):
if not os.path.exists(dir_path):
os.makedirs(dir_path) | [
"def",
"make_dir_if_not_exist",
"(",
"dir_path",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"dir_path",
")",
":",
"os",
".",
"makedirs",
"(",
"dir_path",
")"
] | Make the directory if it does not exists | [
"Make",
"the",
"directory",
"if",
"it",
"does",
"not",
"exists"
] | [
"\"\"\"\n Make the directory if it does not exists\n :param dir_path: absolute path to the directory\n :return:\n \"\"\""
] | [
{
"param": "dir_path",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "dir_path",
"type": null,
"docstring": "absolute path to the directory",
"docstring_tokens": [
"absolute",
... |
f2891e8db93e96da0a0f778b9e33473f6b6eb59c | bohaohuang/ersa | ersa_utils.py | [
"MIT"
] | Python | timer_decorator | <not_specific> | def timer_decorator(func):
"""
This is a decorator to print out running time of executing func
:param func:
:return:
"""
@wraps(func)
def timer_wrapper(*args, **kwargs):
start_time = time.time()
func(*args, **kwargs)
duration = time.time() - start_time
print('... |
This is a decorator to print out running time of executing func
:param func:
:return:
| This is a decorator to print out running time of executing func | [
"This",
"is",
"a",
"decorator",
"to",
"print",
"out",
"running",
"time",
"of",
"executing",
"func"
] | def timer_decorator(func):
@wraps(func)
def timer_wrapper(*args, **kwargs):
start_time = time.time()
func(*args, **kwargs)
duration = time.time() - start_time
print('duration: {:.3f}s'.format(duration))
return timer_wrapper | [
"def",
"timer_decorator",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"timer_wrapper",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"start_time",
"=",
"time",
".",
"time",
"(",
")",
"func",
"(",
"*",
"args",
",",
"**",
"kwargs... | This is a decorator to print out running time of executing func | [
"This",
"is",
"a",
"decorator",
"to",
"print",
"out",
"running",
"time",
"of",
"executing",
"func"
] | [
"\"\"\"\n This is a decorator to print out running time of executing func\n :param func:\n :return:\n \"\"\""
] | [
{
"param": "func",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "func",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
... |
f2891e8db93e96da0a0f778b9e33473f6b6eb59c | bohaohuang/ersa | ersa_utils.py | [
"MIT"
] | Python | str2list | <not_specific> | def str2list(s, sep=',', d_type=int):
"""
Change a {sep} separated string into a list of items with d_type
:param s: input string
:param sep: separator for string
:param d_type: data type of each element
:return:
"""
if type(s) is not list:
s = [d_type(a) for a in s.split(sep)]
... |
Change a {sep} separated string into a list of items with d_type
:param s: input string
:param sep: separator for string
:param d_type: data type of each element
:return:
| Change a {sep} separated string into a list of items with d_type | [
"Change",
"a",
"{",
"sep",
"}",
"separated",
"string",
"into",
"a",
"list",
"of",
"items",
"with",
"d_type"
] | def str2list(s, sep=',', d_type=int):
if type(s) is not list:
s = [d_type(a) for a in s.split(sep)]
return s | [
"def",
"str2list",
"(",
"s",
",",
"sep",
"=",
"','",
",",
"d_type",
"=",
"int",
")",
":",
"if",
"type",
"(",
"s",
")",
"is",
"not",
"list",
":",
"s",
"=",
"[",
"d_type",
"(",
"a",
")",
"for",
"a",
"in",
"s",
".",
"split",
"(",
"sep",
")",
... | Change a {sep} separated string into a list of items with d_type | [
"Change",
"a",
"{",
"sep",
"}",
"separated",
"string",
"into",
"a",
"list",
"of",
"items",
"with",
"d_type"
] | [
"\"\"\"\n Change a {sep} separated string into a list of items with d_type\n :param s: input string\n :param sep: separator for string\n :param d_type: data type of each element\n :return:\n \"\"\""
] | [
{
"param": "s",
"type": null
},
{
"param": "sep",
"type": null
},
{
"param": "d_type",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "s",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
"is... |
f2891e8db93e96da0a0f778b9e33473f6b6eb59c | bohaohuang/ersa | ersa_utils.py | [
"MIT"
] | Python | load_file | <not_specific> | def load_file(file_name):
"""
Read data file of given path, use numpy.load if it is in .npy format,
otherwise use pickle or imageio
:param file_name: absolute path to the file
:return: file data, or IOError if it cannot be read by either numpy or pickle or imageio
"""
try:
if file_na... |
Read data file of given path, use numpy.load if it is in .npy format,
otherwise use pickle or imageio
:param file_name: absolute path to the file
:return: file data, or IOError if it cannot be read by either numpy or pickle or imageio
| Read data file of given path, use numpy.load if it is in .npy format,
otherwise use pickle or imageio | [
"Read",
"data",
"file",
"of",
"given",
"path",
"use",
"numpy",
".",
"load",
"if",
"it",
"is",
"in",
".",
"npy",
"format",
"otherwise",
"use",
"pickle",
"or",
"imageio"
] | def load_file(file_name):
try:
if file_name[-3:] == 'npy':
data = np.load(file_name)
elif file_name[-3:] == 'pkl' or file_name[-6:] == 'pickle':
with open(file_name, 'rb') as f:
data = pickle.load(f)
elif file_name[-3:] == 'txt':
with open(... | [
"def",
"load_file",
"(",
"file_name",
")",
":",
"try",
":",
"if",
"file_name",
"[",
"-",
"3",
":",
"]",
"==",
"'npy'",
":",
"data",
"=",
"np",
".",
"load",
"(",
"file_name",
")",
"elif",
"file_name",
"[",
"-",
"3",
":",
"]",
"==",
"'pkl'",
"or",
... | Read data file of given path, use numpy.load if it is in .npy format,
otherwise use pickle or imageio | [
"Read",
"data",
"file",
"of",
"given",
"path",
"use",
"numpy",
".",
"load",
"if",
"it",
"is",
"in",
".",
"npy",
"format",
"otherwise",
"use",
"pickle",
"or",
"imageio"
] | [
"\"\"\"\n Read data file of given path, use numpy.load if it is in .npy format,\n otherwise use pickle or imageio\n :param file_name: absolute path to the file\n :return: file data, or IOError if it cannot be read by either numpy or pickle or imageio\n \"\"\"",
"# so many things could go wrong, can... | [
{
"param": "file_name",
"type": null
}
] | {
"returns": [
{
"docstring": "file data, or IOError if it cannot be read by either numpy or pickle or imageio",
"docstring_tokens": [
"file",
"data",
"or",
"IOError",
"if",
"it",
"cannot",
"be",
"read",
"by",
"eit... |
f2891e8db93e96da0a0f778b9e33473f6b6eb59c | bohaohuang/ersa | ersa_utils.py | [
"MIT"
] | Python | save_file | <not_specific> | def save_file(file_name, data):
"""
Save data file of given path, use numpy.load if it is in .npy format,
otherwise use pickle or imageio
:param file_name: absolute path to the file
:param data: data to save
:return: file data, or IOError if it cannot be saved by either numpy or or pickle imagei... |
Save data file of given path, use numpy.load if it is in .npy format,
otherwise use pickle or imageio
:param file_name: absolute path to the file
:param data: data to save
:return: file data, or IOError if it cannot be saved by either numpy or or pickle imageio
| Save data file of given path, use numpy.load if it is in .npy format,
otherwise use pickle or imageio | [
"Save",
"data",
"file",
"of",
"given",
"path",
"use",
"numpy",
".",
"load",
"if",
"it",
"is",
"in",
".",
"npy",
"format",
"otherwise",
"use",
"pickle",
"or",
"imageio"
] | def save_file(file_name, data):
try:
if file_name[-3:] == 'npy':
np.save(file_name, data)
elif file_name[-3:] == 'pkl':
with open(file_name, 'wb') as f:
data = pickle.dump(data, f)
else:
data = imageio.imsave(file_name, data)
return... | [
"def",
"save_file",
"(",
"file_name",
",",
"data",
")",
":",
"try",
":",
"if",
"file_name",
"[",
"-",
"3",
":",
"]",
"==",
"'npy'",
":",
"np",
".",
"save",
"(",
"file_name",
",",
"data",
")",
"elif",
"file_name",
"[",
"-",
"3",
":",
"]",
"==",
... | Save data file of given path, use numpy.load if it is in .npy format,
otherwise use pickle or imageio | [
"Save",
"data",
"file",
"of",
"given",
"path",
"use",
"numpy",
".",
"load",
"if",
"it",
"is",
"in",
".",
"npy",
"format",
"otherwise",
"use",
"pickle",
"or",
"imageio"
] | [
"\"\"\"\n Save data file of given path, use numpy.load if it is in .npy format,\n otherwise use pickle or imageio\n :param file_name: absolute path to the file\n :param data: data to save\n :return: file data, or IOError if it cannot be saved by either numpy or or pickle imageio\n \"\"\"",
"# so... | [
{
"param": "file_name",
"type": null
},
{
"param": "data",
"type": null
}
] | {
"returns": [
{
"docstring": "file data, or IOError if it cannot be saved by either numpy or or pickle imageio",
"docstring_tokens": [
"file",
"data",
"or",
"IOError",
"if",
"it",
"cannot",
"be",
"saved",
"by",
"e... |
f2891e8db93e96da0a0f778b9e33473f6b6eb59c | bohaohuang/ersa | ersa_utils.py | [
"MIT"
] | Python | make_center_string | <not_specific> | def make_center_string(char, length, center_str=''):
"""
Make one line decoration string that has center_str at the center and surrounded by char
The total length of the string equals to length
:param char: character to be repeated
:param length: total length of the string
:param center_str: str... |
Make one line decoration string that has center_str at the center and surrounded by char
The total length of the string equals to length
:param char: character to be repeated
:param length: total length of the string
:param center_str: string that shown at the center
:return:
| Make one line decoration string that has center_str at the center and surrounded by char
The total length of the string equals to length | [
"Make",
"one",
"line",
"decoration",
"string",
"that",
"has",
"center_str",
"at",
"the",
"center",
"and",
"surrounded",
"by",
"char",
"The",
"total",
"length",
"of",
"the",
"string",
"equals",
"to",
"length"
] | def make_center_string(char, length, center_str=''):
return center_str.center(length, char) | [
"def",
"make_center_string",
"(",
"char",
",",
"length",
",",
"center_str",
"=",
"''",
")",
":",
"return",
"center_str",
".",
"center",
"(",
"length",
",",
"char",
")"
] | Make one line decoration string that has center_str at the center and surrounded by char
The total length of the string equals to length | [
"Make",
"one",
"line",
"decoration",
"string",
"that",
"has",
"center_str",
"at",
"the",
"center",
"and",
"surrounded",
"by",
"char",
"The",
"total",
"length",
"of",
"the",
"string",
"equals",
"to",
"length"
] | [
"\"\"\"\n Make one line decoration string that has center_str at the center and surrounded by char\n The total length of the string equals to length\n :param char: character to be repeated\n :param length: total length of the string\n :param center_str: string that shown at the center\n :return:\n... | [
{
"param": "char",
"type": null
},
{
"param": "length",
"type": null
},
{
"param": "center_str",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "char",
"type": null,
"docstring": "character to be repeated",
"docstring_tokens": [
"character",
"t... |
f2891e8db93e96da0a0f778b9e33473f6b6eb59c | bohaohuang/ersa | ersa_utils.py | [
"MIT"
] | Python | float2str | <not_specific> | def float2str(f):
"""
Return a string for float number and change '.' to character 'p'
:param f: float number
:return: changed string
"""
return '{}'.format(f).replace('.', 'p') |
Return a string for float number and change '.' to character 'p'
:param f: float number
:return: changed string
| Return a string for float number and change '.' to character 'p' | [
"Return",
"a",
"string",
"for",
"float",
"number",
"and",
"change",
"'",
".",
"'",
"to",
"character",
"'",
"p",
"'"
] | def float2str(f):
return '{}'.format(f).replace('.', 'p') | [
"def",
"float2str",
"(",
"f",
")",
":",
"return",
"'{}'",
".",
"format",
"(",
"f",
")",
".",
"replace",
"(",
"'.'",
",",
"'p'",
")"
] | Return a string for float number and change '.' | [
"Return",
"a",
"string",
"for",
"float",
"number",
"and",
"change",
"'",
".",
"'"
] | [
"\"\"\"\n Return a string for float number and change '.' to character 'p'\n :param f: float number\n :return: changed string\n \"\"\""
] | [
{
"param": "f",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "f",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
"is... |
f2891e8db93e96da0a0f778b9e33473f6b6eb59c | bohaohuang/ersa | ersa_utils.py | [
"MIT"
] | Python | read_tensorboard_csv | <not_specific> | def read_tensorboard_csv(file, window_size=11, order=2):
"""
Read a csv file saved by tensorboard, do savitzky smoothing
:param file: full path to the csv file
:param window_size: window size of savitzky
:param order: order of savitzky
:return: step and value
"""
fields = ['Step', 'Value... |
Read a csv file saved by tensorboard, do savitzky smoothing
:param file: full path to the csv file
:param window_size: window size of savitzky
:param order: order of savitzky
:return: step and value
| Read a csv file saved by tensorboard, do savitzky smoothing | [
"Read",
"a",
"csv",
"file",
"saved",
"by",
"tensorboard",
"do",
"savitzky",
"smoothing"
] | def read_tensorboard_csv(file, window_size=11, order=2):
fields = ['Step', 'Value']
df = pd.read_csv(file, skipinitialspace=True, usecols=fields)
value = savitzky_golay(np.array(df['Value']), window_size, order)
step = np.array(df['Step'])
return step, value | [
"def",
"read_tensorboard_csv",
"(",
"file",
",",
"window_size",
"=",
"11",
",",
"order",
"=",
"2",
")",
":",
"fields",
"=",
"[",
"'Step'",
",",
"'Value'",
"]",
"df",
"=",
"pd",
".",
"read_csv",
"(",
"file",
",",
"skipinitialspace",
"=",
"True",
",",
... | Read a csv file saved by tensorboard, do savitzky smoothing | [
"Read",
"a",
"csv",
"file",
"saved",
"by",
"tensorboard",
"do",
"savitzky",
"smoothing"
] | [
"\"\"\"\n Read a csv file saved by tensorboard, do savitzky smoothing\n :param file: full path to the csv file\n :param window_size: window size of savitzky\n :param order: order of savitzky\n :return: step and value\n \"\"\""
] | [
{
"param": "file",
"type": null
},
{
"param": "window_size",
"type": null
},
{
"param": "order",
"type": null
}
] | {
"returns": [
{
"docstring": "step and value",
"docstring_tokens": [
"step",
"and",
"value"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "file",
"type": null,
"docstring": "full path to the csv file",
"docstri... |
b020c9db9985e7d30b6a1a2d959bba344d284113 | bohaohuang/ersa | nn/deeplab.py | [
"MIT"
] | Python | load_resnet | null | def load_resnet(self, resnet_dir):
"""
Load the resnet101 model pretrained on ImageNet
:param resnet_dir: path to the pretrained model
:return:
"""
with tf.Session(config=self.config) as sess:
# init model
init = [tf.global_variables_initializer(),... |
Load the resnet101 model pretrained on ImageNet
:param resnet_dir: path to the pretrained model
:return:
| Load the resnet101 model pretrained on ImageNet | [
"Load",
"the",
"resnet101",
"model",
"pretrained",
"on",
"ImageNet"
] | def load_resnet(self, resnet_dir):
with tf.Session(config=self.config) as sess:
init = [tf.global_variables_initializer(), tf.local_variables_initializer()]
sess.run(init)
restore_var = [v for v in tf.global_variables() if 'resnet_v1' in v.name and not 'Adam' in v.name]
... | [
"def",
"load_resnet",
"(",
"self",
",",
"resnet_dir",
")",
":",
"with",
"tf",
".",
"Session",
"(",
"config",
"=",
"self",
".",
"config",
")",
"as",
"sess",
":",
"init",
"=",
"[",
"tf",
".",
"global_variables_initializer",
"(",
")",
",",
"tf",
".",
"l... | Load the resnet101 model pretrained on ImageNet | [
"Load",
"the",
"resnet101",
"model",
"pretrained",
"on",
"ImageNet"
] | [
"\"\"\"\n Load the resnet101 model pretrained on ImageNet\n :param resnet_dir: path to the pretrained model\n :return:\n \"\"\"",
"# init model",
"# load model"
] | [
{
"param": "self",
"type": null
},
{
"param": "resnet_dir",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
... |
b020c9db9985e7d30b6a1a2d959bba344d284113 | bohaohuang/ersa | nn/deeplab.py | [
"MIT"
] | Python | _conv2d | <not_specific> | def _conv2d(self, x, kernel_size, num_o, stride, name, biased=False):
"""
Conv2d without BN or relu.
"""
num_x = x.shape[self.channel_axis].value
with tf.variable_scope(name):
w = tf.get_variable('weights', shape=[kernel_size, kernel_size, num_x, num_o])
s... |
Conv2d without BN or relu.
| Conv2d without BN or relu. | [
"Conv2d",
"without",
"BN",
"or",
"relu",
"."
] | def _conv2d(self, x, kernel_size, num_o, stride, name, biased=False):
num_x = x.shape[self.channel_axis].value
with tf.variable_scope(name):
w = tf.get_variable('weights', shape=[kernel_size, kernel_size, num_x, num_o])
s = [1, stride, stride, 1]
o = tf.nn.conv2d(x, w... | [
"def",
"_conv2d",
"(",
"self",
",",
"x",
",",
"kernel_size",
",",
"num_o",
",",
"stride",
",",
"name",
",",
"biased",
"=",
"False",
")",
":",
"num_x",
"=",
"x",
".",
"shape",
"[",
"self",
".",
"channel_axis",
"]",
".",
"value",
"with",
"tf",
".",
... | Conv2d without BN or relu. | [
"Conv2d",
"without",
"BN",
"or",
"relu",
"."
] | [
"\"\"\"\n Conv2d without BN or relu.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "kernel_size",
"type": null
},
{
"param": "num_o",
"type": null
},
{
"param": "stride",
"type": null
},
{
"param": "name",
"type": null
},
{
"param": "biased",
... | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
b020c9db9985e7d30b6a1a2d959bba344d284113 | bohaohuang/ersa | nn/deeplab.py | [
"MIT"
] | Python | _dilated_conv2d | <not_specific> | def _dilated_conv2d(self, x, kernel_size, num_o, dilation_factor, name, biased=False):
"""
Dilated conv2d without BN or relu.
"""
num_x = x.shape[self.channel_axis].value
with tf.variable_scope(name):
w = tf.get_variable('weights', shape=[kernel_size, kernel_size, num... |
Dilated conv2d without BN or relu.
| Dilated conv2d without BN or relu. | [
"Dilated",
"conv2d",
"without",
"BN",
"or",
"relu",
"."
] | def _dilated_conv2d(self, x, kernel_size, num_o, dilation_factor, name, biased=False):
num_x = x.shape[self.channel_axis].value
with tf.variable_scope(name):
w = tf.get_variable('weights', shape=[kernel_size, kernel_size, num_x, num_o])
o = tf.nn.atrous_conv2d(x, w, dilation_fact... | [
"def",
"_dilated_conv2d",
"(",
"self",
",",
"x",
",",
"kernel_size",
",",
"num_o",
",",
"dilation_factor",
",",
"name",
",",
"biased",
"=",
"False",
")",
":",
"num_x",
"=",
"x",
".",
"shape",
"[",
"self",
".",
"channel_axis",
"]",
".",
"value",
"with",... | Dilated conv2d without BN or relu. | [
"Dilated",
"conv2d",
"without",
"BN",
"or",
"relu",
"."
] | [
"\"\"\"\n Dilated conv2d without BN or relu.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "x",
"type": null
},
{
"param": "kernel_size",
"type": null
},
{
"param": "num_o",
"type": null
},
{
"param": "dilation_factor",
"type": null
},
{
"param": "name",
"type": null
},
{
"param": "bi... | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": null,
"docstring": null,
"docstring_tokens": [],
... |
3d56b1ce0b982af7e6b2409dbdd4215956836d27 | bohaohuang/ersa | nn/unet.py | [
"MIT"
] | Python | create_graph | null | def create_graph(self, feature, **kwargs):
"""
Create graph for the U-Net
:param feature: input image
:param start_filter_num: #filters at the start layer, #filters in U-Net grows exponentially
:return:
"""
sfn = self.sfn
# downsample
conv1, pool1... |
Create graph for the U-Net
:param feature: input image
:param start_filter_num: #filters at the start layer, #filters in U-Net grows exponentially
:return:
| Create graph for the U-Net | [
"Create",
"graph",
"for",
"the",
"U",
"-",
"Net"
] | def create_graph(self, feature, **kwargs):
sfn = self.sfn
conv1, pool1 = nn_utils.conv_conv_pool(feature, [sfn, sfn], self.mode, name='conv1',
padding='valid', dropout=self.dropout_rate)
conv2, pool2 = nn_utils.conv_conv_pool(pool1, [sfn * 2, sfn * ... | [
"def",
"create_graph",
"(",
"self",
",",
"feature",
",",
"**",
"kwargs",
")",
":",
"sfn",
"=",
"self",
".",
"sfn",
"conv1",
",",
"pool1",
"=",
"nn_utils",
".",
"conv_conv_pool",
"(",
"feature",
",",
"[",
"sfn",
",",
"sfn",
"]",
",",
"self",
".",
"m... | Create graph for the U-Net | [
"Create",
"graph",
"for",
"the",
"U",
"-",
"Net"
] | [
"\"\"\"\n Create graph for the U-Net\n :param feature: input image\n :param start_filter_num: #filters at the start layer, #filters in U-Net grows exponentially\n :return:\n \"\"\"",
"# downsample",
"# upsample"
] | [
{
"param": "self",
"type": null
},
{
"param": "feature",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
... |
3d56b1ce0b982af7e6b2409dbdd4215956836d27 | bohaohuang/ersa | nn/unet.py | [
"MIT"
] | Python | is_valid_patch_size | <not_specific> | def is_valid_patch_size(ps):
"""
Due to the existence of cropping and pooling, U-Net cannot take arbitrary input size
This function determines if a input size is a valid input size, other wise return closest valid size
:param ps: input patch size, should be a tuple
:return: True ... |
Due to the existence of cropping and pooling, U-Net cannot take arbitrary input size
This function determines if a input size is a valid input size, other wise return closest valid size
:param ps: input patch size, should be a tuple
:return: True if ps is valid, otherwise the closest va... | Due to the existence of cropping and pooling, U-Net cannot take arbitrary input size
This function determines if a input size is a valid input size, other wise return closest valid size | [
"Due",
"to",
"the",
"existence",
"of",
"cropping",
"and",
"pooling",
"U",
"-",
"Net",
"cannot",
"take",
"arbitrary",
"input",
"size",
"This",
"function",
"determines",
"if",
"a",
"input",
"size",
"is",
"a",
"valid",
"input",
"size",
"other",
"wise",
"retur... | def is_valid_patch_size(ps):
if (ps[0] - 124) % 32 == 0 and (ps[1] - 124) % 32 == 0:
return True
else:
ps_0 = (ps[0] - 124) // 32 + 124
ps_1 = (ps[1] - 124) // 32 + 124
return tuple([ps_0, ps_1]) | [
"def",
"is_valid_patch_size",
"(",
"ps",
")",
":",
"if",
"(",
"ps",
"[",
"0",
"]",
"-",
"124",
")",
"%",
"32",
"==",
"0",
"and",
"(",
"ps",
"[",
"1",
"]",
"-",
"124",
")",
"%",
"32",
"==",
"0",
":",
"return",
"True",
"else",
":",
"ps_0",
"=... | Due to the existence of cropping and pooling, U-Net cannot take arbitrary input size
This function determines if a input size is a valid input size, other wise return closest valid size | [
"Due",
"to",
"the",
"existence",
"of",
"cropping",
"and",
"pooling",
"U",
"-",
"Net",
"cannot",
"take",
"arbitrary",
"input",
"size",
"This",
"function",
"determines",
"if",
"a",
"input",
"size",
"is",
"a",
"valid",
"input",
"size",
"other",
"wise",
"retur... | [
"\"\"\"\n Due to the existence of cropping and pooling, U-Net cannot take arbitrary input size\n This function determines if a input size is a valid input size, other wise return closest valid size\n :param ps: input patch size, should be a tuple\n :return: True if ps is valid, otherwise... | [
{
"param": "ps",
"type": null
}
] | {
"returns": [
{
"docstring": "True if ps is valid, otherwise the closest valid input size",
"docstring_tokens": [
"True",
"if",
"ps",
"is",
"valid",
"otherwise",
"the",
"closest",
"valid",
"input",
"size"
],... |
3d56b1ce0b982af7e6b2409dbdd4215956836d27 | bohaohuang/ersa | nn/unet.py | [
"MIT"
] | Python | load_weights | null | def load_weights(ckpt_dir, layers2load):
"""
This is different from network.load(). This function only loads specified layers
:param ckpt_dir: path to the model to load
:param layers2load: could be a list, or string where numbers separated by ,
:return:
"""
layers... |
This is different from network.load(). This function only loads specified layers
:param ckpt_dir: path to the model to load
:param layers2load: could be a list, or string where numbers separated by ,
:return:
| This is different from network.load(). This function only loads specified layers | [
"This",
"is",
"different",
"from",
"network",
".",
"load",
"()",
".",
"This",
"function",
"only",
"loads",
"specified",
"layers"
] | def load_weights(ckpt_dir, layers2load):
layers_list = []
if isinstance(layers2load, str):
layers2load = [int(a) for a in layers2load.split(',')]
for layer_id in layers2load:
assert 1 <= layer_id <= 9
if layer_id <= 5:
prefix = 'layerconv'
... | [
"def",
"load_weights",
"(",
"ckpt_dir",
",",
"layers2load",
")",
":",
"layers_list",
"=",
"[",
"]",
"if",
"isinstance",
"(",
"layers2load",
",",
"str",
")",
":",
"layers2load",
"=",
"[",
"int",
"(",
"a",
")",
"for",
"a",
"in",
"layers2load",
".",
"spli... | This is different from network.load(). | [
"This",
"is",
"different",
"from",
"network",
".",
"load",
"()",
"."
] | [
"\"\"\"\n This is different from network.load(). This function only loads specified layers\n :param ckpt_dir: path to the model to load\n :param layers2load: could be a list, or string where numbers separated by ,\n :return:\n \"\"\""
] | [
{
"param": "ckpt_dir",
"type": null
},
{
"param": "layers2load",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "ckpt_dir",
"type": null,
"docstring": "path to the model to load",
"docstring_tokens": [
"path",
"t... |
3d56b1ce0b982af7e6b2409dbdd4215956836d27 | bohaohuang/ersa | nn/unet.py | [
"MIT"
] | Python | make_loss | null | def make_loss(self, label, loss_type='xent', **kwargs):
"""
Make loss to optimize for the network
U-Net's output is smaller than input, thus ground truth need to be cropped
:param label: input labels, can be generated by tf.data.Dataset
:param loss_type:
xent: cross e... |
Make loss to optimize for the network
U-Net's output is smaller than input, thus ground truth need to be cropped
:param label: input labels, can be generated by tf.data.Dataset
:param loss_type:
xent: cross entropy loss
:return:
| Make loss to optimize for the network
U-Net's output is smaller than input, thus ground truth need to be cropped | [
"Make",
"loss",
"to",
"optimize",
"for",
"the",
"network",
"U",
"-",
"Net",
"'",
"s",
"output",
"is",
"smaller",
"than",
"input",
"thus",
"ground",
"truth",
"need",
"to",
"be",
"cropped"
] | def make_loss(self, label, loss_type='xent', **kwargs):
with tf.variable_scope('loss'):
pred_flat = tf.reshape(self.pred, [-1, self.class_num])
_, w, h, _ = label.get_shape().as_list()
y = tf.image.resize_image_with_crop_or_pad(label, w - self.get_overlap(), h - self.get_over... | [
"def",
"make_loss",
"(",
"self",
",",
"label",
",",
"loss_type",
"=",
"'xent'",
",",
"**",
"kwargs",
")",
":",
"with",
"tf",
".",
"variable_scope",
"(",
"'loss'",
")",
":",
"pred_flat",
"=",
"tf",
".",
"reshape",
"(",
"self",
".",
"pred",
",",
"[",
... | Make loss to optimize for the network
U-Net's output is smaller than input, thus ground truth need to be cropped | [
"Make",
"loss",
"to",
"optimize",
"for",
"the",
"network",
"U",
"-",
"Net",
"'",
"s",
"output",
"is",
"smaller",
"than",
"input",
"thus",
"ground",
"truth",
"need",
"to",
"be",
"cropped"
] | [
"\"\"\"\n Make loss to optimize for the network\n U-Net's output is smaller than input, thus ground truth need to be cropped\n :param label: input labels, can be generated by tf.data.Dataset\n :param loss_type:\n xent: cross entropy loss\n :return:\n \"\"\"",
"... | [
{
"param": "self",
"type": null
},
{
"param": "label",
"type": null
},
{
"param": "loss_type",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
... |
64db48ee74222e191f2d01e42466a59605a770bd | bohaohuang/ersa | visualize/visualize_utils.py | [
"MIT"
] | Python | compare_two_figure | null | def compare_two_figure(img_1, img_2, show_axis=False, fig_size=(12, 6), show_fig=True, color_bar=False):
"""
Show two figures in a row, link their axes
:param img_1: image to show on the left
:param img_2: image to show on the right
:param show_axis: if False, axes will be hide
:param fig_size: ... |
Show two figures in a row, link their axes
:param img_1: image to show on the left
:param img_2: image to show on the right
:param show_axis: if False, axes will be hide
:param fig_size: size of the figure
:param show_fig: show figure or not
:param color_bar: if True, add color bar to the l... | Show two figures in a row, link their axes | [
"Show",
"two",
"figures",
"in",
"a",
"row",
"link",
"their",
"axes"
] | def compare_two_figure(img_1, img_2, show_axis=False, fig_size=(12, 6), show_fig=True, color_bar=False):
plt.figure(figsize=fig_size)
ax1 = plt.subplot(121)
plt.imshow(img_1)
if not show_axis:
plt.axis('off')
if color_bar:
plt.colorbar()
plt.subplot(122, sharex=ax1, sharey=ax1)
... | [
"def",
"compare_two_figure",
"(",
"img_1",
",",
"img_2",
",",
"show_axis",
"=",
"False",
",",
"fig_size",
"=",
"(",
"12",
",",
"6",
")",
",",
"show_fig",
"=",
"True",
",",
"color_bar",
"=",
"False",
")",
":",
"plt",
".",
"figure",
"(",
"figsize",
"="... | Show two figures in a row, link their axes | [
"Show",
"two",
"figures",
"in",
"a",
"row",
"link",
"their",
"axes"
] | [
"\"\"\"\n Show two figures in a row, link their axes\n :param img_1: image to show on the left\n :param img_2: image to show on the right\n :param show_axis: if False, axes will be hide\n :param fig_size: size of the figure\n :param show_fig: show figure or not\n :param color_bar: if True, add ... | [
{
"param": "img_1",
"type": null
},
{
"param": "img_2",
"type": null
},
{
"param": "show_axis",
"type": null
},
{
"param": "fig_size",
"type": null
},
{
"param": "show_fig",
"type": null
},
{
"param": "color_bar",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "img_1",
"type": null,
"docstring": "image to show on the left",
"docstring_tokens": [
"image",
"to"... |
64db48ee74222e191f2d01e42466a59605a770bd | bohaohuang/ersa | visualize/visualize_utils.py | [
"MIT"
] | Python | compare_three_figure | null | def compare_three_figure(img_1, img_2, img_3, show_axis=False, fig_size=(12, 6), show_fig=True, color_bar=False):
"""
Show three figures in a row, link their axes
:param img_1: image to show on the left
:param img_2: image to show at the center
:param img_3: image to show on the right
:param sho... |
Show three figures in a row, link their axes
:param img_1: image to show on the left
:param img_2: image to show at the center
:param img_3: image to show on the right
:param show_axis: if False, axes will be hide
:param fig_size: size of the figure
:param show_fig: show figure or not
:... | Show three figures in a row, link their axes | [
"Show",
"three",
"figures",
"in",
"a",
"row",
"link",
"their",
"axes"
] | def compare_three_figure(img_1, img_2, img_3, show_axis=False, fig_size=(12, 6), show_fig=True, color_bar=False):
plt.figure(figsize=fig_size)
ax1 = plt.subplot(131)
plt.imshow(img_1)
if not show_axis:
plt.axis('off')
plt.subplot(132, sharex=ax1, sharey=ax1)
plt.imshow(img_2)
if not ... | [
"def",
"compare_three_figure",
"(",
"img_1",
",",
"img_2",
",",
"img_3",
",",
"show_axis",
"=",
"False",
",",
"fig_size",
"=",
"(",
"12",
",",
"6",
")",
",",
"show_fig",
"=",
"True",
",",
"color_bar",
"=",
"False",
")",
":",
"plt",
".",
"figure",
"("... | Show three figures in a row, link their axes | [
"Show",
"three",
"figures",
"in",
"a",
"row",
"link",
"their",
"axes"
] | [
"\"\"\"\n Show three figures in a row, link their axes\n :param img_1: image to show on the left\n :param img_2: image to show at the center\n :param img_3: image to show on the right\n :param show_axis: if False, axes will be hide\n :param fig_size: size of the figure\n :param show_fig: show f... | [
{
"param": "img_1",
"type": null
},
{
"param": "img_2",
"type": null
},
{
"param": "img_3",
"type": null
},
{
"param": "show_axis",
"type": null
},
{
"param": "fig_size",
"type": null
},
{
"param": "show_fig",
"type": null
},
{
"param": "co... | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "img_1",
"type": null,
"docstring": "image to show on the left",
"docstring_tokens": [
"image",
"to"... |
8df95f9a6b807c1c55d02f4aa38171148769f54f | bohaohuang/ersa | reader/reader_utils.py | [
"MIT"
] | Python | image_rotating | <not_specific> | def image_rotating(img):
"""
randomly rotate images by 0/90/180/270 degrees
:param img: input image
:return:rotated images
"""
rot_time = np.random.randint(low=0, high=4)
img = np.rot90(img, rot_time, (0, 1))
return img |
randomly rotate images by 0/90/180/270 degrees
:param img: input image
:return:rotated images
| randomly rotate images by 0/90/180/270 degrees | [
"randomly",
"rotate",
"images",
"by",
"0",
"/",
"90",
"/",
"180",
"/",
"270",
"degrees"
] | def image_rotating(img):
rot_time = np.random.randint(low=0, high=4)
img = np.rot90(img, rot_time, (0, 1))
return img | [
"def",
"image_rotating",
"(",
"img",
")",
":",
"rot_time",
"=",
"np",
".",
"random",
".",
"randint",
"(",
"low",
"=",
"0",
",",
"high",
"=",
"4",
")",
"img",
"=",
"np",
".",
"rot90",
"(",
"img",
",",
"rot_time",
",",
"(",
"0",
",",
"1",
")",
... | randomly rotate images by 0/90/180/270 degrees | [
"randomly",
"rotate",
"images",
"by",
"0",
"/",
"90",
"/",
"180",
"/",
"270",
"degrees"
] | [
"\"\"\"\n randomly rotate images by 0/90/180/270 degrees\n :param img: input image\n :return:rotated images\n \"\"\""
] | [
{
"param": "img",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "img",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
"... |
8df95f9a6b807c1c55d02f4aa38171148769f54f | bohaohuang/ersa | reader/reader_utils.py | [
"MIT"
] | Python | image_flipping | <not_specific> | def image_flipping(img):
"""
randomly flips images left-right and up-down
:param img: input image
:return:flipped images
"""
img = image_flipping_hori(img)
img = image_flipping_vert(img)
return img |
randomly flips images left-right and up-down
:param img: input image
:return:flipped images
| randomly flips images left-right and up-down | [
"randomly",
"flips",
"images",
"left",
"-",
"right",
"and",
"up",
"-",
"down"
] | def image_flipping(img):
img = image_flipping_hori(img)
img = image_flipping_vert(img)
return img | [
"def",
"image_flipping",
"(",
"img",
")",
":",
"img",
"=",
"image_flipping_hori",
"(",
"img",
")",
"img",
"=",
"image_flipping_vert",
"(",
"img",
")",
"return",
"img"
] | randomly flips images left-right and up-down | [
"randomly",
"flips",
"images",
"left",
"-",
"right",
"and",
"up",
"-",
"down"
] | [
"\"\"\"\n randomly flips images left-right and up-down\n :param img: input image\n :return:flipped images\n \"\"\""
] | [
{
"param": "img",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "img",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
"... |
8df95f9a6b807c1c55d02f4aa38171148769f54f | bohaohuang/ersa | reader/reader_utils.py | [
"MIT"
] | Python | image_flipping_hori | <not_specific> | def image_flipping_hori(img):
"""
randomly flips images left-right
:param img: input image
:return:flipped images
"""
h_flip = np.random.randint(0, 1)
if h_flip == 1:
img = img[:, ::-1, :]
return img |
randomly flips images left-right
:param img: input image
:return:flipped images
| randomly flips images left-right | [
"randomly",
"flips",
"images",
"left",
"-",
"right"
] | def image_flipping_hori(img):
h_flip = np.random.randint(0, 1)
if h_flip == 1:
img = img[:, ::-1, :]
return img | [
"def",
"image_flipping_hori",
"(",
"img",
")",
":",
"h_flip",
"=",
"np",
".",
"random",
".",
"randint",
"(",
"0",
",",
"1",
")",
"if",
"h_flip",
"==",
"1",
":",
"img",
"=",
"img",
"[",
":",
",",
":",
":",
"-",
"1",
",",
":",
"]",
"return",
"i... | randomly flips images left-right | [
"randomly",
"flips",
"images",
"left",
"-",
"right"
] | [
"\"\"\"\n randomly flips images left-right\n :param img: input image\n :return:flipped images\n \"\"\""
] | [
{
"param": "img",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "img",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
"... |
8df95f9a6b807c1c55d02f4aa38171148769f54f | bohaohuang/ersa | reader/reader_utils.py | [
"MIT"
] | Python | image_flipping_vert | <not_specific> | def image_flipping_vert(img):
"""
randomly flips images up-down
:param img: input image
:return:flipped images
"""
v_flip = np.random.randint(0, 1)
if v_flip == 1:
img = img[::-1, :, :]
return img |
randomly flips images up-down
:param img: input image
:return:flipped images
| randomly flips images up-down | [
"randomly",
"flips",
"images",
"up",
"-",
"down"
] | def image_flipping_vert(img):
v_flip = np.random.randint(0, 1)
if v_flip == 1:
img = img[::-1, :, :]
return img | [
"def",
"image_flipping_vert",
"(",
"img",
")",
":",
"v_flip",
"=",
"np",
".",
"random",
".",
"randint",
"(",
"0",
",",
"1",
")",
"if",
"v_flip",
"==",
"1",
":",
"img",
"=",
"img",
"[",
":",
":",
"-",
"1",
",",
":",
",",
":",
"]",
"return",
"i... | randomly flips images up-down | [
"randomly",
"flips",
"images",
"up",
"-",
"down"
] | [
"\"\"\"\n randomly flips images up-down\n :param img: input image\n :return:flipped images\n \"\"\""
] | [
{
"param": "img",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "img",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
"... |
8df95f9a6b807c1c55d02f4aa38171148769f54f | bohaohuang/ersa | reader/reader_utils.py | [
"MIT"
] | Python | resize_image | <not_specific> | def resize_image(img, new_size, preserve_range=False):
"""
Resize the input image, can preserve the original data range if given ground truth
:param img: the image to be resized
:param new_size: new image size
:param preserve_range: keep the original data range or not
:return:
"""
if pre... |
Resize the input image, can preserve the original data range if given ground truth
:param img: the image to be resized
:param new_size: new image size
:param preserve_range: keep the original data range or not
:return:
| Resize the input image, can preserve the original data range if given ground truth | [
"Resize",
"the",
"input",
"image",
"can",
"preserve",
"the",
"original",
"data",
"range",
"if",
"given",
"ground",
"truth"
] | def resize_image(img, new_size, preserve_range=False):
if preserve_range:
return skimage.transform.resize(img, new_size, order=0, preserve_range=True, mode='reflect')
else:
return skimage.transform.resize(img, new_size, mode='reflect') | [
"def",
"resize_image",
"(",
"img",
",",
"new_size",
",",
"preserve_range",
"=",
"False",
")",
":",
"if",
"preserve_range",
":",
"return",
"skimage",
".",
"transform",
".",
"resize",
"(",
"img",
",",
"new_size",
",",
"order",
"=",
"0",
",",
"preserve_range"... | Resize the input image, can preserve the original data range if given ground truth | [
"Resize",
"the",
"input",
"image",
"can",
"preserve",
"the",
"original",
"data",
"range",
"if",
"given",
"ground",
"truth"
] | [
"\"\"\"\n Resize the input image, can preserve the original data range if given ground truth\n :param img: the image to be resized\n :param new_size: new image size\n :param preserve_range: keep the original data range or not\n :return:\n \"\"\""
] | [
{
"param": "img",
"type": null
},
{
"param": "new_size",
"type": null
},
{
"param": "preserve_range",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "img",
"type": null,
"docstring": "the image to be resized",
"docstring_tokens": [
"the",
"image",
... |
8df95f9a6b807c1c55d02f4aa38171148769f54f | bohaohuang/ersa | reader/reader_utils.py | [
"MIT"
] | Python | image_scaling_with_label | <not_specific> | def image_scaling_with_label(img):
"""
Random scale images, assume the last channel is the label
Resize the rgb part with bilinear interpolation, the label part with nearest neighbor
:param img: image data cube, the last channel is the label
:param rescale: if True, the image and label will be resca... |
Random scale images, assume the last channel is the label
Resize the rgb part with bilinear interpolation, the label part with nearest neighbor
:param img: image data cube, the last channel is the label
:param rescale: if True, the image and label will be rescaled to the original shape
:return: res... | Random scale images, assume the last channel is the label
Resize the rgb part with bilinear interpolation, the label part with nearest neighbor | [
"Random",
"scale",
"images",
"assume",
"the",
"last",
"channel",
"is",
"the",
"label",
"Resize",
"the",
"rgb",
"part",
"with",
"bilinear",
"interpolation",
"the",
"label",
"part",
"with",
"nearest",
"neighbor"
] | def image_scaling_with_label(img):
ftr = img[:, :, :-1]
lbl = img[:, :, -1]
scale = np.random.uniform(low=0.5, high=2.0)
h, w = ftr.shape[:2]
h_new = int(h * scale)
w_new = int(w * scale)
ftr = resize_image(ftr, (h_new, w_new))
lbl = np.expand_dims(resize_image(lbl, (h_new, w_new), prese... | [
"def",
"image_scaling_with_label",
"(",
"img",
")",
":",
"ftr",
"=",
"img",
"[",
":",
",",
":",
",",
":",
"-",
"1",
"]",
"lbl",
"=",
"img",
"[",
":",
",",
":",
",",
"-",
"1",
"]",
"scale",
"=",
"np",
".",
"random",
".",
"uniform",
"(",
"low",... | Random scale images, assume the last channel is the label
Resize the rgb part with bilinear interpolation, the label part with nearest neighbor | [
"Random",
"scale",
"images",
"assume",
"the",
"last",
"channel",
"is",
"the",
"label",
"Resize",
"the",
"rgb",
"part",
"with",
"bilinear",
"interpolation",
"the",
"label",
"part",
"with",
"nearest",
"neighbor"
] | [
"\"\"\"\n Random scale images, assume the last channel is the label\n Resize the rgb part with bilinear interpolation, the label part with nearest neighbor\n :param img: image data cube, the last channel is the label\n :param rescale: if True, the image and label will be rescaled to the original shape\n... | [
{
"param": "img",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "img",
"type": null,
"docstring": "image data cube, the last channel is the label",
"docstring_tokens": [
"i... |
8df95f9a6b807c1c55d02f4aa38171148769f54f | bohaohuang/ersa | reader/reader_utils.py | [
"MIT"
] | Python | random_crop | <not_specific> | def random_crop(img, h_target, w_target):
"""
Random crop the image to the target size
:param img: image to be cropped
:param h_target: target height
:param w_target: target width
:return: random cropped image
"""
h, w, _ = img.shape
h_range = h - h_target
w_range = w - w_target
... |
Random crop the image to the target size
:param img: image to be cropped
:param h_target: target height
:param w_target: target width
:return: random cropped image
| Random crop the image to the target size | [
"Random",
"crop",
"the",
"image",
"to",
"the",
"target",
"size"
] | def random_crop(img, h_target, w_target):
h, w, _ = img.shape
h_range = h - h_target
w_range = w - w_target
if h_range == 0:
h_start = 0
else:
h_start = np.random.randint(0, h_range)
if w_range == 0:
w_start = 0
else:
w_start = np.random.randint(0, w_range)
... | [
"def",
"random_crop",
"(",
"img",
",",
"h_target",
",",
"w_target",
")",
":",
"h",
",",
"w",
",",
"_",
"=",
"img",
".",
"shape",
"h_range",
"=",
"h",
"-",
"h_target",
"w_range",
"=",
"w",
"-",
"w_target",
"if",
"h_range",
"==",
"0",
":",
"h_start",... | Random crop the image to the target size | [
"Random",
"crop",
"the",
"image",
"to",
"the",
"target",
"size"
] | [
"\"\"\"\n Random crop the image to the target size\n :param img: image to be cropped\n :param h_target: target height\n :param w_target: target width\n :return: random cropped image\n \"\"\""
] | [
{
"param": "img",
"type": null
},
{
"param": "h_target",
"type": null
},
{
"param": "w_target",
"type": null
}
] | {
"returns": [
{
"docstring": "random cropped image",
"docstring_tokens": [
"random",
"cropped",
"image"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "img",
"type": null,
"docstring": "image to be cropped",
"do... |
8df95f9a6b807c1c55d02f4aa38171148769f54f | bohaohuang/ersa | reader/reader_utils.py | [
"MIT"
] | Python | random_pad_crop_image_with_label | <not_specific> | def random_pad_crop_image_with_label(img, size, ignore_label=255):
"""
Random pad or crop the image to the desired shape
:param img: the data cube, assume the label is at the last dimension
:param size: desired size of the image
:param ignore_label: label to be ignored
:return: image with the de... |
Random pad or crop the image to the desired shape
:param img: the data cube, assume the label is at the last dimension
:param size: desired size of the image
:param ignore_label: label to be ignored
:return: image with the desired shape
| Random pad or crop the image to the desired shape | [
"Random",
"pad",
"or",
"crop",
"the",
"image",
"to",
"the",
"desired",
"shape"
] | def random_pad_crop_image_with_label(img, size, ignore_label=255):
img[:, :, -1] -= ignore_label
h, w, _ = img.shape
pad_h0, pad_h1, pad_w0, pad_w1 = 0, 0, 0, 0
if size[0] > h:
diff = size[0] - h
if diff % 2 == 0:
pad_h0, pad_h1 = diff // 2, diff // 2
else:
... | [
"def",
"random_pad_crop_image_with_label",
"(",
"img",
",",
"size",
",",
"ignore_label",
"=",
"255",
")",
":",
"img",
"[",
":",
",",
":",
",",
"-",
"1",
"]",
"-=",
"ignore_label",
"h",
",",
"w",
",",
"_",
"=",
"img",
".",
"shape",
"pad_h0",
",",
"p... | Random pad or crop the image to the desired shape | [
"Random",
"pad",
"or",
"crop",
"the",
"image",
"to",
"the",
"desired",
"shape"
] | [
"\"\"\"\n Random pad or crop the image to the desired shape\n :param img: the data cube, assume the label is at the last dimension\n :param size: desired size of the image\n :param ignore_label: label to be ignored\n :return: image with the desired shape\n \"\"\"",
"# padded zeros will eventuall... | [
{
"param": "img",
"type": null
},
{
"param": "size",
"type": null
},
{
"param": "ignore_label",
"type": null
}
] | {
"returns": [
{
"docstring": "image with the desired shape",
"docstring_tokens": [
"image",
"with",
"the",
"desired",
"shape"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "img",
"type": null,
"docstr... |
503c463c8cf18e8109260684fa65659523770a97 | bohaohuang/ersa | nn/pspnet.py | [
"MIT"
] | Python | make_loss | null | def make_loss(self, label, loss_type='xent'):
"""
Make loss to optimize for the network
:param label: input labels, can be generated by tf.data.Dataset
:param loss_type:
xent: cross entropy loss
:return:
"""
with tf.variable_scope('loss'):
... |
Make loss to optimize for the network
:param label: input labels, can be generated by tf.data.Dataset
:param loss_type:
xent: cross entropy loss
:return:
| Make loss to optimize for the network | [
"Make",
"loss",
"to",
"optimize",
"for",
"the",
"network"
] | def make_loss(self, label, loss_type='xent'):
with tf.variable_scope('loss'):
pred_flat = tf.reshape(self.pred, [-1, self.class_num])
label = tf.image.resize_nearest_neighbor(label, tf.stack(self.pred.get_shape()[1:3]))
y_flat = tf.reshape(tf.squeeze(label, axis=[3]), [-1, ])... | [
"def",
"make_loss",
"(",
"self",
",",
"label",
",",
"loss_type",
"=",
"'xent'",
")",
":",
"with",
"tf",
".",
"variable_scope",
"(",
"'loss'",
")",
":",
"pred_flat",
"=",
"tf",
".",
"reshape",
"(",
"self",
".",
"pred",
",",
"[",
"-",
"1",
",",
"self... | Make loss to optimize for the network | [
"Make",
"loss",
"to",
"optimize",
"for",
"the",
"network"
] | [
"\"\"\"\n Make loss to optimize for the network\n :param label: input labels, can be generated by tf.data.Dataset\n :param loss_type:\n xent: cross entropy loss\n :return:\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "label",
"type": null
},
{
"param": "loss_type",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
... |
503c463c8cf18e8109260684fa65659523770a97 | bohaohuang/ersa | nn/pspnet.py | [
"MIT"
] | Python | make_optimizer | null | def make_optimizer(self, train_var_filter):
"""
Make optimizer fot the network, Adam is used
:param train_var_filter: if not None, only optimize variables in train_var_filter
:return:
"""
# According from the prototxt in Caffe implement, learning rate must multiply by 10.... |
Make optimizer fot the network, Adam is used
:param train_var_filter: if not None, only optimize variables in train_var_filter
:return:
| Make optimizer fot the network, Adam is used | [
"Make",
"optimizer",
"fot",
"the",
"network",
"Adam",
"is",
"used"
] | def make_optimizer(self, train_var_filter):
fc_list = ['conv5_3_pool1_conv', 'conv5_3_pool2_conv', 'conv5_3_pool3_conv', 'conv5_3_pool6_conv', 'conv6',
'conv5_4']
all_trainable = [v for v in tf.trainable_variables() if
('beta' not in v.name and 'gamma' not in ... | [
"def",
"make_optimizer",
"(",
"self",
",",
"train_var_filter",
")",
":",
"fc_list",
"=",
"[",
"'conv5_3_pool1_conv'",
",",
"'conv5_3_pool2_conv'",
",",
"'conv5_3_pool3_conv'",
",",
"'conv5_3_pool6_conv'",
",",
"'conv6'",
",",
"'conv5_4'",
"]",
"all_trainable",
"=",
... | Make optimizer fot the network, Adam is used | [
"Make",
"optimizer",
"fot",
"the",
"network",
"Adam",
"is",
"used"
] | [
"\"\"\"\n Make optimizer fot the network, Adam is used\n :param train_var_filter: if not None, only optimize variables in train_var_filter\n :return:\n \"\"\"",
"# According from the prototxt in Caffe implement, learning rate must multiply by 10.0 in pyramid module",
"# lr * 1.0",
... | [
{
"param": "self",
"type": null
},
{
"param": "train_var_filter",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
... |
503c463c8cf18e8109260684fa65659523770a97 | bohaohuang/ersa | nn/pspnet.py | [
"MIT"
] | Python | load_resnet | null | def load_resnet(self, resnet_dir, keep_last=False):
"""
Load the resnet101 model pretrained on ImageNet
:param resnet_dir: path to the pretrained model
:param keep_last: if keep last classification layer or not
:return:
"""
ckpt = tf.train.latest_checkpoint(resnet... |
Load the resnet101 model pretrained on ImageNet
:param resnet_dir: path to the pretrained model
:param keep_last: if keep last classification layer or not
:return:
| Load the resnet101 model pretrained on ImageNet | [
"Load",
"the",
"resnet101",
"model",
"pretrained",
"on",
"ImageNet"
] | def load_resnet(self, resnet_dir, keep_last=False):
ckpt = tf.train.latest_checkpoint(resnet_dir)
with tf.Session(config=self.config) as sess:
init = [tf.global_variables_initializer(), tf.local_variables_initializer()]
sess.run(init)
if keep_last:
res... | [
"def",
"load_resnet",
"(",
"self",
",",
"resnet_dir",
",",
"keep_last",
"=",
"False",
")",
":",
"ckpt",
"=",
"tf",
".",
"train",
".",
"latest_checkpoint",
"(",
"resnet_dir",
")",
"with",
"tf",
".",
"Session",
"(",
"config",
"=",
"self",
".",
"config",
... | Load the resnet101 model pretrained on ImageNet | [
"Load",
"the",
"resnet101",
"model",
"pretrained",
"on",
"ImageNet"
] | [
"\"\"\"\n Load the resnet101 model pretrained on ImageNet\n :param resnet_dir: path to the pretrained model\n :param keep_last: if keep last classification layer or not\n :return:\n \"\"\"",
"# init model",
"# load model"
] | [
{
"param": "self",
"type": null
},
{
"param": "resnet_dir",
"type": null
},
{
"param": "keep_last",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
... |
35673d22447611ef4fab0da1732296c4802e0136 | bohaohuang/ersa | nn/nn_utils.py | [
"MIT"
] | Python | conv_conv_pool | <not_specific> | def conv_conv_pool(input_, n_filters, training, name, kernel_size=(3, 3),
conv_stride=(1, 1), pool=True, pool_size=(2, 2), pool_stride=(2, 2),
activation=tf.nn.relu, padding='same', bn=True, dropout=False, dropout_rate=None):
"""
Do multiple convolution and one pooling, thi... |
Do multiple convolution and one pooling, this is the basic component in many CNNs
:param input_: input variable
:param n_filters: #filters in each convolutional layers, could be a list
:param training: indicates it is in training or not
:param name: name for this variable scope
:param kernel_si... | Do multiple convolution and one pooling, this is the basic component in many CNNs | [
"Do",
"multiple",
"convolution",
"and",
"one",
"pooling",
"this",
"is",
"the",
"basic",
"component",
"in",
"many",
"CNNs"
] | def conv_conv_pool(input_, n_filters, training, name, kernel_size=(3, 3),
conv_stride=(1, 1), pool=True, pool_size=(2, 2), pool_stride=(2, 2),
activation=tf.nn.relu, padding='same', bn=True, dropout=False, dropout_rate=None):
net = input_
with tf.variable_scope('layer{}'.fo... | [
"def",
"conv_conv_pool",
"(",
"input_",
",",
"n_filters",
",",
"training",
",",
"name",
",",
"kernel_size",
"=",
"(",
"3",
",",
"3",
")",
",",
"conv_stride",
"=",
"(",
"1",
",",
"1",
")",
",",
"pool",
"=",
"True",
",",
"pool_size",
"=",
"(",
"2",
... | Do multiple convolution and one pooling, this is the basic component in many CNNs | [
"Do",
"multiple",
"convolution",
"and",
"one",
"pooling",
"this",
"is",
"the",
"basic",
"component",
"in",
"many",
"CNNs"
] | [
"\"\"\"\n Do multiple convolution and one pooling, this is the basic component in many CNNs\n :param input_: input variable\n :param n_filters: #filters in each convolutional layers, could be a list\n :param training: indicates it is in training or not\n :param name: name for this variable scope\n ... | [
{
"param": "input_",
"type": null
},
{
"param": "n_filters",
"type": null
},
{
"param": "training",
"type": null
},
{
"param": "name",
"type": null
},
{
"param": "kernel_size",
"type": null
},
{
"param": "conv_stride",
"type": null
},
{
"pa... | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "input_",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
... |
35673d22447611ef4fab0da1732296c4802e0136 | bohaohuang/ersa | nn/nn_utils.py | [
"MIT"
] | Python | concat | <not_specific> | def concat(input_a, input_b, training, name):
"""
Concatenate two tensors along the last dimension
:param input_a:
:param input_b:
:param training: indicates it is in training or not
:param name: name for this variable scope
:return:
"""
with tf.variable_scope('layer{}'.format(name))... |
Concatenate two tensors along the last dimension
:param input_a:
:param input_b:
:param training: indicates it is in training or not
:param name: name for this variable scope
:return:
| Concatenate two tensors along the last dimension | [
"Concatenate",
"two",
"tensors",
"along",
"the",
"last",
"dimension"
] | def concat(input_a, input_b, training, name):
with tf.variable_scope('layer{}'.format(name)):
input_a_norm = tf.layers.batch_normalization(input_a, training=training, name='bn')
return tf.concat([input_a_norm, input_b], axis=-1, name='concat_{}'.format(name)) | [
"def",
"concat",
"(",
"input_a",
",",
"input_b",
",",
"training",
",",
"name",
")",
":",
"with",
"tf",
".",
"variable_scope",
"(",
"'layer{}'",
".",
"format",
"(",
"name",
")",
")",
":",
"input_a_norm",
"=",
"tf",
".",
"layers",
".",
"batch_normalization... | Concatenate two tensors along the last dimension | [
"Concatenate",
"two",
"tensors",
"along",
"the",
"last",
"dimension"
] | [
"\"\"\"\n Concatenate two tensors along the last dimension\n :param input_a:\n :param input_b:\n :param training: indicates it is in training or not\n :param name: name for this variable scope\n :return:\n \"\"\""
] | [
{
"param": "input_a",
"type": null
},
{
"param": "input_b",
"type": null
},
{
"param": "training",
"type": null
},
{
"param": "name",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "input_a",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
... |
35673d22447611ef4fab0da1732296c4802e0136 | bohaohuang/ersa | nn/nn_utils.py | [
"MIT"
] | Python | upsampling_2d | <not_specific> | def upsampling_2d(tensor, name, size=(2, 2)):
"""
Do 2d upsampling of the input tensor by size times
:param tensor: input tensor, should be a 3d tensor
:param name: name for this variable scope
:param size: how many times the input should be upsampled
:return:
"""
h, w, _ = tensor.get_sh... |
Do 2d upsampling of the input tensor by size times
:param tensor: input tensor, should be a 3d tensor
:param name: name for this variable scope
:param size: how many times the input should be upsampled
:return:
| Do 2d upsampling of the input tensor by size times | [
"Do",
"2d",
"upsampling",
"of",
"the",
"input",
"tensor",
"by",
"size",
"times"
] | def upsampling_2d(tensor, name, size=(2, 2)):
h, w, _ = tensor.get_shape().as_list()[1:]
h_multi, w_multi = size
target_h = h * h_multi
target_w = w * w_multi
return tf.image.resize_nearest_neighbor(tensor, (target_h, target_w), name='upsample_{}'.format(name)) | [
"def",
"upsampling_2d",
"(",
"tensor",
",",
"name",
",",
"size",
"=",
"(",
"2",
",",
"2",
")",
")",
":",
"h",
",",
"w",
",",
"_",
"=",
"tensor",
".",
"get_shape",
"(",
")",
".",
"as_list",
"(",
")",
"[",
"1",
":",
"]",
"h_multi",
",",
"w_mult... | Do 2d upsampling of the input tensor by size times | [
"Do",
"2d",
"upsampling",
"of",
"the",
"input",
"tensor",
"by",
"size",
"times"
] | [
"\"\"\"\n Do 2d upsampling of the input tensor by size times\n :param tensor: input tensor, should be a 3d tensor\n :param name: name for this variable scope\n :param size: how many times the input should be upsampled\n :return:\n \"\"\"",
"# first dim is batch num"
] | [
{
"param": "tensor",
"type": null
},
{
"param": "name",
"type": null
},
{
"param": "size",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "tensor",
"type": null,
"docstring": "input tensor, should be a 3d tensor",
"docstring_tokens": [
"input",
... |
35673d22447611ef4fab0da1732296c4802e0136 | bohaohuang/ersa | nn/nn_utils.py | [
"MIT"
] | Python | upsample_concat | <not_specific> | def upsample_concat(input_a, input_b, name, size=(2, 2)):
"""
Upsample tensor a and concatenate with tensor b
:param input_a:
:param input_b:
:param name: name for this variable scope
:param size: how many times tensor a should be upsampled
:return:
"""
upsample = upsampling_2d(input... |
Upsample tensor a and concatenate with tensor b
:param input_a:
:param input_b:
:param name: name for this variable scope
:param size: how many times tensor a should be upsampled
:return:
| Upsample tensor a and concatenate with tensor b | [
"Upsample",
"tensor",
"a",
"and",
"concatenate",
"with",
"tensor",
"b"
] | def upsample_concat(input_a, input_b, name, size=(2, 2)):
upsample = upsampling_2d(input_a, size=size, name=name)
return tf.concat([upsample, input_b], axis=-1, name='concat_{}'.format(name)) | [
"def",
"upsample_concat",
"(",
"input_a",
",",
"input_b",
",",
"name",
",",
"size",
"=",
"(",
"2",
",",
"2",
")",
")",
":",
"upsample",
"=",
"upsampling_2d",
"(",
"input_a",
",",
"size",
"=",
"size",
",",
"name",
"=",
"name",
")",
"return",
"tf",
"... | Upsample tensor a and concatenate with tensor b | [
"Upsample",
"tensor",
"a",
"and",
"concatenate",
"with",
"tensor",
"b"
] | [
"\"\"\"\n Upsample tensor a and concatenate with tensor b\n :param input_a:\n :param input_b:\n :param name: name for this variable scope\n :param size: how many times tensor a should be upsampled\n :return:\n \"\"\""
] | [
{
"param": "input_a",
"type": null
},
{
"param": "input_b",
"type": null
},
{
"param": "name",
"type": null
},
{
"param": "size",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "input_a",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
... |
35673d22447611ef4fab0da1732296c4802e0136 | bohaohuang/ersa | nn/nn_utils.py | [
"MIT"
] | Python | upsample_conv_concat | <not_specific> | def upsample_conv_concat(input_a, input_b, filter_n, training, name, size=(2, 2)):
"""
Upsample tensor a, do convolution and concatenate with tensor b
:param input_a:
:param input_b:
:param filter_n: #filters in convolutional layers to precess upsampled tensor a
:param training: indicates it is ... |
Upsample tensor a, do convolution and concatenate with tensor b
:param input_a:
:param input_b:
:param filter_n: #filters in convolutional layers to precess upsampled tensor a
:param training: indicates it is in training or not
:param name: name for this variable scope
:param size: how many... | Upsample tensor a, do convolution and concatenate with tensor b | [
"Upsample",
"tensor",
"a",
"do",
"convolution",
"and",
"concatenate",
"with",
"tensor",
"b"
] | def upsample_conv_concat(input_a, input_b, filter_n, training, name, size=(2, 2)):
upsample = upsampling_2d(input_a, size=size, name=name)
upsample = conv_conv_pool(upsample, filter_n, training, 'upsample_'+name, kernel_size=(2, 2), pool=False)
return tf.concat([input_b, upsample], axis=-1, name='concat_{}'... | [
"def",
"upsample_conv_concat",
"(",
"input_a",
",",
"input_b",
",",
"filter_n",
",",
"training",
",",
"name",
",",
"size",
"=",
"(",
"2",
",",
"2",
")",
")",
":",
"upsample",
"=",
"upsampling_2d",
"(",
"input_a",
",",
"size",
"=",
"size",
",",
"name",
... | Upsample tensor a, do convolution and concatenate with tensor b | [
"Upsample",
"tensor",
"a",
"do",
"convolution",
"and",
"concatenate",
"with",
"tensor",
"b"
] | [
"\"\"\"\n Upsample tensor a, do convolution and concatenate with tensor b\n :param input_a:\n :param input_b:\n :param filter_n: #filters in convolutional layers to precess upsampled tensor a\n :param training: indicates it is in training or not\n :param name: name for this variable scope\n :pa... | [
{
"param": "input_a",
"type": null
},
{
"param": "input_b",
"type": null
},
{
"param": "filter_n",
"type": null
},
{
"param": "training",
"type": null
},
{
"param": "name",
"type": null
},
{
"param": "size",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "input_a",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
... |
35673d22447611ef4fab0da1732296c4802e0136 | bohaohuang/ersa | nn/nn_utils.py | [
"MIT"
] | Python | crop_upsample_concat | <not_specific> | def crop_upsample_concat(input_a, input_b, margin, name):
"""
Upsample tensor a, crop tensor b and concatenate them
:param input_a:
:param input_b:
:param margin: the margin tensor b need to be cropped
:param name: name for this variable scope
:return:
"""
with tf.variable_scope('cro... |
Upsample tensor a, crop tensor b and concatenate them
:param input_a:
:param input_b:
:param margin: the margin tensor b need to be cropped
:param name: name for this variable scope
:return:
| Upsample tensor a, crop tensor b and concatenate them | [
"Upsample",
"tensor",
"a",
"crop",
"tensor",
"b",
"and",
"concatenate",
"them"
] | def crop_upsample_concat(input_a, input_b, margin, name):
with tf.variable_scope('crop_upsample_concat'):
_, w, h, _ = input_b.get_shape().as_list()
input_b_crop = tf.image.resize_image_with_crop_or_pad(input_b, w - margin, h - margin)
return upsample_concat(input_a, input_b_crop, name) | [
"def",
"crop_upsample_concat",
"(",
"input_a",
",",
"input_b",
",",
"margin",
",",
"name",
")",
":",
"with",
"tf",
".",
"variable_scope",
"(",
"'crop_upsample_concat'",
")",
":",
"_",
",",
"w",
",",
"h",
",",
"_",
"=",
"input_b",
".",
"get_shape",
"(",
... | Upsample tensor a, crop tensor b and concatenate them | [
"Upsample",
"tensor",
"a",
"crop",
"tensor",
"b",
"and",
"concatenate",
"them"
] | [
"\"\"\"\n Upsample tensor a, crop tensor b and concatenate them\n :param input_a:\n :param input_b:\n :param margin: the margin tensor b need to be cropped\n :param name: name for this variable scope\n :return:\n \"\"\""
] | [
{
"param": "input_a",
"type": null
},
{
"param": "input_b",
"type": null
},
{
"param": "margin",
"type": null
},
{
"param": "name",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "input_a",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
... |
35673d22447611ef4fab0da1732296c4802e0136 | bohaohuang/ersa | nn/nn_utils.py | [
"MIT"
] | Python | crop_upsample_conv_concat | <not_specific> | def crop_upsample_conv_concat(input_a, input_b, margin, name, filter_n, training):
"""
Upsample tensor a, do convolution on tensor a, crop tensor b and concatenate them
:param input_a:
:param input_b:
:param margin: the margin tensor b need to be cropped
:param name: name for this variable scope... |
Upsample tensor a, do convolution on tensor a, crop tensor b and concatenate them
:param input_a:
:param input_b:
:param margin: the margin tensor b need to be cropped
:param name: name for this variable scope
:param filter_n: #filters in convolutional layers to precess upsampled tensor a
:... | Upsample tensor a, do convolution on tensor a, crop tensor b and concatenate them | [
"Upsample",
"tensor",
"a",
"do",
"convolution",
"on",
"tensor",
"a",
"crop",
"tensor",
"b",
"and",
"concatenate",
"them"
] | def crop_upsample_conv_concat(input_a, input_b, margin, name, filter_n, training):
_, w, h, _ = input_b.get_shape().as_list()
input_b_crop = tf.image.resize_image_with_crop_or_pad(input_b, w - margin, h - margin)
return upsample_conv_concat(input_a, input_b_crop, filter_n, training, name) | [
"def",
"crop_upsample_conv_concat",
"(",
"input_a",
",",
"input_b",
",",
"margin",
",",
"name",
",",
"filter_n",
",",
"training",
")",
":",
"_",
",",
"w",
",",
"h",
",",
"_",
"=",
"input_b",
".",
"get_shape",
"(",
")",
".",
"as_list",
"(",
")",
"inpu... | Upsample tensor a, do convolution on tensor a, crop tensor b and concatenate them | [
"Upsample",
"tensor",
"a",
"do",
"convolution",
"on",
"tensor",
"a",
"crop",
"tensor",
"b",
"and",
"concatenate",
"them"
] | [
"\"\"\"\n Upsample tensor a, do convolution on tensor a, crop tensor b and concatenate them\n :param input_a:\n :param input_b:\n :param margin: the margin tensor b need to be cropped\n :param name: name for this variable scope\n :param filter_n: #filters in convolutional layers to precess upsampl... | [
{
"param": "input_a",
"type": null
},
{
"param": "input_b",
"type": null
},
{
"param": "margin",
"type": null
},
{
"param": "name",
"type": null
},
{
"param": "filter_n",
"type": null
},
{
"param": "training",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "input_a",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
... |
35673d22447611ef4fab0da1732296c4802e0136 | bohaohuang/ersa | nn/nn_utils.py | [
"MIT"
] | Python | decode_labels | <not_specific> | def decode_labels(label, label_num=2):
"""
Decode label prediction map into rgb color map
:param label: label prediction map
:param label_num: #distinct classes in ground truth
:return:
"""
n, h, w, c = label.shape
outputs = np.zeros((n, h, w, 3), dtype=np.uint8)
color_list = ersa_ut... |
Decode label prediction map into rgb color map
:param label: label prediction map
:param label_num: #distinct classes in ground truth
:return:
| Decode label prediction map into rgb color map | [
"Decode",
"label",
"prediction",
"map",
"into",
"rgb",
"color",
"map"
] | def decode_labels(label, label_num=2):
n, h, w, c = label.shape
outputs = np.zeros((n, h, w, 3), dtype=np.uint8)
color_list = ersa_utils.get_color_list()
label_colors = {}
for i in range(label_num):
label_colors[i] = color_list[i]
label_colors[0] = (255, 255, 255)
for i in range(n):
... | [
"def",
"decode_labels",
"(",
"label",
",",
"label_num",
"=",
"2",
")",
":",
"n",
",",
"h",
",",
"w",
",",
"c",
"=",
"label",
".",
"shape",
"outputs",
"=",
"np",
".",
"zeros",
"(",
"(",
"n",
",",
"h",
",",
"w",
",",
"3",
")",
",",
"dtype",
"... | Decode label prediction map into rgb color map | [
"Decode",
"label",
"prediction",
"map",
"into",
"rgb",
"color",
"map"
] | [
"\"\"\"\n Decode label prediction map into rgb color map\n :param label: label prediction map\n :param label_num: #distinct classes in ground truth\n :return:\n \"\"\""
] | [
{
"param": "label",
"type": null
},
{
"param": "label_num",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "label",
"type": null,
"docstring": "label prediction map",
"docstring_tokens": [
"label",
"predicti... |
35673d22447611ef4fab0da1732296c4802e0136 | bohaohuang/ersa | nn/nn_utils.py | [
"MIT"
] | Python | pad_prediction | <not_specific> | def pad_prediction(image, prediction):
"""
Pad prediction map if necessary, this is useful when network has smaller outputs than input images
:param image: input rgb image
:param prediction: network prediction map
:return:
"""
_, img_w, img_h, _ = image.shape
n, pred_img_w, pred_img_h, c... |
Pad prediction map if necessary, this is useful when network has smaller outputs than input images
:param image: input rgb image
:param prediction: network prediction map
:return:
| Pad prediction map if necessary, this is useful when network has smaller outputs than input images | [
"Pad",
"prediction",
"map",
"if",
"necessary",
"this",
"is",
"useful",
"when",
"network",
"has",
"smaller",
"outputs",
"than",
"input",
"images"
] | def pad_prediction(image, prediction):
_, img_w, img_h, _ = image.shape
n, pred_img_w, pred_img_h, c = prediction.shape
if img_w > pred_img_w and img_h > pred_img_h:
pad_w = int((img_w - pred_img_w) / 2)
pad_h = int((img_h - pred_img_h) / 2)
prediction_padded = np.zeros((n, img_w, im... | [
"def",
"pad_prediction",
"(",
"image",
",",
"prediction",
")",
":",
"_",
",",
"img_w",
",",
"img_h",
",",
"_",
"=",
"image",
".",
"shape",
"n",
",",
"pred_img_w",
",",
"pred_img_h",
",",
"c",
"=",
"prediction",
".",
"shape",
"if",
"img_w",
">",
"pred... | Pad prediction map if necessary, this is useful when network has smaller outputs than input images | [
"Pad",
"prediction",
"map",
"if",
"necessary",
"this",
"is",
"useful",
"when",
"network",
"has",
"smaller",
"outputs",
"than",
"input",
"images"
] | [
"\"\"\"\n Pad prediction map if necessary, this is useful when network has smaller outputs than input images\n :param image: input rgb image\n :param prediction: network prediction map\n :return:\n \"\"\""
] | [
{
"param": "image",
"type": null
},
{
"param": "prediction",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "image",
"type": null,
"docstring": "input rgb image",
"docstring_tokens": [
"input",
"rgb",
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.