Search is not available for this dataset
identifier
stringlengths
1
155
parameters
stringlengths
2
6.09k
docstring
stringlengths
11
63.4k
docstring_summary
stringlengths
0
63.4k
function
stringlengths
29
99.8k
function_tokens
list
start_point
list
end_point
list
language
stringclasses
1 value
docstring_language
stringlengths
2
7
docstring_language_predictions
stringlengths
18
23
is_langid_reliable
stringclasses
2 values
WeekMixin.get_previous_week
(self, date)
Get the previous valid week.
Get the previous valid week.
def get_previous_week(self, date): """Get the previous valid week.""" return _get_next_prev(self, date, is_previous=True, period='week')
[ "def", "get_previous_week", "(", "self", ",", "date", ")", ":", "return", "_get_next_prev", "(", "self", ",", "date", ",", "is_previous", "=", "True", ",", "period", "=", "'week'", ")" ]
[ 194, 4 ]
[ 196, 74 ]
python
en
['en', 'af', 'en']
True
WeekMixin._get_next_week
(self, date)
Return the start date of the next interval. The interval is defined by start date <= item date < next start date.
Return the start date of the next interval.
def _get_next_week(self, date): """ Return the start date of the next interval. The interval is defined by start date <= item date < next start date. """ try: return date + datetime.timedelta(days=7 - self._get_weekday(date)) except OverflowError: ...
[ "def", "_get_next_week", "(", "self", ",", "date", ")", ":", "try", ":", "return", "date", "+", "datetime", ".", "timedelta", "(", "days", "=", "7", "-", "self", ".", "_get_weekday", "(", "date", ")", ")", "except", "OverflowError", ":", "raise", "Http...
[ 198, 4 ]
[ 207, 49 ]
python
en
['en', 'error', 'th']
False
WeekMixin._get_current_week
(self, date)
Return the start date of the current interval.
Return the start date of the current interval.
def _get_current_week(self, date): """Return the start date of the current interval.""" return date - datetime.timedelta(self._get_weekday(date))
[ "def", "_get_current_week", "(", "self", ",", "date", ")", ":", "return", "date", "-", "datetime", ".", "timedelta", "(", "self", ".", "_get_weekday", "(", "date", ")", ")" ]
[ 209, 4 ]
[ 211, 65 ]
python
en
['en', 'en', 'en']
True
WeekMixin._get_weekday
(self, date)
Return the weekday for a given date. The first day according to the week format is 0 and the last day is 6.
Return the weekday for a given date.
def _get_weekday(self, date): """ Return the weekday for a given date. The first day according to the week format is 0 and the last day is 6. """ week_format = self.get_week_format() if week_format in {'%W', '%V'}: # week starts on Monday return date....
[ "def", "_get_weekday", "(", "self", ",", "date", ")", ":", "week_format", "=", "self", ".", "get_week_format", "(", ")", "if", "week_format", "in", "{", "'%W'", ",", "'%V'", "}", ":", "# week starts on Monday", "return", "date", ".", "weekday", "(", ")", ...
[ 213, 4 ]
[ 225, 69 ]
python
en
['en', 'error', 'th']
False
DateMixin.get_date_field
(self)
Get the name of the date field to be used to filter by.
Get the name of the date field to be used to filter by.
def get_date_field(self): """Get the name of the date field to be used to filter by.""" if self.date_field is None: raise ImproperlyConfigured("%s.date_field is required." % self.__class__.__name__) return self.date_field
[ "def", "get_date_field", "(", "self", ")", ":", "if", "self", ".", "date_field", "is", "None", ":", "raise", "ImproperlyConfigured", "(", "\"%s.date_field is required.\"", "%", "self", ".", "__class__", ".", "__name__", ")", "return", "self", ".", "date_field" ]
[ 233, 4 ]
[ 237, 30 ]
python
en
['en', 'en', 'en']
True
DateMixin.get_allow_future
(self)
Return `True` if the view should be allowed to display objects from the future.
Return `True` if the view should be allowed to display objects from the future.
def get_allow_future(self): """ Return `True` if the view should be allowed to display objects from the future. """ return self.allow_future
[ "def", "get_allow_future", "(", "self", ")", ":", "return", "self", ".", "allow_future" ]
[ 239, 4 ]
[ 244, 32 ]
python
en
['en', 'error', 'th']
False
DateMixin.uses_datetime_field
(self)
Return `True` if the date field is a `DateTimeField` and `False` if it's a `DateField`.
Return `True` if the date field is a `DateTimeField` and `False` if it's a `DateField`.
def uses_datetime_field(self): """ Return `True` if the date field is a `DateTimeField` and `False` if it's a `DateField`. """ model = self.get_queryset().model if self.model is None else self.model field = model._meta.get_field(self.get_date_field()) return isins...
[ "def", "uses_datetime_field", "(", "self", ")", ":", "model", "=", "self", ".", "get_queryset", "(", ")", ".", "model", "if", "self", ".", "model", "is", "None", "else", "self", ".", "model", "field", "=", "model", ".", "_meta", ".", "get_field", "(", ...
[ 250, 4 ]
[ 257, 54 ]
python
en
['en', 'error', 'th']
False
DateMixin._make_date_lookup_arg
(self, value)
Convert a date into a datetime when the date field is a DateTimeField. When time zone support is enabled, `date` is assumed to be in the current time zone, so that displayed items are consistent with the URL.
Convert a date into a datetime when the date field is a DateTimeField.
def _make_date_lookup_arg(self, value): """ Convert a date into a datetime when the date field is a DateTimeField. When time zone support is enabled, `date` is assumed to be in the current time zone, so that displayed items are consistent with the URL. """ if self.uses_d...
[ "def", "_make_date_lookup_arg", "(", "self", ",", "value", ")", ":", "if", "self", ".", "uses_datetime_field", ":", "value", "=", "datetime", ".", "datetime", ".", "combine", "(", "value", ",", "datetime", ".", "time", ".", "min", ")", "if", "settings", ...
[ 259, 4 ]
[ 270, 20 ]
python
en
['en', 'error', 'th']
False
DateMixin._make_single_date_lookup
(self, date)
Get the lookup kwargs for filtering on a single date. If the date field is a DateTimeField, we can't just filter on date_field=date because that doesn't take the time into account.
Get the lookup kwargs for filtering on a single date.
def _make_single_date_lookup(self, date): """ Get the lookup kwargs for filtering on a single date. If the date field is a DateTimeField, we can't just filter on date_field=date because that doesn't take the time into account. """ date_field = self.get_date_field() ...
[ "def", "_make_single_date_lookup", "(", "self", ",", "date", ")", ":", "date_field", "=", "self", ".", "get_date_field", "(", ")", "if", "self", ".", "uses_datetime_field", ":", "since", "=", "self", ".", "_make_date_lookup_arg", "(", "date", ")", "until", "...
[ 272, 4 ]
[ 289, 37 ]
python
en
['en', 'error', 'th']
False
BaseDateListView.get_dated_items
(self)
Obtain the list of dates and items.
Obtain the list of dates and items.
def get_dated_items(self): """Obtain the list of dates and items.""" raise NotImplementedError('A DateView must provide an implementation of get_dated_items()')
[ "def", "get_dated_items", "(", "self", ")", ":", "raise", "NotImplementedError", "(", "'A DateView must provide an implementation of get_dated_items()'", ")" ]
[ 306, 4 ]
[ 308, 99 ]
python
en
['en', 'en', 'en']
True
BaseDateListView.get_ordering
(self)
Return the field or fields to use for ordering the queryset; use the date field by default.
Return the field or fields to use for ordering the queryset; use the date field by default.
def get_ordering(self): """ Return the field or fields to use for ordering the queryset; use the date field by default. """ return '-%s' % self.get_date_field() if self.ordering is None else self.ordering
[ "def", "get_ordering", "(", "self", ")", ":", "return", "'-%s'", "%", "self", ".", "get_date_field", "(", ")", "if", "self", ".", "ordering", "is", "None", "else", "self", ".", "ordering" ]
[ 310, 4 ]
[ 315, 88 ]
python
en
['en', 'error', 'th']
False
BaseDateListView.get_dated_queryset
(self, **lookup)
Get a queryset properly filtered according to `allow_future` and any extra lookup kwargs.
Get a queryset properly filtered according to `allow_future` and any extra lookup kwargs.
def get_dated_queryset(self, **lookup): """ Get a queryset properly filtered according to `allow_future` and any extra lookup kwargs. """ qs = self.get_queryset().filter(**lookup) date_field = self.get_date_field() allow_future = self.get_allow_future() al...
[ "def", "get_dated_queryset", "(", "self", ",", "*", "*", "lookup", ")", ":", "qs", "=", "self", ".", "get_queryset", "(", ")", ".", "filter", "(", "*", "*", "lookup", ")", "date_field", "=", "self", ".", "get_date_field", "(", ")", "allow_future", "=",...
[ 317, 4 ]
[ 341, 17 ]
python
en
['en', 'error', 'th']
False
BaseDateListView.get_date_list_period
(self)
Get the aggregation period for the list of dates: 'year', 'month', or 'day'.
Get the aggregation period for the list of dates: 'year', 'month', or 'day'.
def get_date_list_period(self): """ Get the aggregation period for the list of dates: 'year', 'month', or 'day'. """ return self.date_list_period
[ "def", "get_date_list_period", "(", "self", ")", ":", "return", "self", ".", "date_list_period" ]
[ 343, 4 ]
[ 348, 36 ]
python
en
['en', 'error', 'th']
False
BaseDateListView.get_date_list
(self, queryset, date_type=None, ordering='ASC')
Get a date list by calling `queryset.dates/datetimes()`, checking along the way for empty lists that aren't allowed.
Get a date list by calling `queryset.dates/datetimes()`, checking along the way for empty lists that aren't allowed.
def get_date_list(self, queryset, date_type=None, ordering='ASC'): """ Get a date list by calling `queryset.dates/datetimes()`, checking along the way for empty lists that aren't allowed. """ date_field = self.get_date_field() allow_empty = self.get_allow_empty() ...
[ "def", "get_date_list", "(", "self", ",", "queryset", ",", "date_type", "=", "None", ",", "ordering", "=", "'ASC'", ")", ":", "date_field", "=", "self", ".", "get_date_field", "(", ")", "allow_empty", "=", "self", ".", "get_allow_empty", "(", ")", "if", ...
[ 350, 4 ]
[ 371, 24 ]
python
en
['en', 'error', 'th']
False
BaseArchiveIndexView.get_dated_items
(self)
Return (date_list, items, extra_context) for this request.
Return (date_list, items, extra_context) for this request.
def get_dated_items(self): """Return (date_list, items, extra_context) for this request.""" qs = self.get_dated_queryset() date_list = self.get_date_list(qs, ordering='DESC') if not date_list: qs = qs.none() return (date_list, qs, {})
[ "def", "get_dated_items", "(", "self", ")", ":", "qs", "=", "self", ".", "get_dated_queryset", "(", ")", "date_list", "=", "self", ".", "get_date_list", "(", "qs", ",", "ordering", "=", "'DESC'", ")", "if", "not", "date_list", ":", "qs", "=", "qs", "."...
[ 380, 4 ]
[ 388, 34 ]
python
en
['en', 'en', 'en']
True
BaseYearArchiveView.get_dated_items
(self)
Return (date_list, items, extra_context) for this request.
Return (date_list, items, extra_context) for this request.
def get_dated_items(self): """Return (date_list, items, extra_context) for this request.""" year = self.get_year() date_field = self.get_date_field() date = _date_from_string(year, self.get_year_format()) since = self._make_date_lookup_arg(date) until = self._make_date_...
[ "def", "get_dated_items", "(", "self", ")", ":", "year", "=", "self", ".", "get_year", "(", ")", "date_field", "=", "self", ".", "get_date_field", "(", ")", "date", "=", "_date_from_string", "(", "year", ",", "self", ".", "get_year_format", "(", ")", ")"...
[ 401, 4 ]
[ 427, 10 ]
python
en
['en', 'en', 'en']
True
BaseYearArchiveView.get_make_object_list
(self)
Return `True` if this view should contain the full list of objects in the given year.
Return `True` if this view should contain the full list of objects in the given year.
def get_make_object_list(self): """ Return `True` if this view should contain the full list of objects in the given year. """ return self.make_object_list
[ "def", "get_make_object_list", "(", "self", ")", ":", "return", "self", ".", "make_object_list" ]
[ 429, 4 ]
[ 434, 36 ]
python
en
['en', 'error', 'th']
False
BaseMonthArchiveView.get_dated_items
(self)
Return (date_list, items, extra_context) for this request.
Return (date_list, items, extra_context) for this request.
def get_dated_items(self): """Return (date_list, items, extra_context) for this request.""" year = self.get_year() month = self.get_month() date_field = self.get_date_field() date = _date_from_string(year, self.get_year_format(), month, self.get_...
[ "def", "get_dated_items", "(", "self", ")", ":", "year", "=", "self", ".", "get_year", "(", ")", "month", "=", "self", ".", "get_month", "(", ")", "date_field", "=", "self", ".", "get_date_field", "(", ")", "date", "=", "_date_from_string", "(", "year", ...
[ 446, 4 ]
[ 469, 10 ]
python
en
['en', 'en', 'en']
True
BaseWeekArchiveView.get_dated_items
(self)
Return (date_list, items, extra_context) for this request.
Return (date_list, items, extra_context) for this request.
def get_dated_items(self): """Return (date_list, items, extra_context) for this request.""" year = self.get_year() week = self.get_week() date_field = self.get_date_field() week_format = self.get_week_format() week_choices = {'%W': '1', '%U': '0', '%V': '1'} try:...
[ "def", "get_dated_items", "(", "self", ")", ":", "year", "=", "self", ".", "get_year", "(", ")", "week", "=", "self", ".", "get_week", "(", ")", "date_field", "=", "self", ".", "get_date_field", "(", ")", "week_format", "=", "self", ".", "get_week_format...
[ 480, 4 ]
[ 517, 10 ]
python
en
['en', 'en', 'en']
True
BaseDayArchiveView.get_dated_items
(self)
Return (date_list, items, extra_context) for this request.
Return (date_list, items, extra_context) for this request.
def get_dated_items(self): """Return (date_list, items, extra_context) for this request.""" year = self.get_year() month = self.get_month() day = self.get_day() date = _date_from_string(year, self.get_year_format(), month, self.get_month_format()...
[ "def", "get_dated_items", "(", "self", ")", ":", "year", "=", "self", ".", "get_year", "(", ")", "month", "=", "self", ".", "get_month", "(", ")", "day", "=", "self", ".", "get_day", "(", ")", "date", "=", "_date_from_string", "(", "year", ",", "self...
[ 527, 4 ]
[ 537, 42 ]
python
en
['en', 'en', 'en']
True
BaseDayArchiveView._get_dated_items
(self, date)
Do the actual heavy lifting of getting the dated items; this accepts a date object so that TodayArchiveView can be trivial.
Do the actual heavy lifting of getting the dated items; this accepts a date object so that TodayArchiveView can be trivial.
def _get_dated_items(self, date): """ Do the actual heavy lifting of getting the dated items; this accepts a date object so that TodayArchiveView can be trivial. """ lookup_kwargs = self._make_single_date_lookup(date) qs = self.get_dated_queryset(**lookup_kwargs) ...
[ "def", "_get_dated_items", "(", "self", ",", "date", ")", ":", "lookup_kwargs", "=", "self", ".", "_make_single_date_lookup", "(", "date", ")", "qs", "=", "self", ".", "get_dated_queryset", "(", "*", "*", "lookup_kwargs", ")", "return", "(", "None", ",", "...
[ 539, 4 ]
[ 553, 10 ]
python
en
['en', 'error', 'th']
False
BaseTodayArchiveView.get_dated_items
(self)
Return (date_list, items, extra_context) for this request.
Return (date_list, items, extra_context) for this request.
def get_dated_items(self): """Return (date_list, items, extra_context) for this request.""" return self._get_dated_items(datetime.date.today())
[ "def", "get_dated_items", "(", "self", ")", ":", "return", "self", ".", "_get_dated_items", "(", "datetime", ".", "date", ".", "today", "(", ")", ")" ]
[ 564, 4 ]
[ 566, 59 ]
python
en
['en', 'en', 'en']
True
BaseDateDetailView.get_object
(self, queryset=None)
Get the object this request displays.
Get the object this request displays.
def get_object(self, queryset=None): """Get the object this request displays.""" year = self.get_year() month = self.get_month() day = self.get_day() date = _date_from_string(year, self.get_year_format(), month, self.get_month_format(), ...
[ "def", "get_object", "(", "self", ",", "queryset", "=", "None", ")", ":", "year", "=", "self", ".", "get_year", "(", ")", "month", "=", "self", ".", "get_month", "(", ")", "day", "=", "self", ".", "get_day", "(", ")", "date", "=", "_date_from_string"...
[ 579, 4 ]
[ 606, 46 ]
python
en
['en', 'en', 'en']
True
PipProvider.get_preference
( self, identifier: str, resolutions: Mapping[str, Candidate], candidates: Mapping[str, Iterator[Candidate]], information: Mapping[str, Iterator["PreferenceInformation"]], )
Produce a sort key for given requirement based on preference. The lower the return value is, the more preferred this group of arguments is. Currently pip considers the followings in order: * Prefer if any of the known requirements is "direct", e.g. points to an explicit URL....
Produce a sort key for given requirement based on preference.
def get_preference( self, identifier: str, resolutions: Mapping[str, Candidate], candidates: Mapping[str, Iterator[Candidate]], information: Mapping[str, Iterator["PreferenceInformation"]], ) -> "Preference": """Produce a sort key for given requirement based on prefer...
[ "def", "get_preference", "(", "self", ",", "identifier", ":", "str", ",", "resolutions", ":", "Mapping", "[", "str", ",", "Candidate", "]", ",", "candidates", ":", "Mapping", "[", "str", ",", "Iterator", "[", "Candidate", "]", "]", ",", "information", ":...
[ 68, 4 ]
[ 143, 9 ]
python
en
['en', 'en', 'en']
True
opener_for
(ca_bundle=None)
Get a urlopen() replacement that uses ca_bundle for verification
Get a urlopen() replacement that uses ca_bundle for verification
def opener_for(ca_bundle=None): """Get a urlopen() replacement that uses ca_bundle for verification""" return urllib.request.build_opener( VerifyingHTTPSHandler(ca_bundle or find_ca_bundle()) ).open
[ "def", "opener_for", "(", "ca_bundle", "=", "None", ")", ":", "return", "urllib", ".", "request", ".", "build_opener", "(", "VerifyingHTTPSHandler", "(", "ca_bundle", "or", "find_ca_bundle", "(", ")", ")", ")", ".", "open" ]
[ 204, 0 ]
[ 208, 10 ]
python
en
['en', 'en', 'en']
True
find_ca_bundle
()
Return an existing CA bundle path, or None
Return an existing CA bundle path, or None
def find_ca_bundle(): """Return an existing CA bundle path, or None""" extant_cert_paths = filter(os.path.isfile, cert_paths) return ( get_win_certfile() or next(extant_cert_paths, None) or _certifi_where() )
[ "def", "find_ca_bundle", "(", ")", ":", "extant_cert_paths", "=", "filter", "(", "os", ".", "path", ".", "isfile", ",", "cert_paths", ")", "return", "(", "get_win_certfile", "(", ")", "or", "next", "(", "extant_cert_paths", ",", "None", ")", "or", "_certif...
[ 245, 0 ]
[ 252, 5 ]
python
en
['en', 'en', 'en']
True
client_with_credentials
(app)
This fixture provides a Flask app test client that has a session pre-configured with use credentials.
This fixture provides a Flask app test client that has a session pre-configured with use credentials.
def client_with_credentials(app): """This fixture provides a Flask app test client that has a session pre-configured with use credentials.""" credentials = OAuth2Credentials( 'access_token', 'client_id', 'client_secret', 'refresh_token', '3600', None, ...
[ "def", "client_with_credentials", "(", "app", ")", ":", "credentials", "=", "OAuth2Credentials", "(", "'access_token'", ",", "'client_id'", ",", "'client_secret'", ",", "'refresh_token'", ",", "'3600'", ",", "None", ",", "'Test'", ",", "id_token", "=", "{", "'su...
[ 25, 0 ]
[ 50, 16 ]
python
en
['en', 'en', 'en']
True
Menu.run
(self)
Display the menu and respond to choices
Display the menu and respond to choices
def run(self): "Display the menu and respond to choices" while True: self.display_menu() choice = raw_input("> ") action = self.choices.get(choice) if action: action() else: print "{0} is not a valid choice".form...
[ "def", "run", "(", "self", ")", ":", "while", "True", ":", "self", ".", "display_menu", "(", ")", "choice", "=", "raw_input", "(", "\"> \"", ")", "action", "=", "self", ".", "choices", ".", "get", "(", "choice", ")", "if", "action", ":", "action", ...
[ 24, 4 ]
[ 33, 64 ]
python
en
['en', 'en', 'en']
True
_load_client_secrets
(filename)
Loads client secrets from the given filename. Args: filename: The name of the file containing the JSON secret key. Returns: A 2-tuple, the first item containing the client id, and the second item containing a client secret.
Loads client secrets from the given filename.
def _load_client_secrets(filename): """Loads client secrets from the given filename. Args: filename: The name of the file containing the JSON secret key. Returns: A 2-tuple, the first item containing the client id, and the second item containing a client secret. """ client_...
[ "def", "_load_client_secrets", "(", "filename", ")", ":", "client_type", ",", "client_info", "=", "clientsecrets", ".", "loadfile", "(", "filename", ")", "if", "client_type", "!=", "clientsecrets", ".", "TYPE_WEB", ":", "raise", "ValueError", "(", "'The flow speci...
[ 244, 0 ]
[ 260, 65 ]
python
en
['en', 'en', 'en']
True
_get_oauth2_client_id_and_secret
(settings_instance)
Initializes client id and client secret based on the settings. Args: settings_instance: An instance of ``django.conf.settings``. Returns: A 2-tuple, the first item is the client id and the second item is the client secret.
Initializes client id and client secret based on the settings.
def _get_oauth2_client_id_and_secret(settings_instance): """Initializes client id and client secret based on the settings. Args: settings_instance: An instance of ``django.conf.settings``. Returns: A 2-tuple, the first item is the client id and the second item is the client secret...
[ "def", "_get_oauth2_client_id_and_secret", "(", "settings_instance", ")", ":", "secret_json", "=", "getattr", "(", "settings_instance", ",", "'GOOGLE_OAUTH2_CLIENT_SECRETS_JSON'", ",", "None", ")", "if", "secret_json", "is", "not", "None", ":", "return", "_load_client_s...
[ 263, 0 ]
[ 288, 61 ]
python
en
['en', 'en', 'en']
True
_get_storage_model
()
This configures whether the credentials will be stored in the session or the Django ORM based on the settings. By default, the credentials will be stored in the session, unless `GOOGLE_OAUTH2_STORAGE_MODEL` is found in the settings. Usually, the ORM storage is used to integrate credentials into an exist...
This configures whether the credentials will be stored in the session or the Django ORM based on the settings. By default, the credentials will be stored in the session, unless `GOOGLE_OAUTH2_STORAGE_MODEL` is found in the settings. Usually, the ORM storage is used to integrate credentials into an exist...
def _get_storage_model(): """This configures whether the credentials will be stored in the session or the Django ORM based on the settings. By default, the credentials will be stored in the session, unless `GOOGLE_OAUTH2_STORAGE_MODEL` is found in the settings. Usually, the ORM storage is used to integr...
[ "def", "_get_storage_model", "(", ")", ":", "storage_model_settings", "=", "getattr", "(", "django", ".", "conf", ".", "settings", ",", "'GOOGLE_OAUTH2_STORAGE_MODEL'", ",", "None", ")", "if", "storage_model_settings", "is", "not", "None", ":", "return", "(", "s...
[ 291, 0 ]
[ 315, 31 ]
python
en
['en', 'en', 'en']
True
get_storage
(request)
Gets a Credentials storage object provided by the Django OAuth2 Helper object. Args: request: Reference to the current request object. Returns: An :class:`oauth2.client.Storage` object.
Gets a Credentials storage object provided by the Django OAuth2 Helper object.
def get_storage(request): """ Gets a Credentials storage object provided by the Django OAuth2 Helper object. Args: request: Reference to the current request object. Returns: An :class:`oauth2.client.Storage` object. """ storage_model = oauth2_settings.storage_model user_prop...
[ "def", "get_storage", "(", "request", ")", ":", "storage_model", "=", "oauth2_settings", ".", "storage_model", "user_property", "=", "oauth2_settings", ".", "storage_model_user_property", "credentials_property", "=", "oauth2_settings", ".", "storage_model_credentials_property...
[ 369, 0 ]
[ 394, 50 ]
python
en
['en', 'en', 'en']
True
_redirect_with_params
(url_name, *args, **kwargs)
Helper method to create a redirect response with URL params. This builds a redirect string that converts kwargs into a query string. Args: url_name: The name of the url to redirect to. kwargs: the query string param and their values to build. Returns: A properly formatted redi...
Helper method to create a redirect response with URL params.
def _redirect_with_params(url_name, *args, **kwargs): """Helper method to create a redirect response with URL params. This builds a redirect string that converts kwargs into a query string. Args: url_name: The name of the url to redirect to. kwargs: the query string param and their val...
[ "def", "_redirect_with_params", "(", "url_name", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "url", "=", "urlresolvers", ".", "reverse", "(", "url_name", ",", "args", "=", "args", ")", "params", "=", "parse", ".", "urlencode", "(", "kwargs", "...
[ 397, 0 ]
[ 412, 40 ]
python
en
['en', 'en', 'en']
True
_credentials_from_request
(request)
Gets the authorized credentials for this flow, if they exist.
Gets the authorized credentials for this flow, if they exist.
def _credentials_from_request(request): """Gets the authorized credentials for this flow, if they exist.""" # ORM storage requires a logged in user if (oauth2_settings.storage_model is None or request.user.is_authenticated()): return get_storage(request).get() else: return No...
[ "def", "_credentials_from_request", "(", "request", ")", ":", "# ORM storage requires a logged in user", "if", "(", "oauth2_settings", ".", "storage_model", "is", "None", "or", "request", ".", "user", ".", "is_authenticated", "(", ")", ")", ":", "return", "get_stora...
[ 415, 0 ]
[ 422, 19 ]
python
en
['en', 'en', 'en']
True
UserOAuth2.__init__
(self, request, scopes=None, return_url=None)
Initialize the Oauth2 Object. Args: request: Django request object. scopes: Scopes desired for this OAuth2 flow. return_url: The url to return to after the OAuth flow is complete, defaults to the request's current URL path.
Initialize the Oauth2 Object.
def __init__(self, request, scopes=None, return_url=None): """Initialize the Oauth2 Object. Args: request: Django request object. scopes: Scopes desired for this OAuth2 flow. return_url: The url to return to after the OAuth flow is complete, defaults...
[ "def", "__init__", "(", "self", ",", "request", ",", "scopes", "=", "None", ",", "return_url", "=", "None", ")", ":", "self", ".", "request", "=", "request", "self", ".", "return_url", "=", "return_url", "or", "request", ".", "get_full_path", "(", ")", ...
[ 430, 4 ]
[ 444, 54 ]
python
en
['en', 'en', 'en']
True
UserOAuth2.get_authorize_redirect
(self)
Creates a URl to start the OAuth2 authorization flow.
Creates a URl to start the OAuth2 authorization flow.
def get_authorize_redirect(self): """Creates a URl to start the OAuth2 authorization flow.""" get_params = { 'return_url': self.return_url, 'scopes': self._get_scopes() } return _redirect_with_params('google_oauth:authorize', **get_params)
[ "def", "get_authorize_redirect", "(", "self", ")", ":", "get_params", "=", "{", "'return_url'", ":", "self", ".", "return_url", ",", "'scopes'", ":", "self", ".", "_get_scopes", "(", ")", "}", "return", "_redirect_with_params", "(", "'google_oauth:authorize'", "...
[ 446, 4 ]
[ 453, 76 ]
python
en
['en', 'en', 'en']
True
UserOAuth2.has_credentials
(self)
Returns True if there are valid credentials for the current user and required scopes.
Returns True if there are valid credentials for the current user and required scopes.
def has_credentials(self): """Returns True if there are valid credentials for the current user and required scopes.""" credentials = _credentials_from_request(self.request) return (credentials and not credentials.invalid and credentials.has_scopes(self._get_scopes()))
[ "def", "has_credentials", "(", "self", ")", ":", "credentials", "=", "_credentials_from_request", "(", "self", ".", "request", ")", "return", "(", "credentials", "and", "not", "credentials", ".", "invalid", "and", "credentials", ".", "has_scopes", "(", "self", ...
[ 455, 4 ]
[ 460, 59 ]
python
en
['en', 'en', 'en']
True
UserOAuth2._get_scopes
(self)
Returns the scopes associated with this object, kept up to date for incremental auth.
Returns the scopes associated with this object, kept up to date for incremental auth.
def _get_scopes(self): """Returns the scopes associated with this object, kept up to date for incremental auth.""" if _credentials_from_request(self.request): return (self._scopes | _credentials_from_request(self.request).scopes) else: return ...
[ "def", "_get_scopes", "(", "self", ")", ":", "if", "_credentials_from_request", "(", "self", ".", "request", ")", ":", "return", "(", "self", ".", "_scopes", "|", "_credentials_from_request", "(", "self", ".", "request", ")", ".", "scopes", ")", "else", ":...
[ 462, 4 ]
[ 469, 31 ]
python
en
['en', 'en', 'en']
True
UserOAuth2.scopes
(self)
Returns the scopes associated with this OAuth2 object.
Returns the scopes associated with this OAuth2 object.
def scopes(self): """Returns the scopes associated with this OAuth2 object.""" # make sure previously requested custom scopes are maintained # in future authorizations return self._get_scopes()
[ "def", "scopes", "(", "self", ")", ":", "# make sure previously requested custom scopes are maintained", "# in future authorizations", "return", "self", ".", "_get_scopes", "(", ")" ]
[ 472, 4 ]
[ 476, 33 ]
python
en
['en', 'en', 'en']
True
UserOAuth2.credentials
(self)
Gets the authorized credentials for this flow, if they exist.
Gets the authorized credentials for this flow, if they exist.
def credentials(self): """Gets the authorized credentials for this flow, if they exist.""" return _credentials_from_request(self.request)
[ "def", "credentials", "(", "self", ")", ":", "return", "_credentials_from_request", "(", "self", ".", "request", ")" ]
[ 479, 4 ]
[ 481, 54 ]
python
en
['en', 'en', 'en']
True
UserOAuth2.http
(self)
Helper: create HTTP client authorized with OAuth2 credentials.
Helper: create HTTP client authorized with OAuth2 credentials.
def http(self): """Helper: create HTTP client authorized with OAuth2 credentials.""" if self.has_credentials(): return self.credentials.authorize(transport.get_http_object()) return None
[ "def", "http", "(", "self", ")", ":", "if", "self", ".", "has_credentials", "(", ")", ":", "return", "self", ".", "credentials", ".", "authorize", "(", "transport", ".", "get_http_object", "(", ")", ")", "return", "None" ]
[ 484, 4 ]
[ 488, 19 ]
python
en
['en', 'en', 'en']
True
keygen
()
Key generator.
Key generator.
def keygen(): """Key generator.""" # Parse the CLI options parser = OptionParser(usage='usage: %prog [options] keysize', description='Generates a new RSA keypair of "keysize" bits.') parser.add_option('--pubout', type='string', help='Output filename for ...
[ "def", "keygen", "(", ")", ":", "# Parse the CLI options", "parser", "=", "OptionParser", "(", "usage", "=", "'usage: %prog [options] keysize'", ",", "description", "=", "'Generates a new RSA keypair of \"keysize\" bits.'", ")", "parser", ".", "add_option", "(", "'--pubou...
[ 33, 0 ]
[ 85, 41 ]
python
de
['de', 'uk', 'en']
False
CryptoOperation.perform_operation
(self, indata, key, cli_args)
Performs the program's operation. Implement in a subclass. :returns: the data to write to the output.
Performs the program's operation.
def perform_operation(self, indata, key, cli_args): """Performs the program's operation. Implement in a subclass. :returns: the data to write to the output. """
[ "def", "perform_operation", "(", "self", ",", "indata", ",", "key", ",", "cli_args", ")", ":" ]
[ 114, 4 ]
[ 120, 11 ]
python
en
['en', 'en', 'en']
True
CryptoOperation.__call__
(self)
Runs the program.
Runs the program.
def __call__(self): """Runs the program.""" (cli, cli_args) = self.parse_cli() key = self.read_key(cli_args[0], cli.keyform) indata = self.read_infile(cli.input) print(self.operation_progressive.title(), file=sys.stderr) outdata = self.perform_operation(indata, key, c...
[ "def", "__call__", "(", "self", ")", ":", "(", "cli", ",", "cli_args", ")", "=", "self", ".", "parse_cli", "(", ")", "key", "=", "self", ".", "read_key", "(", "cli_args", "[", "0", "]", ",", "cli", ".", "keyform", ")", "indata", "=", "self", ".",...
[ 122, 4 ]
[ 135, 51 ]
python
en
['en', 'sv', 'en']
True
CryptoOperation.parse_cli
(self)
Parse the CLI options :returns: (cli_opts, cli_args)
Parse the CLI options
def parse_cli(self): """Parse the CLI options :returns: (cli_opts, cli_args) """ parser = OptionParser(usage=self.usage, description=self.description) parser.add_option('-i', '--input', type='string', help=self.input_help) if self.has_output: parser.add_op...
[ "def", "parse_cli", "(", "self", ")", ":", "parser", "=", "OptionParser", "(", "usage", "=", "self", ".", "usage", ",", "description", "=", "self", ".", "description", ")", "parser", ".", "add_option", "(", "'-i'", ",", "'--input'", ",", "type", "=", "...
[ 137, 4 ]
[ 160, 28 ]
python
en
['en', 'en', 'en']
True
CryptoOperation.read_key
(self, filename, keyform)
Reads a public or private key.
Reads a public or private key.
def read_key(self, filename, keyform): """Reads a public or private key.""" print('Reading %s key from %s' % (self.keyname, filename), file=sys.stderr) with open(filename, 'rb') as keyfile: keydata = keyfile.read() return self.key_class.load_pkcs1(keydata, keyform)
[ "def", "read_key", "(", "self", ",", "filename", ",", "keyform", ")", ":", "print", "(", "'Reading %s key from %s'", "%", "(", "self", ".", "keyname", ",", "filename", ")", ",", "file", "=", "sys", ".", "stderr", ")", "with", "open", "(", "filename", "...
[ 162, 4 ]
[ 169, 58 ]
python
en
['en', 'en', 'en']
True
CryptoOperation.read_infile
(self, inname)
Read the input file
Read the input file
def read_infile(self, inname): """Read the input file""" if inname: print('Reading input from %s' % inname, file=sys.stderr) with open(inname, 'rb') as infile: return infile.read() print('Reading input from stdin', file=sys.stderr) return sys.std...
[ "def", "read_infile", "(", "self", ",", "inname", ")", ":", "if", "inname", ":", "print", "(", "'Reading input from %s'", "%", "inname", ",", "file", "=", "sys", ".", "stderr", ")", "with", "open", "(", "inname", ",", "'rb'", ")", "as", "infile", ":", ...
[ 171, 4 ]
[ 180, 31 ]
python
en
['en', 'en', 'en']
True
CryptoOperation.write_outfile
(self, outdata, outname)
Write the output file
Write the output file
def write_outfile(self, outdata, outname): """Write the output file""" if outname: print('Writing output to %s' % outname, file=sys.stderr) with open(outname, 'wb') as outfile: outfile.write(outdata) else: print('Writing output to stdout', fil...
[ "def", "write_outfile", "(", "self", ",", "outdata", ",", "outname", ")", ":", "if", "outname", ":", "print", "(", "'Writing output to %s'", "%", "outname", ",", "file", "=", "sys", ".", "stderr", ")", "with", "open", "(", "outname", ",", "'wb'", ")", ...
[ 182, 4 ]
[ 191, 48 ]
python
en
['en', 'sm', 'en']
True
EncryptOperation.perform_operation
(self, indata, pub_key, cli_args=None)
Encrypts files.
Encrypts files.
def perform_operation(self, indata, pub_key, cli_args=None): """Encrypts files.""" return rsa.encrypt(indata, pub_key)
[ "def", "perform_operation", "(", "self", ",", "indata", ",", "pub_key", ",", "cli_args", "=", "None", ")", ":", "return", "rsa", ".", "encrypt", "(", "indata", ",", "pub_key", ")" ]
[ 204, 4 ]
[ 207, 43 ]
python
en
['en', 'ht', 'en']
False
DecryptOperation.perform_operation
(self, indata, priv_key, cli_args=None)
Decrypts files.
Decrypts files.
def perform_operation(self, indata, priv_key, cli_args=None): """Decrypts files.""" return rsa.decrypt(indata, priv_key)
[ "def", "perform_operation", "(", "self", ",", "indata", ",", "priv_key", ",", "cli_args", "=", "None", ")", ":", "return", "rsa", ".", "decrypt", "(", "indata", ",", "priv_key", ")" ]
[ 221, 4 ]
[ 224, 44 ]
python
en
['en', 'lv', 'en']
False
SignOperation.perform_operation
(self, indata, priv_key, cli_args)
Signs files.
Signs files.
def perform_operation(self, indata, priv_key, cli_args): """Signs files.""" hash_method = cli_args[1] if hash_method not in HASH_METHODS: raise SystemExit('Invalid hash method, choose one of %s' % ', '.join(HASH_METHODS)) return rsa.sign(indata,...
[ "def", "perform_operation", "(", "self", ",", "indata", ",", "priv_key", ",", "cli_args", ")", ":", "hash_method", "=", "cli_args", "[", "1", "]", "if", "hash_method", "not", "in", "HASH_METHODS", ":", "raise", "SystemExit", "(", "'Invalid hash method, choose on...
[ 243, 4 ]
[ 251, 54 ]
python
en
['en', 'en', 'en']
False
VerifyOperation.perform_operation
(self, indata, pub_key, cli_args)
Verifies files.
Verifies files.
def perform_operation(self, indata, pub_key, cli_args): """Verifies files.""" signature_file = cli_args[1] with open(signature_file, 'rb') as sigfile: signature = sigfile.read() try: rsa.verify(indata, signature, pub_key) except rsa.VerificationError: ...
[ "def", "perform_operation", "(", "self", ",", "indata", ",", "pub_key", ",", "cli_args", ")", ":", "signature_file", "=", "cli_args", "[", "1", "]", "with", "open", "(", "signature_file", ",", "'rb'", ")", "as", "sigfile", ":", "signature", "=", "sigfile",...
[ 268, 4 ]
[ 281, 49 ]
python
en
['en', 'lv', 'en']
False
average_losses
(all_losses)
Average the losses into one dict of losses. Args: all_losses: List of dictionary of losses. Returns: combined: A dictionary with same keys as individual dicts, with all losses combined.
Average the losses into one dict of losses. Args: all_losses: List of dictionary of losses. Returns: combined: A dictionary with same keys as individual dicts, with all losses combined.
def average_losses(all_losses): """Average the losses into one dict of losses. Args: all_losses: List of dictionary of losses. Returns: combined: A dictionary with same keys as individual dicts, with all losses combined. """ if len(all_losses) == 0: return {} ...
[ "def", "average_losses", "(", "all_losses", ")", ":", "if", "len", "(", "all_losses", ")", "==", "0", ":", "return", "{", "}", "combined", "=", "{", "}", "for", "key", ",", "val", "in", "all_losses", "[", "0", "]", ".", "items", "(", ")", ":", "i...
[ 796, 0 ]
[ 817, 19 ]
python
en
['en', 'en', 'en']
True
combine_obj_pixels
(obj_pix, obj_dim)
Combine obj-split pixels into a single image. Args: obj_pix: B, ..., Nobj, ..., C, H, W obj_dim: The dimension to reduce over -- which corresponds to objs Returns B, ..., ..., C, H, W
Combine obj-split pixels into a single image. Args: obj_pix: B, ..., Nobj, ..., C, H, W obj_dim: The dimension to reduce over -- which corresponds to objs Returns B, ..., ..., C, H, W
def combine_obj_pixels(obj_pix, obj_dim): """Combine obj-split pixels into a single image. Args: obj_pix: B, ..., Nobj, ..., C, H, W obj_dim: The dimension to reduce over -- which corresponds to objs Returns B, ..., ..., C, H, W """ if obj_pix is None: return None ...
[ "def", "combine_obj_pixels", "(", "obj_pix", ",", "obj_dim", ")", ":", "if", "obj_pix", "is", "None", ":", "return", "None", "return", "torch", ".", "max", "(", "obj_pix", ",", "dim", "=", "obj_dim", ")", "[", "0", "]" ]
[ 1146, 0 ]
[ 1156, 45 ]
python
en
['en', 'fr', 'en']
True
DynConcat.forward
(self, features, pixels)
This dyn model does not use pixels, so will just return the last history frame Args: features: (B, T, Nobj, D, H', W') pixels: (B, T, Nobj, C, H, W) Returns: pred: (B, Nobj, D, H', W') pixels: (B, Nobj, C, H, W) addl_losses...
This dyn model does not use pixels, so will just return the last history frame Args: features: (B, T, Nobj, D, H', W') pixels: (B, T, Nobj, C, H, W) Returns: pred: (B, Nobj, D, H', W') pixels: (B, Nobj, C, H, W) addl_losses...
def forward(self, features, pixels): """ This dyn model does not use pixels, so will just return the last history frame Args: features: (B, T, Nobj, D, H', W') pixels: (B, T, Nobj, C, H, W) Returns: pred: (B, Nobj, D, H', W') pi...
[ "def", "forward", "(", "self", ",", "features", ",", "pixels", ")", ":", "cat_feats", "=", "torch", ".", "reshape", "(", "features", ",", "(", "features", ".", "shape", "[", "0", "]", ",", "-", "1", ")", "+", "features", ".", "shape", "[", "-", "...
[ 266, 4 ]
[ 285, 43 ]
python
en
['en', 'error', 'th']
False
MultiSTN.__init__
(self, input_dim, num_tx, dof='affine', inp_type='pix', affine_tx_mode='bilinear', kernel_size=3, stochastic=False)
Args: input_dim (int): Dimension of the features used to predict the STN parameters num_tx (int): Number of transformations to predict, will apply to the tensor, split along some dimension dof (str): Controls how generic of a affine matrix to ...
Args: input_dim (int): Dimension of the features used to predict the STN parameters num_tx (int): Number of transformations to predict, will apply to the tensor, split along some dimension dof (str): Controls how generic of a affine matrix to ...
def __init__(self, input_dim, num_tx, dof='affine', inp_type='pix', affine_tx_mode='bilinear', kernel_size=3, stochastic=False): """ Args: input_dim (int): Dimension of the ...
[ "def", "__init__", "(", "self", ",", "input_dim", ",", "num_tx", ",", "dof", "=", "'affine'", ",", "inp_type", "=", "'pix'", ",", "affine_tx_mode", "=", "'bilinear'", ",", "kernel_size", "=", "3", ",", "stochastic", "=", "False", ")", ":", "super", "(", ...
[ 291, 4 ]
[ 357, 75 ]
python
en
['en', 'error', 'th']
False
MultiSTN.transform_pix
(self, feat, theta, mode='bilinear')
Transform the features using theta.
Transform the features using theta.
def transform_pix(self, feat, theta, mode='bilinear'): """Transform the features using theta.""" grid = nn.functional.affine_grid(theta, feat.size(), align_corners=True) return nn.functional.grid_sample(feat, ...
[ "def", "transform_pix", "(", "self", ",", "feat", ",", "theta", ",", "mode", "=", "'bilinear'", ")", ":", "grid", "=", "nn", ".", "functional", ".", "affine_grid", "(", "theta", ",", "feat", ".", "size", "(", ")", ",", "align_corners", "=", "True", "...
[ 359, 4 ]
[ 367, 60 ]
python
en
['en', 'en', 'en']
True
MultiSTN.transform_pt
(self, feat, theta)
Transform pt-net style feature using theta. Here, it assumes the first 2 dimensions of the feature are loc. Args: feat (B, C, H, W), C >= 2 Returns: tx feat (B, C, H, W)
Transform pt-net style feature using theta. Here, it assumes the first 2 dimensions of the feature are loc. Args: feat (B, C, H, W), C >= 2 Returns: tx feat (B, C, H, W)
def transform_pt(self, feat, theta): """Transform pt-net style feature using theta. Here, it assumes the first 2 dimensions of the feature are loc. Args: feat (B, C, H, W), C >= 2 Returns: tx feat (B, C, H, W) """ assert feat.shape[1] >= 2 ...
[ "def", "transform_pt", "(", "self", ",", "feat", ",", "theta", ")", ":", "assert", "feat", ".", "shape", "[", "1", "]", ">=", "2", "feat_pos", "=", "feat", "[", ":", ",", ":", "2", ",", "...", "]", "feat_pos_ones", "=", "torch", ".", "ones_like", ...
[ 369, 4 ]
[ 387, 22 ]
python
en
['en', 'en', 'en']
True
MultiSTN.forward
(self, feat_for_tx, feat_to_tx, split_dim=1)
Args: feat_for_tx (B, D, H, W): The features to use to compute the transformation feat_to_tx (B, D', H, W): Features to apply the tx onto split_dim (int): Dimension to split on
Args: feat_for_tx (B, D, H, W): The features to use to compute the transformation feat_to_tx (B, D', H, W): Features to apply the tx onto split_dim (int): Dimension to split on
def forward(self, feat_for_tx, feat_to_tx, split_dim=1): """ Args: feat_for_tx (B, D, H, W): The features to use to compute the transformation feat_to_tx (B, D', H, W): Features to apply the tx onto split_dim (int): Dimension to split on """ ...
[ "def", "forward", "(", "self", ",", "feat_for_tx", ",", "feat_to_tx", ",", "split_dim", "=", "1", ")", ":", "feat_hist_embed", "=", "self", ".", "localization", "(", "feat_for_tx", ")", "# Average out the spatial dimension", "feat_hist_embed", "=", "torch", ".", ...
[ 399, 4 ]
[ 460, 75 ]
python
en
['en', 'error', 'th']
False
DynSTN.forward
(self, features, pixels)
This dyn model does not use pixels, so will just return the last history frame Args: features: (B, T, Nobj, D, H', W') pixels: (B, T, Nobj, C, H, W) Returns: pred: (B, Nobj, D, H', W') pix addl_losses
This dyn model does not use pixels, so will just return the last history frame Args: features: (B, T, Nobj, D, H', W') pixels: (B, T, Nobj, C, H, W) Returns: pred: (B, Nobj, D, H', W') pix addl_losses
def forward(self, features, pixels): """ This dyn model does not use pixels, so will just return the last history frame Args: features: (B, T, Nobj, D, H', W') pixels: (B, T, Nobj, C, H, W) Returns: pred: (B, Nobj, D, H', W') pi...
[ "def", "forward", "(", "self", ",", "features", ",", "pixels", ")", ":", "cat_feats", "=", "torch", ".", "reshape", "(", "features", ",", "(", "features", ".", "shape", "[", "0", "]", ",", "-", "1", ")", "+", "features", ".", "shape", "[", "-", "...
[ 472, 4 ]
[ 492, 58 ]
python
en
['en', 'error', 'th']
False
DynSTNPixels_DEPRECATED.forward
(self, features, pixels)
Args: features: (B, T, Nobj, D, H', W') pixels: (B, T, C, H, W) Returns: pred: (B, Nobj, D, H', W')
Args: features: (B, T, Nobj, D, H', W') pixels: (B, T, C, H, W) Returns: pred: (B, Nobj, D, H', W')
def forward(self, features, pixels): """ Args: features: (B, T, Nobj, D, H', W') pixels: (B, T, C, H, W) Returns: pred: (B, Nobj, D, H', W') """ raise NotImplementedError('Deal with objectified pixel input. ' '...
[ "def", "forward", "(", "self", ",", "features", ",", "pixels", ")", ":", "raise", "NotImplementedError", "(", "'Deal with objectified pixel input. '", "'Also deal with addl losses. '", ")", "cat_feats", "=", "torch", ".", "reshape", "(", "features", ",", "(", "featu...
[ 510, 4 ]
[ 540, 41 ]
python
en
['en', 'error', 'th']
False
DynSTNPixelChannels_DEPRECATED.forward
(self, features, pixels)
Args: features: (B, T, Nobj, D, H', W') pixels: (B, T, C, H, W) Returns: pred: (B, Nobj, D, H', W')
Args: features: (B, T, Nobj, D, H', W') pixels: (B, T, C, H, W) Returns: pred: (B, Nobj, D, H', W')
def forward(self, features, pixels): """ Args: features: (B, T, Nobj, D, H', W') pixels: (B, T, C, H, W) Returns: pred: (B, Nobj, D, H', W') """ raise NotImplementedError('Deal with objectified pixel input. ' '...
[ "def", "forward", "(", "self", ",", "features", ",", "pixels", ")", ":", "raise", "NotImplementedError", "(", "'Deal with objectified pixel input. '", "'Also deal with addl losses. '", ")", "assert", "(", "pixels", ".", "shape", "[", "2", "]", "==", "self", ".", ...
[ 553, 4 ]
[ 572, 41 ]
python
en
['en', 'error', 'th']
False
DynSTNPixelChannelsGenBg_DEPRECATED.forward
(self, features, pixels)
Args: features: (B, T, Nobj, D, H', W') pixels: (B, T, C, H, W) Returns: pred: (B, Nobj, D, H', W')
Args: features: (B, T, Nobj, D, H', W') pixels: (B, T, C, H, W) Returns: pred: (B, Nobj, D, H', W')
def forward(self, features, pixels): """ Args: features: (B, T, Nobj, D, H', W') pixels: (B, T, C, H, W) Returns: pred: (B, Nobj, D, H', W') """ raise NotImplementedError('Deal with objectified pixel input. ' '...
[ "def", "forward", "(", "self", ",", "features", ",", "pixels", ")", ":", "raise", "NotImplementedError", "(", "'Deal with objectified pixel input. '", "'Also deal with addl losses. '", ")", "assert", "(", "pixels", ".", "shape", "[", "2", "]", "-", "1", ")", "==...
[ 600, 4 ]
[ 621, 41 ]
python
en
['en', 'error', 'th']
False
DynSTNPixelChannelsDetBg.forward
(self, features, pixels)
Args: features: (B, T, Nobj, D, H', W') pixels: (B, T, Nobj, C, H, W) Returns: pred: (B, Nobj, D, H', W') pix addl_losses
Args: features: (B, T, Nobj, D, H', W') pixels: (B, T, Nobj, C, H, W) Returns: pred: (B, Nobj, D, H', W') pix addl_losses
def forward(self, features, pixels): """ Args: features: (B, T, Nobj, D, H', W') pixels: (B, T, Nobj, C, H, W) Returns: pred: (B, Nobj, D, H', W') pix addl_losses """ assert pixels.shape[3] >= self.num_tx cat_fea...
[ "def", "forward", "(", "self", ",", "features", ",", "pixels", ")", ":", "assert", "pixels", ".", "shape", "[", "3", "]", ">=", "self", ".", "num_tx", "cat_feats", "=", "torch", ".", "reshape", "(", "features", ",", "(", "features", ".", "shape", "["...
[ 651, 4 ]
[ 681, 54 ]
python
en
['en', 'error', 'th']
False
BasicDecoder.forward
(self, features, pixels)
Args: features (BxNobjxDxH'xW'): Features to be decoded pixels (BxNobjxCxHxW): Pixels generated by the dynamics model Returns: imgs (BxNobjxD_outxHxW): Output frames (per obj, aggregation is done later in the Fwd class)
Args: features (BxNobjxDxH'xW'): Features to be decoded pixels (BxNobjxCxHxW): Pixels generated by the dynamics model Returns: imgs (BxNobjxD_outxHxW): Output frames (per obj, aggregation is done later in the Fwd class)
def forward(self, features, pixels): """ Args: features (BxNobjxDxH'xW'): Features to be decoded pixels (BxNobjxCxHxW): Pixels generated by the dynamics model Returns: imgs (BxNobjxD_outxHxW): Output frames (per obj, aggregation is done later i...
[ "def", "forward", "(", "self", ",", "features", ",", "pixels", ")", ":", "if", "self", ".", "decode_from", "==", "'pixels'", ":", "decode_feature", "=", "pixels", "else", ":", "decode_feature", "=", "features", "if", "not", "self", ".", "backprop_feat_ext", ...
[ 750, 4 ]
[ 775, 18 ]
python
en
['en', 'error', 'th']
False
TrivialDecoder.forward
(self, features, pixels)
Args: features (BxNobjxDxH'xW'): Features to be decoded pixels (BxNobjxCxHxW): Pixels generated by the dynamics model Returns: imgs (BxNobjxCxHxW): Output frames
Args: features (BxNobjxDxH'xW'): Features to be decoded pixels (BxNobjxCxHxW): Pixels generated by the dynamics model Returns: imgs (BxNobjxCxHxW): Output frames
def forward(self, features, pixels): """ Args: features (BxNobjxDxH'xW'): Features to be decoded pixels (BxNobjxCxHxW): Pixels generated by the dynamics model Returns: imgs (BxNobjxCxHxW): Output frames """ del features # assumes the dynamics ...
[ "def", "forward", "(", "self", ",", "features", ",", "pixels", ")", ":", "del", "features", "# assumes the dynamics model will do all decoding", "return", "pixels" ]
[ 784, 4 ]
[ 793, 21 ]
python
en
['en', 'error', 'th']
False
BasicObjEncoder.forward
(self, feat)
Args: feat: (B, T, Nobj, D, H', W')
Args: feat: (B, T, Nobj, D, H', W')
def forward(self, feat): """ Args: feat: (B, T, Nobj, D, H', W') """ if self.encoder: feat_flat = torch.flatten(feat, 0, 2) obj_embed_flat = self.encoder(feat_flat) obj_embed = torch.reshape( obj_embed_flat, feat.shape[:3] +...
[ "def", "forward", "(", "self", ",", "feat", ")", ":", "if", "self", ".", "encoder", ":", "feat_flat", "=", "torch", ".", "flatten", "(", "feat", ",", "0", ",", "2", ")", "obj_embed_flat", "=", "self", ".", "encoder", "(", "feat_flat", ")", "obj_embed...
[ 854, 4 ]
[ 868, 24 ]
python
en
['en', 'error', 'th']
False
ContextGatingObjectifier.forward
(self, vid_feat)
Decompose the video features into object level representation. Args: vid_feat: (BxTxDxH'xW') nobj (int): Max number of objects in the scene. The hope is that the extra channels will just have some degenerate information Returns: BxTxNobjxDxH''...
Decompose the video features into object level representation. Args: vid_feat: (BxTxDxH'xW') nobj (int): Max number of objects in the scene. The hope is that the extra channels will just have some degenerate information Returns: BxTxNobjxDxH''...
def forward(self, vid_feat): """ Decompose the video features into object level representation. Args: vid_feat: (BxTxDxH'xW') nobj (int): Max number of objects in the scene. The hope is that the extra channels will just have some degenerate information ...
[ "def", "forward", "(", "self", ",", "vid_feat", ")", ":", "raise", "NotImplementedError", "(", "'The inp is now objfied, TODO deal with it'", ")", "batch_size", "=", "vid_feat", ".", "shape", "[", "0", "]", "# Use context gating: generate a heatmap for each object at each t...
[ 887, 4 ]
[ 912, 25 ]
python
en
['en', 'error', 'th']
False
ChannelSplitObjectifier.forward
(self, vid_feat)
Decompose the video features into object level representation. Args: vid_feat: (BxTxNobjxDxH'xW') Returns: BxTxNobjx(D/Nobj)xH'xW'
Decompose the video features into object level representation. Args: vid_feat: (BxTxNobjxDxH'xW') Returns: BxTxNobjx(D/Nobj)xH'xW'
def forward(self, vid_feat): """ Decompose the video features into object level representation. Args: vid_feat: (BxTxNobjxDxH'xW') Returns: BxTxNobjx(D/Nobj)xH'xW' """ assert vid_feat.shape[2] == 1, ( 'Channel split can not deal with pr...
[ "def", "forward", "(", "self", ",", "vid_feat", ")", ":", "assert", "vid_feat", ".", "shape", "[", "2", "]", "==", "1", ",", "(", "'Channel split can not deal with pre objectified {} input'", ".", "format", "(", "vid_feat", ".", "shape", "[", "2", "]", ")", ...
[ 923, 4 ]
[ 942, 26 ]
python
en
['en', 'error', 'th']
False
SimpleBaseEncoder.__init__
(self, in_dim, width_scale_factor)
Simple encoder weights. For a 256x256 input, it'll give a 4x4 output.
Simple encoder weights. For a 256x256 input, it'll give a 4x4 output.
def __init__(self, in_dim, width_scale_factor): """Simple encoder weights. For a 256x256 input, it'll give a 4x4 output.""" super().__init__() self.width_scale_factor = width_scale_factor _s = self._scale_int self.stem = nn.Sequential( nn.Conv2d(in_dim, 3, ker...
[ "def", "__init__", "(", "self", ",", "in_dim", ",", "width_scale_factor", ")", ":", "super", "(", ")", ".", "__init__", "(", ")", "self", ".", "width_scale_factor", "=", "width_scale_factor", "_s", "=", "self", ".", "_scale_int", "self", ".", "stem", "=", ...
[ 965, 4 ]
[ 1016, 30 ]
python
af
['es', 'af', 'en']
False
SimpleBaseEncoder._scale_int
(self, n)
Scale the number by a factor. To control width of this network.
Scale the number by a factor. To control width of this network.
def _scale_int(self, n): """Scale the number by a factor. To control width of this network.""" return int(self.width_scale_factor * n)
[ "def", "_scale_int", "(", "self", ",", "n", ")", ":", "return", "int", "(", "self", ".", "width_scale_factor", "*", "n", ")" ]
[ 1018, 4 ]
[ 1020, 47 ]
python
en
['en', 'en', 'en']
True
BasicEncoder.__init__
(self, in_dim, nobj, feat_ext, objectifier, obj_encoder, spatial_mean, feat_ext_eval_mode, process_objs_together)
Args: obj_before_enc: If true, do the objectify in the input (pixel) space before running the encode (so each object is encoded separately) spatial_mean: Avg pool the features to 1x1 feat_ext_eval_mode: Set the feature extractor to eval mode for BN, ...
Args: obj_before_enc: If true, do the objectify in the input (pixel) space before running the encode (so each object is encoded separately) spatial_mean: Avg pool the features to 1x1 feat_ext_eval_mode: Set the feature extractor to eval mode for BN, ...
def __init__(self, in_dim, nobj, feat_ext, objectifier, obj_encoder, spatial_mean, feat_ext_eval_mode, process_objs_together): """ Args: obj_before_enc: If true, do the objectify in the input (pixel) space before running the encode (so each object is encoded ...
[ "def", "__init__", "(", "self", ",", "in_dim", ",", "nobj", ",", "feat_ext", ",", "objectifier", ",", "obj_encoder", ",", "spatial_mean", ",", "feat_ext_eval_mode", ",", "process_objs_together", ")", ":", "super", "(", ")", ".", "__init__", "(", ")", "self",...
[ 1057, 4 ]
[ 1085, 52 ]
python
en
['en', 'error', 'th']
False
BasicEncoder._forward_vid
(self, batch_vid_obs, l2_norm_feats=False)
Convert a video into images to run the forward model. Args: batch_vid_obs: BxTxCxHxW or BxTxNobjxCxHxW Returns: features: BxTxDxH'xW' or BxTxNobjxDxH'xW'
Convert a video into images to run the forward model. Args: batch_vid_obs: BxTxCxHxW or BxTxNobjxCxHxW Returns: features: BxTxDxH'xW' or BxTxNobjxDxH'xW'
def _forward_vid(self, batch_vid_obs, l2_norm_feats=False): """ Convert a video into images to run the forward model. Args: batch_vid_obs: BxTxCxHxW or BxTxNobjxCxHxW Returns: features: BxTxDxH'xW' or BxTxNobjxDxH'xW' """ # Add an object dimension,...
[ "def", "_forward_vid", "(", "self", ",", "batch_vid_obs", ",", "l2_norm_feats", "=", "False", ")", ":", "# Add an object dimension, so the rest of the code doesn't have to", "# deal with edge cases", "added_obj_dim", "=", "False", "if", "len", "(", "batch_vid_obs", ".", "...
[ 1087, 4 ]
[ 1131, 31 ]
python
en
['en', 'error', 'th']
False
BasicEncoder.forward
(self, vid)
Args: vid (B, T, Nobj, C, H, W): Input video, in preprocessed form; i.e. one-hot Returns: obj_feat (B, T, Nobj', D, H', W'): Features with objects, if needed
Args: vid (B, T, Nobj, C, H, W): Input video, in preprocessed form; i.e. one-hot Returns: obj_feat (B, T, Nobj', D, H', W'): Features with objects, if needed
def forward(self, vid): """ Args: vid (B, T, Nobj, C, H, W): Input video, in preprocessed form; i.e. one-hot Returns: obj_feat (B, T, Nobj', D, H', W'): Features with objects, if needed """ vid_feat = self._forward_vid(vid) vid_feat...
[ "def", "forward", "(", "self", ",", "vid", ")", ":", "vid_feat", "=", "self", ".", "_forward_vid", "(", "vid", ")", "vid_feat", "=", "self", ".", "objectifier", "(", "vid_feat", ")", "return", "vid_feat" ]
[ 1133, 4 ]
[ 1143, 23 ]
python
en
['en', 'error', 'th']
False
MLPClassifier.forward
(self, preds, pixs, process_all_frames=False)
Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (BxT) process_all_frames: Set true when used by other classifiers for intermediate feature extraction, so to get features for e...
Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (BxT) process_all_frames: Set true when used by other classifiers for intermediate feature extraction, so to get features for e...
def forward(self, preds, pixs, process_all_frames=False): """ Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (BxT) process_all_frames: Set true when used by other classifiers for ...
[ "def", "forward", "(", "self", ",", "preds", ",", "pixs", ",", "process_all_frames", "=", "False", ")", ":", "del", "pixs", "# This does not use it", "if", "self", ".", "nlayers", "==", "0", ":", "return", "preds", "# Since this classifier doesn't take into accoun...
[ 1181, 4 ]
[ 1212, 46 ]
python
en
['en', 'error', 'th']
False
ConvNetClassifier.forward
(self, preds, pixs, process_all_frames=False)
Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) process_all_frames: Set true when used by other classifiers for intermediate feature extraction, so to get features for each frame. Retuns:...
Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) process_all_frames: Set true when used by other classifiers for intermediate feature extraction, so to get features for each frame. Retuns:...
def forward(self, preds, pixs, process_all_frames=False): """ Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) process_all_frames: Set true when used by other classifiers for intermediate feature extractio...
[ "def", "forward", "(", "self", ",", "preds", ",", "pixs", ",", "process_all_frames", "=", "False", ")", ":", "# Not enforcing the assert here if pred is None, since this module", "# is usually used by other modules as a way to extract features,", "# and it might pass in None for pred...
[ 1256, 4 ]
[ 1281, 79 ]
python
en
['en', 'error', 'th']
False
TxClassifier.forward
(self, preds, pixs)
Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (Bx1)
Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (Bx1)
def forward(self, preds, pixs): """ Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (Bx1) """ del pixs # This does not use it # Spatial mean the features stacked_m...
[ "def", "forward", "(", "self", ",", "preds", ",", "pixs", ")", ":", "del", "pixs", "# This does not use it", "# Spatial mean the features", "stacked_mean_feat", "=", "torch", ".", "flatten", "(", "torch", ".", "mean", "(", "preds", ",", "axis", "=", "[", "-"...
[ 1291, 4 ]
[ 1310, 23 ]
python
en
['en', 'error', 'th']
False
ConvTxClassifier.forward
(self, preds, pixs)
Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (Bx1)
Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (Bx1)
def forward(self, preds, pixs): """ Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (Bx1) """ assert preds.shape[1] == pixs.shape[1], ( 'Must pass in run_decode=True if...
[ "def", "forward", "(", "self", ",", "preds", ",", "pixs", ")", ":", "assert", "preds", ".", "shape", "[", "1", "]", "==", "pixs", ".", "shape", "[", "1", "]", ",", "(", "'Must pass in run_decode=True if using a pixel-based classifier!!'", ")", "del", "preds"...
[ 1320, 4 ]
[ 1334, 20 ]
python
en
['en', 'error', 'th']
False
Conv3dClassifier.forward
(self, preds, pixs)
Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (Bx1)
Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (Bx1)
def forward(self, preds, pixs): """ Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (Bx1) """ del pixs enc_preds = self.enc(preds.squeeze(2).transpose(1, 2)) cls_pr...
[ "def", "forward", "(", "self", ",", "preds", ",", "pixs", ")", ":", "del", "pixs", "enc_preds", "=", "self", ".", "enc", "(", "preds", ".", "squeeze", "(", "2", ")", ".", "transpose", "(", "1", ",", "2", ")", ")", "cls_preds", "=", "self", ".", ...
[ 1349, 4 ]
[ 1364, 24 ]
python
en
['en', 'error', 'th']
False
ConvConv3dClassifier.forward
(self, preds, pixs)
Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (Bx1)
Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (Bx1)
def forward(self, preds, pixs): """ Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (Bx1) """ assert preds.shape[1] == pixs.shape[1], ( 'Must pass in run_decode=True if...
[ "def", "forward", "(", "self", ",", "preds", ",", "pixs", ")", ":", "assert", "preds", ".", "shape", "[", "1", "]", "==", "pixs", ".", "shape", "[", "1", "]", ",", "(", "'Must pass in run_decode=True if using a pixel-based classifier!!'", ")", "del", "preds"...
[ 1374, 4 ]
[ 1388, 20 ]
python
en
['en', 'error', 'th']
False
ConcatClassifier.forward
(self, preds, pixs)
Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (Bx1)
Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (Bx1)
def forward(self, preds, pixs): """ Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (Bx1) """ del pixs # Concatenate over the time dimension preds_flat = preds.view...
[ "def", "forward", "(", "self", ",", "preds", ",", "pixs", ")", ":", "del", "pixs", "# Concatenate over the time dimension", "preds_flat", "=", "preds", ".", "view", "(", "preds", ".", "shape", "[", "0", "]", ",", "1", ",", "1", ",", "-", "1", ",", "p...
[ 1397, 4 ]
[ 1410, 66 ]
python
en
['en', 'error', 'th']
False
ConvConcatClassifier.forward
(self, preds, pixs)
Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (Bx1)
Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (Bx1)
def forward(self, preds, pixs): """ Run the classifier on the predictions. Args: preds: (BxTx1xDxH'xW') pixs: (BxTx1xDxHxW) Retuns: solved: (Bx1) """ assert preds.shape[1] == pixs.shape[1], ( 'Must pass in run_decode=True if...
[ "def", "forward", "(", "self", ",", "preds", ",", "pixs", ")", ":", "assert", "preds", ".", "shape", "[", "1", "]", "==", "pixs", ".", "shape", "[", "1", "]", ",", "(", "'Must pass in run_decode=True if using a pixel-based classifier!!'", ")", "del", "preds"...
[ 1421, 4 ]
[ 1435, 20 ]
python
en
['en', 'error', 'th']
False
TrivialInteractor.forward
(cls, feat)
Args: feat: (B, T, Nobj, C, H', W') Returns: feat as is
Args: feat: (B, T, Nobj, C, H', W') Returns: feat as is
def forward(cls, feat): """ Args: feat: (B, T, Nobj, C, H', W') Returns: feat as is """ return feat
[ "def", "forward", "(", "cls", ",", "feat", ")", ":", "return", "feat" ]
[ 1445, 4 ]
[ 1452, 19 ]
python
en
['en', 'error', 'th']
False
TxEncoder.__init__
(self, in_dim, nheads, nlayers, maintain_dim=False)
Args: maintain_dim (bool): If true, it maps the final output to the same dimensionality as the input
Args: maintain_dim (bool): If true, it maps the final output to the same dimensionality as the input
def __init__(self, in_dim, nheads, nlayers, maintain_dim=False): """ Args: maintain_dim (bool): If true, it maps the final output to the same dimensionality as the input """ super().__init__() # Very basic position encoding self.loc_embed = nn....
[ "def", "__init__", "(", "self", ",", "in_dim", ",", "nheads", ",", "nlayers", ",", "maintain_dim", "=", "False", ")", ":", "super", "(", ")", ".", "__init__", "(", ")", "# Very basic position encoding", "self", ".", "loc_embed", "=", "nn", ".", "Sequential...
[ 1457, 4 ]
[ 1478, 37 ]
python
en
['en', 'error', 'th']
False
TxEncoder.forward
(self, feat)
Args: feat: (B, T, C) Returns: Same shape as input
Args: feat: (B, T, C) Returns: Same shape as input
def forward(self, feat): """ Args: feat: (B, T, C) Returns: Same shape as input """ # Add a location embedding (over time), since time axis will flatten loc_embedding = self.loc_embed( torch.arange(feat.shape[1], ...
[ "def", "forward", "(", "self", ",", "feat", ")", ":", "# Add a location embedding (over time), since time axis will flatten", "loc_embedding", "=", "self", ".", "loc_embed", "(", "torch", ".", "arange", "(", "feat", ".", "shape", "[", "1", "]", ",", "device", "=...
[ 1480, 4 ]
[ 1501, 71 ]
python
en
['en', 'error', 'th']
False
TxInteractor.forward
(self, feat)
Args: feat: (B, T, Nobj, C, H', W') Returns: Same shape as input
Args: feat: (B, T, Nobj, C, H', W') Returns: Same shape as input
def forward(self, feat): """ Args: feat: (B, T, Nobj, C, H', W') Returns: Same shape as input """ # Mean reduce the spatial dimensions for tx, then add it back to the # original feature as a residual connection feat_spat_mean = torch.mean(f...
[ "def", "forward", "(", "self", ",", "feat", ")", ":", "# Mean reduce the spatial dimensions for tx, then add it back to the", "# original feature as a residual connection", "feat_spat_mean", "=", "torch", ".", "mean", "(", "feat", ",", "dim", "=", "[", "-", "1", ",", ...
[ 1511, 4 ]
[ 1525, 29 ]
python
en
['en', 'error', 'th']
False
TxSpatialAttention.forward
(self, feat)
Args: feats (B, T, Nobj, D, H', W')
Args: feats (B, T, Nobj, D, H', W')
def forward(self, feat): """ Args: feats (B, T, Nobj, D, H', W') """ feat_flat = torch.flatten(torch.flatten(feat, 0, 2), -2, -1) feat_att = self.tx_enc(feat_flat.transpose(1, 2)).transpose(1, 2) return feat_att.view(feat.shape)
[ "def", "forward", "(", "self", ",", "feat", ")", ":", "feat_flat", "=", "torch", ".", "flatten", "(", "torch", ".", "flatten", "(", "feat", ",", "0", ",", "2", ")", ",", "-", "2", ",", "-", "1", ")", "feat_att", "=", "self", ".", "tx_enc", "(",...
[ 1542, 4 ]
[ 1549, 40 ]
python
en
['en', 'error', 'th']
False
Fwd.__init__
(self, agent_cfg)
Args: dyn_type: The type of dynamics model to use. dyn_n: Number of previous features used for prediction.
Args: dyn_type: The type of dynamics model to use. dyn_n: Number of previous features used for prediction.
def __init__(self, agent_cfg): """ Args: dyn_type: The type of dynamics model to use. dyn_n: Number of previous features used for prediction. """ super().__init__() # The image embedding model self.preproc = VideoPreprocessor(agent_cfg) sel...
[ "def", "__init__", "(", "self", ",", "agent_cfg", ")", ":", "super", "(", ")", ".", "__init__", "(", ")", "# The image embedding model", "self", ".", "preproc", "=", "VideoPreprocessor", "(", "agent_cfg", ")", "self", ".", "enc", "=", "hydra", ".", "utils"...
[ 1554, 4 ]
[ 1581, 75 ]
python
en
['en', 'error', 'th']
False
Fwd._forward_dyn
(self, feats, vids, n_fwd_times, need_intermediate=False)
Args: feats: (BxT_histxNobjxDxH'xW') vids: (BxT_histxCxHxW) The video corresponding to the feats, some dyn models might use them. n_fwd_times: Number of times to run the fwd model on the last frames need_intermediate: If true, give all the interme...
Args: feats: (BxT_histxNobjxDxH'xW') vids: (BxT_histxCxHxW) The video corresponding to the feats, some dyn models might use them. n_fwd_times: Number of times to run the fwd model on the last frames need_intermediate: If true, give all the interme...
def _forward_dyn(self, feats, vids, n_fwd_times, need_intermediate=False): """ Args: feats: (BxT_histxNobjxDxH'xW') vids: (BxT_histxCxHxW) The video corresponding to the feats, some dyn models might use them. n_fwd_times: Number of times to run the fwd...
[ "def", "_forward_dyn", "(", "self", ",", "feats", ",", "vids", ",", "n_fwd_times", ",", "need_intermediate", "=", "False", ")", ":", "all_preds", "=", "[", "]", "all_pixs", "=", "[", "]", "all_addl_losses", "=", "[", "]", "if", "n_fwd_times", "==", "0", ...
[ 1590, 4 ]
[ 1637, 51 ]
python
en
['en', 'error', 'th']
False
Fwd._slice_for_dyn
(self, features_batched, n_hist_frames, nslices=-1)
Args: features_batched: BxTx.... can deal with any following dimensions, typically it is (BxTxNobjxDxH'xW') n_hist_frames (int): Number of frames to use as history nslices (int): If -1, make as many slices of the training data as possible. If ...
Args: features_batched: BxTx.... can deal with any following dimensions, typically it is (BxTxNobjxDxH'xW') n_hist_frames (int): Number of frames to use as history nslices (int): If -1, make as many slices of the training data as possible. If ...
def _slice_for_dyn(self, features_batched, n_hist_frames, nslices=-1): """ Args: features_batched: BxTx.... can deal with any following dimensions, typically it is (BxTxNobjxDxH'xW') n_hist_frames (int): Number of frames to use as history nslices (int)...
[ "def", "_slice_for_dyn", "(", "self", ",", "features_batched", ",", "n_hist_frames", ",", "nslices", "=", "-", "1", ")", ":", "clip_hist", "=", "[", "]", "assert", "features_batched", ".", "shape", "[", "1", "]", ">=", "n_hist_frames", "for", "i", "in", ...
[ 1639, 4 ]
[ 1660, 24 ]
python
en
['en', 'error', 'th']
False
Fwd._forward_dec
(self, feats, pixels)
Args: feats: List of features (BxD) from the dynamics prediction stage, one for each time step predicted. pixels: List of corresponding pixels from the dynamics model. The dyn model may or may not actually generate new pixels.
Args: feats: List of features (BxD) from the dynamics prediction stage, one for each time step predicted. pixels: List of corresponding pixels from the dynamics model. The dyn model may or may not actually generate new pixels.
def _forward_dec(self, feats, pixels): """ Args: feats: List of features (BxD) from the dynamics prediction stage, one for each time step predicted. pixels: List of corresponding pixels from the dynamics model. The dyn model may or may not actually...
[ "def", "_forward_dec", "(", "self", ",", "feats", ",", "pixels", ")", ":", "return", "[", "self", ".", "dec", "(", "feat", ",", "pix", ")", "for", "feat", ",", "pix", "in", "zip", "(", "feats", ",", "pixels", ")", "]" ]
[ 1662, 4 ]
[ 1670, 72 ]
python
en
['en', 'error', 'th']
False
Fwd.cswm_loss
(self, pred, gt, hinge=1.0)
The energy based contrastive loss. Args: pred (BxNobjxDxH'xW') gt (BxNobjxDxH'xW') From https://github.com/tkipf/c-swm/blob/master/modules.py#L94
The energy based contrastive loss. Args: pred (BxNobjxDxH'xW') gt (BxNobjxDxH'xW') From https://github.com/tkipf/c-swm/blob/master/modules.py#L94
def cswm_loss(self, pred, gt, hinge=1.0): """ The energy based contrastive loss. Args: pred (BxNobjxDxH'xW') gt (BxNobjxDxH'xW') From https://github.com/tkipf/c-swm/blob/master/modules.py#L94 """ pred = pred.view(pred.shape[:2] + (-1, )) ...
[ "def", "cswm_loss", "(", "self", ",", "pred", ",", "gt", ",", "hinge", "=", "1.0", ")", ":", "pred", "=", "pred", ".", "view", "(", "pred", ".", "shape", "[", ":", "2", "]", "+", "(", "-", "1", ",", ")", ")", "gt", "=", "gt", ".", "view", ...
[ 1673, 4 ]
[ 1701, 34 ]
python
en
['en', 'error', 'th']
False
Fwd.autoencoder_loss
(self, pix, latent, autoenc_loss_ratio)
Runs a random portion of the actual frames through decoder to incur a loss to encourage the intermediate representation to learn a good autoencoder as well. Random fraction only for compute reasons. Ideally would run every frame (ratio = 1) Args: pix (B, T, H, W): Ac...
Runs a random portion of the actual frames through decoder to incur a loss to encourage the intermediate representation to learn a good autoencoder as well. Random fraction only for compute reasons. Ideally would run every frame (ratio = 1) Args: pix (B, T, H, W): Ac...
def autoencoder_loss(self, pix, latent, autoenc_loss_ratio): """ Runs a random portion of the actual frames through decoder to incur a loss to encourage the intermediate representation to learn a good autoencoder as well. Random fraction only for compute reasons. Ideally would ru...
[ "def", "autoencoder_loss", "(", "self", ",", "pix", ",", "latent", ",", "autoenc_loss_ratio", ")", ":", "# Flatten the Batch and time dimension to get all the frames", "pix_flat", "=", "torch", ".", "flatten", "(", "pix", ",", "0", ",", "1", ")", "latent_flat", "=...
[ 1708, 4 ]
[ 1737, 36 ]
python
en
['en', 'error', 'th']
False
Fwd.solved_or_not_loss
(self, clip_preds_solved, vid_is_solved)
Repeat the is_solved to as many times the batch was repeated to get the class label at each forward prediction Args: clip_preds_solved (B',) vid_is_solved (B,) B and B' might be different but B' must be a multiple of B, since it happens when n...
Repeat the is_solved to as many times the batch was repeated to get the class label at each forward prediction Args: clip_preds_solved (B',) vid_is_solved (B,) B and B' might be different but B' must be a multiple of B, since it happens when n...
def solved_or_not_loss(self, clip_preds_solved, vid_is_solved): """ Repeat the is_solved to as many times the batch was repeated to get the class label at each forward prediction Args: clip_preds_solved (B',) vid_is_solved (B,) B and B' might be differ...
[ "def", "solved_or_not_loss", "(", "self", ",", "clip_preds_solved", ",", "vid_is_solved", ")", ":", "assert", "clip_preds_solved", ".", "shape", "[", "0", "]", "%", "vid_is_solved", ".", "shape", "[", "0", "]", "==", "0", "return", "{", "'ce'", ":", "self"...
[ 1739, 4 ]
[ 1758, 9 ]
python
en
['en', 'error', 'th']
False
Fwd._compute_losses
(self, clip_pred, clip_pred_pix, vid_feat, vid, n_hist_frames, n_fwd_times)
Compute all losses possible.
Compute all losses possible.
def _compute_losses(self, clip_pred, clip_pred_pix, vid_feat, vid, n_hist_frames, n_fwd_times): """ Compute all losses possible. """ dummy_loss = torch.Tensor([-1]).to(clip_pred.device) losses = {} # NCE and pixel loss # find the GT for eac...
[ "def", "_compute_losses", "(", "self", ",", "clip_pred", ",", "clip_pred_pix", ",", "vid_feat", ",", "vid", ",", "n_hist_frames", ",", "n_fwd_times", ")", ":", "dummy_loss", "=", "torch", ".", "Tensor", "(", "[", "-", "1", "]", ")", ".", "to", "(", "cl...
[ 1762, 4 ]
[ 1814, 21 ]
python
en
['en', 'error', 'th']
False
Fwd._cls
(self, feat_hist, pix_hist, feat_preds, pix_preds)
Wrapper around the classifier, collates all the input frames/features and predicted future frames/features. The images, features are already summed over the objects Args: feat_hist: (B, T, C, H', W') pix_hist: (B, T, 7, H, W) feat_preds [list ...
Wrapper around the classifier, collates all the input frames/features and predicted future frames/features. The images, features are already summed over the objects Args: feat_hist: (B, T, C, H', W') pix_hist: (B, T, 7, H, W) feat_preds [list ...
def _cls(self, feat_hist, pix_hist, feat_preds, pix_preds): """ Wrapper around the classifier, collates all the input frames/features and predicted future frames/features. The images, features are already summed over the objects Args: feat_hist: (B, T, C, H', ...
[ "def", "_cls", "(", "self", ",", "feat_hist", ",", "pix_hist", ",", "feat_preds", ",", "pix_preds", ")", ":", "feats_combined", "=", "feat_hist", "if", "feat_preds", "is", "not", "None", "and", "len", "(", "feat_preds", ")", ">", "0", ":", "feats_combined"...
[ 1816, 4 ]
[ 1854, 60 ]
python
en
['en', 'error', 'th']
False
Fwd.forward
(self, vid, vid_is_solved, n_hist_frames=3, n_fwd_times=1, n_fwd_times_incur_loss=999999, run_decode=False, compute_losses=False, need_intermediate=False, autoenc_loss_ratio=0....
Args: vid: (BxTxNobjxHxW) The input video vid_is_solved: (Bx1) Whether the video is solved in the end of not. Could be None at test time. n_hist_frames: (int) Number of frames to use as history for prediction n_fwd_times: (int) How...
Args: vid: (BxTxNobjxHxW) The input video vid_is_solved: (Bx1) Whether the video is solved in the end of not. Could be None at test time. n_hist_frames: (int) Number of frames to use as history for prediction n_fwd_times: (int) How...
def forward(self, vid, vid_is_solved, n_hist_frames=3, n_fwd_times=1, n_fwd_times_incur_loss=999999, run_decode=False, compute_losses=False, need_intermediate=False, autoenc_lo...
[ "def", "forward", "(", "self", ",", "vid", ",", "vid_is_solved", ",", "n_hist_frames", "=", "3", ",", "n_fwd_times", "=", "1", ",", "n_fwd_times_incur_loss", "=", "999999", ",", "run_decode", "=", "False", ",", "compute_losses", "=", "False", ",", "need_inte...
[ 1856, 4 ]
[ 1959, 36 ]
python
en
['en', 'error', 'th']
False
block_output_tokens
(blocks, true_tokens)
blocks = the output from blockify true_tokens = a list of true tokens
blocks = the output from blockify true_tokens = a list of true tokens
def block_output_tokens(blocks, true_tokens): """ blocks = the output from blockify true_tokens = a list of true tokens """ assert len(blocks) == len(true_tokens) for k in range_(len(blocks)): block_tokens = re.split(r"\s+", blocks[k].text.strip()) assert block_tokens == true_tok...
[ "def", "block_output_tokens", "(", "blocks", ",", "true_tokens", ")", ":", "assert", "len", "(", "blocks", ")", "==", "len", "(", "true_tokens", ")", "for", "k", "in", "range_", "(", "len", "(", "blocks", ")", ")", ":", "block_tokens", "=", "re", ".", ...
[ 21, 0 ]
[ 29, 45 ]
python
en
['en', 'error', 'th']
False
TestBlockifier.test_lxml_error
(self)
tests the case where lxml raises an error during parsing also handles case where lxml returns None for the tree
tests the case where lxml raises an error during parsing
def test_lxml_error(self): """tests the case where lxml raises an error during parsing also handles case where lxml returns None for the tree""" # this raises an error in parsing with pytest.raises(BlockifyError): Blockifier.blockify("") # this returns None in lxml ...
[ "def", "test_lxml_error", "(", "self", ")", ":", "# this raises an error in parsing", "with", "pytest", ".", "raises", "(", "BlockifyError", ")", ":", "Blockifier", ".", "blockify", "(", "\"\"", ")", "# this returns None in lxml", "assert", "etree", ".", "fromstring...
[ 48, 4 ]
[ 58, 39 ]
python
en
['en', 'en', 'en']
True
TestBlockifier.test_very_simple
(self)
test_very_simple
test_very_simple
def test_very_simple(self): """test_very_simple""" s = """<div>some text <script> skip this </script> more text here </div>""" blocks = Blockifier.blockify(s) block_output_tokens(blocks, [['some', 'text', 'more', 'text', 'here']])
[ "def", "test_very_simple", "(", "self", ")", ":", "s", "=", "\"\"\"<div>some text\n <script> skip this </script>\n more text here\n </div>\"\"\"", "blocks", "=", "Blockifier", ".", "blockify", "(", "s", ")", "block_output_tokens",...
[ 60, 4 ]
[ 67, 79 ]
python
en
['en', 'en', 'en']
False