partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | DjangoStorageAdapter.create_many | Creates multiple statement entries. | chatterbot/storage/django_storage.py | def create_many(self, statements):
"""
Creates multiple statement entries.
"""
Statement = self.get_model('statement')
Tag = self.get_model('tag')
tag_cache = {}
for statement in statements:
statement_data = statement.serialize()
tag_dat... | def create_many(self, statements):
"""
Creates multiple statement entries.
"""
Statement = self.get_model('statement')
Tag = self.get_model('tag')
tag_cache = {}
for statement in statements:
statement_data = statement.serialize()
tag_dat... | [
"Creates",
"multiple",
"statement",
"entries",
"."
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/storage/django_storage.py#L123-L157 | [
"def",
"create_many",
"(",
"self",
",",
"statements",
")",
":",
"Statement",
"=",
"self",
".",
"get_model",
"(",
"'statement'",
")",
"Tag",
"=",
"self",
".",
"get_model",
"(",
"'tag'",
")",
"tag_cache",
"=",
"{",
"}",
"for",
"statement",
"in",
"statement... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | DjangoStorageAdapter.update | Update the provided statement. | chatterbot/storage/django_storage.py | def update(self, statement):
"""
Update the provided statement.
"""
Statement = self.get_model('statement')
Tag = self.get_model('tag')
if hasattr(statement, 'id'):
statement.save()
else:
statement = Statement.objects.create(
... | def update(self, statement):
"""
Update the provided statement.
"""
Statement = self.get_model('statement')
Tag = self.get_model('tag')
if hasattr(statement, 'id'):
statement.save()
else:
statement = Statement.objects.create(
... | [
"Update",
"the",
"provided",
"statement",
"."
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/storage/django_storage.py#L159-L183 | [
"def",
"update",
"(",
"self",
",",
"statement",
")",
":",
"Statement",
"=",
"self",
".",
"get_model",
"(",
"'statement'",
")",
"Tag",
"=",
"self",
".",
"get_model",
"(",
"'tag'",
")",
"if",
"hasattr",
"(",
"statement",
",",
"'id'",
")",
":",
"statement... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | DjangoStorageAdapter.get_random | Returns a random statement from the database | chatterbot/storage/django_storage.py | def get_random(self):
"""
Returns a random statement from the database
"""
Statement = self.get_model('statement')
statement = Statement.objects.order_by('?').first()
if statement is None:
raise self.EmptyDatabaseException()
return statement | def get_random(self):
"""
Returns a random statement from the database
"""
Statement = self.get_model('statement')
statement = Statement.objects.order_by('?').first()
if statement is None:
raise self.EmptyDatabaseException()
return statement | [
"Returns",
"a",
"random",
"statement",
"from",
"the",
"database"
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/storage/django_storage.py#L185-L196 | [
"def",
"get_random",
"(",
"self",
")",
":",
"Statement",
"=",
"self",
".",
"get_model",
"(",
"'statement'",
")",
"statement",
"=",
"Statement",
".",
"objects",
".",
"order_by",
"(",
"'?'",
")",
".",
"first",
"(",
")",
"if",
"statement",
"is",
"None",
"... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | DjangoStorageAdapter.remove | Removes the statement that matches the input text.
Removes any responses from statements if the response text matches the
input text. | chatterbot/storage/django_storage.py | def remove(self, statement_text):
"""
Removes the statement that matches the input text.
Removes any responses from statements if the response text matches the
input text.
"""
Statement = self.get_model('statement')
statements = Statement.objects.filter(text=stat... | def remove(self, statement_text):
"""
Removes the statement that matches the input text.
Removes any responses from statements if the response text matches the
input text.
"""
Statement = self.get_model('statement')
statements = Statement.objects.filter(text=stat... | [
"Removes",
"the",
"statement",
"that",
"matches",
"the",
"input",
"text",
".",
"Removes",
"any",
"responses",
"from",
"statements",
"if",
"the",
"response",
"text",
"matches",
"the",
"input",
"text",
"."
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/storage/django_storage.py#L198-L208 | [
"def",
"remove",
"(",
"self",
",",
"statement_text",
")",
":",
"Statement",
"=",
"self",
".",
"get_model",
"(",
"'statement'",
")",
"statements",
"=",
"Statement",
".",
"objects",
".",
"filter",
"(",
"text",
"=",
"statement_text",
")",
"statements",
".",
"... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | DjangoStorageAdapter.drop | Remove all data from the database. | chatterbot/storage/django_storage.py | def drop(self):
"""
Remove all data from the database.
"""
Statement = self.get_model('statement')
Tag = self.get_model('tag')
Statement.objects.all().delete()
Tag.objects.all().delete() | def drop(self):
"""
Remove all data from the database.
"""
Statement = self.get_model('statement')
Tag = self.get_model('tag')
Statement.objects.all().delete()
Tag.objects.all().delete() | [
"Remove",
"all",
"data",
"from",
"the",
"database",
"."
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/storage/django_storage.py#L210-L218 | [
"def",
"drop",
"(",
"self",
")",
":",
"Statement",
"=",
"self",
".",
"get_model",
"(",
"'statement'",
")",
"Tag",
"=",
"self",
".",
"get_model",
"(",
"'tag'",
")",
"Statement",
".",
"objects",
".",
"all",
"(",
")",
".",
"delete",
"(",
")",
"Tag",
"... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | clean_whitespace | Remove any consecutive whitespace characters from the statement text. | chatterbot/preprocessors.py | def clean_whitespace(statement):
"""
Remove any consecutive whitespace characters from the statement text.
"""
import re
# Replace linebreaks and tabs with spaces
statement.text = statement.text.replace('\n', ' ').replace('\r', ' ').replace('\t', ' ')
# Remove any leeding or trailing white... | def clean_whitespace(statement):
"""
Remove any consecutive whitespace characters from the statement text.
"""
import re
# Replace linebreaks and tabs with spaces
statement.text = statement.text.replace('\n', ' ').replace('\r', ' ').replace('\t', ' ')
# Remove any leeding or trailing white... | [
"Remove",
"any",
"consecutive",
"whitespace",
"characters",
"from",
"the",
"statement",
"text",
"."
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/preprocessors.py#L6-L21 | [
"def",
"clean_whitespace",
"(",
"statement",
")",
":",
"import",
"re",
"# Replace linebreaks and tabs with spaces",
"statement",
".",
"text",
"=",
"statement",
".",
"text",
".",
"replace",
"(",
"'\\n'",
",",
"' '",
")",
".",
"replace",
"(",
"'\\r'",
",",
"' '"... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | unescape_html | Convert escaped html characters into unescaped html characters.
For example: "<b>" becomes "<b>". | chatterbot/preprocessors.py | def unescape_html(statement):
"""
Convert escaped html characters into unescaped html characters.
For example: "<b>" becomes "<b>".
"""
import html
statement.text = html.unescape(statement.text)
return statement | def unescape_html(statement):
"""
Convert escaped html characters into unescaped html characters.
For example: "<b>" becomes "<b>".
"""
import html
statement.text = html.unescape(statement.text)
return statement | [
"Convert",
"escaped",
"html",
"characters",
"into",
"unescaped",
"html",
"characters",
".",
"For",
"example",
":",
"<",
";",
"b>",
";",
"becomes",
"<b",
">",
"."
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/preprocessors.py#L24-L33 | [
"def",
"unescape_html",
"(",
"statement",
")",
":",
"import",
"html",
"statement",
".",
"text",
"=",
"html",
".",
"unescape",
"(",
"statement",
".",
"text",
")",
"return",
"statement"
] | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | convert_to_ascii | Converts unicode characters to ASCII character equivalents.
For example: "på fédéral" becomes "pa federal". | chatterbot/preprocessors.py | def convert_to_ascii(statement):
"""
Converts unicode characters to ASCII character equivalents.
For example: "på fédéral" becomes "pa federal".
"""
import unicodedata
text = unicodedata.normalize('NFKD', statement.text)
text = text.encode('ascii', 'ignore').decode('utf-8')
statement.t... | def convert_to_ascii(statement):
"""
Converts unicode characters to ASCII character equivalents.
For example: "på fédéral" becomes "pa federal".
"""
import unicodedata
text = unicodedata.normalize('NFKD', statement.text)
text = text.encode('ascii', 'ignore').decode('utf-8')
statement.t... | [
"Converts",
"unicode",
"characters",
"to",
"ASCII",
"character",
"equivalents",
".",
"For",
"example",
":",
"på",
"fédéral",
"becomes",
"pa",
"federal",
"."
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/preprocessors.py#L36-L47 | [
"def",
"convert_to_ascii",
"(",
"statement",
")",
":",
"import",
"unicodedata",
"text",
"=",
"unicodedata",
".",
"normalize",
"(",
"'NFKD'",
",",
"statement",
".",
"text",
")",
"text",
"=",
"text",
".",
"encode",
"(",
"'ascii'",
",",
"'ignore'",
")",
".",
... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | convert_string_to_number | Convert strings to numbers | chatterbot/parsing.py | def convert_string_to_number(value):
"""
Convert strings to numbers
"""
if value is None:
return 1
if isinstance(value, int):
return value
if value.isdigit():
return int(value)
num_list = map(lambda s: NUMBERS[s], re.findall(numbers + '+', value.lower()))
return s... | def convert_string_to_number(value):
"""
Convert strings to numbers
"""
if value is None:
return 1
if isinstance(value, int):
return value
if value.isdigit():
return int(value)
num_list = map(lambda s: NUMBERS[s], re.findall(numbers + '+', value.lower()))
return s... | [
"Convert",
"strings",
"to",
"numbers"
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/parsing.py#L506-L517 | [
"def",
"convert_string_to_number",
"(",
"value",
")",
":",
"if",
"value",
"is",
"None",
":",
"return",
"1",
"if",
"isinstance",
"(",
"value",
",",
"int",
")",
":",
"return",
"value",
"if",
"value",
".",
"isdigit",
"(",
")",
":",
"return",
"int",
"(",
... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | convert_time_to_hour_minute | Convert time to hour, minute | chatterbot/parsing.py | def convert_time_to_hour_minute(hour, minute, convention):
"""
Convert time to hour, minute
"""
if hour is None:
hour = 0
if minute is None:
minute = 0
if convention is None:
convention = 'am'
hour = int(hour)
minute = int(minute)
if convention.lower() == 'p... | def convert_time_to_hour_minute(hour, minute, convention):
"""
Convert time to hour, minute
"""
if hour is None:
hour = 0
if minute is None:
minute = 0
if convention is None:
convention = 'am'
hour = int(hour)
minute = int(minute)
if convention.lower() == 'p... | [
"Convert",
"time",
"to",
"hour",
"minute"
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/parsing.py#L520-L537 | [
"def",
"convert_time_to_hour_minute",
"(",
"hour",
",",
"minute",
",",
"convention",
")",
":",
"if",
"hour",
"is",
"None",
":",
"hour",
"=",
"0",
"if",
"minute",
"is",
"None",
":",
"minute",
"=",
"0",
"if",
"convention",
"is",
"None",
":",
"convention",
... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | date_from_quarter | Extract date from quarter of a year | chatterbot/parsing.py | def date_from_quarter(base_date, ordinal, year):
"""
Extract date from quarter of a year
"""
interval = 3
month_start = interval * (ordinal - 1)
if month_start < 0:
month_start = 9
month_end = month_start + interval
if month_start == 0:
month_start = 1
return [
... | def date_from_quarter(base_date, ordinal, year):
"""
Extract date from quarter of a year
"""
interval = 3
month_start = interval * (ordinal - 1)
if month_start < 0:
month_start = 9
month_end = month_start + interval
if month_start == 0:
month_start = 1
return [
... | [
"Extract",
"date",
"from",
"quarter",
"of",
"a",
"year"
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/parsing.py#L540-L554 | [
"def",
"date_from_quarter",
"(",
"base_date",
",",
"ordinal",
",",
"year",
")",
":",
"interval",
"=",
"3",
"month_start",
"=",
"interval",
"*",
"(",
"ordinal",
"-",
"1",
")",
"if",
"month_start",
"<",
"0",
":",
"month_start",
"=",
"9",
"month_end",
"=",
... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | date_from_relative_day | Converts relative day to time
Ex: this tuesday, last tuesday | chatterbot/parsing.py | def date_from_relative_day(base_date, time, dow):
"""
Converts relative day to time
Ex: this tuesday, last tuesday
"""
# Reset date to start of the day
base_date = datetime(base_date.year, base_date.month, base_date.day)
time = time.lower()
dow = dow.lower()
if time == 'this' or time... | def date_from_relative_day(base_date, time, dow):
"""
Converts relative day to time
Ex: this tuesday, last tuesday
"""
# Reset date to start of the day
base_date = datetime(base_date.year, base_date.month, base_date.day)
time = time.lower()
dow = dow.lower()
if time == 'this' or time... | [
"Converts",
"relative",
"day",
"to",
"time",
"Ex",
":",
"this",
"tuesday",
"last",
"tuesday"
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/parsing.py#L557-L577 | [
"def",
"date_from_relative_day",
"(",
"base_date",
",",
"time",
",",
"dow",
")",
":",
"# Reset date to start of the day",
"base_date",
"=",
"datetime",
"(",
"base_date",
".",
"year",
",",
"base_date",
".",
"month",
",",
"base_date",
".",
"day",
")",
"time",
"=... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | date_from_relative_week_year | Converts relative day to time
Eg. this tuesday, last tuesday | chatterbot/parsing.py | def date_from_relative_week_year(base_date, time, dow, ordinal=1):
"""
Converts relative day to time
Eg. this tuesday, last tuesday
"""
# If there is an ordinal (next 3 weeks) => return a start and end range
# Reset date to start of the day
relative_date = datetime(base_date.year, base_date.... | def date_from_relative_week_year(base_date, time, dow, ordinal=1):
"""
Converts relative day to time
Eg. this tuesday, last tuesday
"""
# If there is an ordinal (next 3 weeks) => return a start and end range
# Reset date to start of the day
relative_date = datetime(base_date.year, base_date.... | [
"Converts",
"relative",
"day",
"to",
"time",
"Eg",
".",
"this",
"tuesday",
"last",
"tuesday"
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/parsing.py#L580-L636 | [
"def",
"date_from_relative_week_year",
"(",
"base_date",
",",
"time",
",",
"dow",
",",
"ordinal",
"=",
"1",
")",
":",
"# If there is an ordinal (next 3 weeks) => return a start and end range",
"# Reset date to start of the day",
"relative_date",
"=",
"datetime",
"(",
"base_da... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | date_from_adverb | Convert Day adverbs to dates
Tomorrow => Date
Today => Date | chatterbot/parsing.py | def date_from_adverb(base_date, name):
"""
Convert Day adverbs to dates
Tomorrow => Date
Today => Date
"""
# Reset date to start of the day
adverb_date = datetime(base_date.year, base_date.month, base_date.day)
if name == 'today' or name == 'tonite' or name == 'tonight':
return a... | def date_from_adverb(base_date, name):
"""
Convert Day adverbs to dates
Tomorrow => Date
Today => Date
"""
# Reset date to start of the day
adverb_date = datetime(base_date.year, base_date.month, base_date.day)
if name == 'today' or name == 'tonite' or name == 'tonight':
return a... | [
"Convert",
"Day",
"adverbs",
"to",
"dates",
"Tomorrow",
"=",
">",
"Date",
"Today",
"=",
">",
"Date"
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/parsing.py#L639-L652 | [
"def",
"date_from_adverb",
"(",
"base_date",
",",
"name",
")",
":",
"# Reset date to start of the day",
"adverb_date",
"=",
"datetime",
"(",
"base_date",
".",
"year",
",",
"base_date",
".",
"month",
",",
"base_date",
".",
"day",
")",
"if",
"name",
"==",
"'toda... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | date_from_duration | Find dates from duration
Eg: 20 days from now
Currently does not support strings like "20 days from last monday". | chatterbot/parsing.py | def date_from_duration(base_date, number_as_string, unit, duration, base_time=None):
"""
Find dates from duration
Eg: 20 days from now
Currently does not support strings like "20 days from last monday".
"""
# Check if query is `2 days before yesterday` or `day before yesterday`
if base_time ... | def date_from_duration(base_date, number_as_string, unit, duration, base_time=None):
"""
Find dates from duration
Eg: 20 days from now
Currently does not support strings like "20 days from last monday".
"""
# Check if query is `2 days before yesterday` or `day before yesterday`
if base_time ... | [
"Find",
"dates",
"from",
"duration",
"Eg",
":",
"20",
"days",
"from",
"now",
"Currently",
"does",
"not",
"support",
"strings",
"like",
"20",
"days",
"from",
"last",
"monday",
"."
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/parsing.py#L655-L682 | [
"def",
"date_from_duration",
"(",
"base_date",
",",
"number_as_string",
",",
"unit",
",",
"duration",
",",
"base_time",
"=",
"None",
")",
":",
"# Check if query is `2 days before yesterday` or `day before yesterday`",
"if",
"base_time",
"is",
"not",
"None",
":",
"base_d... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | this_week_day | Finds coming weekday | chatterbot/parsing.py | def this_week_day(base_date, weekday):
"""
Finds coming weekday
"""
day_of_week = base_date.weekday()
# If today is Tuesday and the query is `this monday`
# We should output the next_week monday
if day_of_week > weekday:
return next_week_day(base_date, weekday)
start_of_this_week... | def this_week_day(base_date, weekday):
"""
Finds coming weekday
"""
day_of_week = base_date.weekday()
# If today is Tuesday and the query is `this monday`
# We should output the next_week monday
if day_of_week > weekday:
return next_week_day(base_date, weekday)
start_of_this_week... | [
"Finds",
"coming",
"weekday"
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/parsing.py#L685-L698 | [
"def",
"this_week_day",
"(",
"base_date",
",",
"weekday",
")",
":",
"day_of_week",
"=",
"base_date",
".",
"weekday",
"(",
")",
"# If today is Tuesday and the query is `this monday`",
"# We should output the next_week monday",
"if",
"day_of_week",
">",
"weekday",
":",
"ret... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | previous_week_day | Finds previous weekday | chatterbot/parsing.py | def previous_week_day(base_date, weekday):
"""
Finds previous weekday
"""
day = base_date - timedelta(days=1)
while day.weekday() != weekday:
day = day - timedelta(days=1)
return day | def previous_week_day(base_date, weekday):
"""
Finds previous weekday
"""
day = base_date - timedelta(days=1)
while day.weekday() != weekday:
day = day - timedelta(days=1)
return day | [
"Finds",
"previous",
"weekday"
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/parsing.py#L701-L708 | [
"def",
"previous_week_day",
"(",
"base_date",
",",
"weekday",
")",
":",
"day",
"=",
"base_date",
"-",
"timedelta",
"(",
"days",
"=",
"1",
")",
"while",
"day",
".",
"weekday",
"(",
")",
"!=",
"weekday",
":",
"day",
"=",
"day",
"-",
"timedelta",
"(",
"... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | next_week_day | Finds next weekday | chatterbot/parsing.py | def next_week_day(base_date, weekday):
"""
Finds next weekday
"""
day_of_week = base_date.weekday()
end_of_this_week = base_date + timedelta(days=6 - day_of_week)
day = end_of_this_week + timedelta(days=1)
while day.weekday() != weekday:
day = day + timedelta(days=1)
return day | def next_week_day(base_date, weekday):
"""
Finds next weekday
"""
day_of_week = base_date.weekday()
end_of_this_week = base_date + timedelta(days=6 - day_of_week)
day = end_of_this_week + timedelta(days=1)
while day.weekday() != weekday:
day = day + timedelta(days=1)
return day | [
"Finds",
"next",
"weekday"
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/parsing.py#L711-L720 | [
"def",
"next_week_day",
"(",
"base_date",
",",
"weekday",
")",
":",
"day_of_week",
"=",
"base_date",
".",
"weekday",
"(",
")",
"end_of_this_week",
"=",
"base_date",
"+",
"timedelta",
"(",
"days",
"=",
"6",
"-",
"day_of_week",
")",
"day",
"=",
"end_of_this_we... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | datetime_parsing | Extract datetime objects from a string of text. | chatterbot/parsing.py | def datetime_parsing(text, base_date=datetime.now()):
"""
Extract datetime objects from a string of text.
"""
matches = []
found_array = []
# Find the position in the string
for expression, function in regex:
for match in expression.finditer(text):
matches.append((match.... | def datetime_parsing(text, base_date=datetime.now()):
"""
Extract datetime objects from a string of text.
"""
matches = []
found_array = []
# Find the position in the string
for expression, function in regex:
for match in expression.finditer(text):
matches.append((match.... | [
"Extract",
"datetime",
"objects",
"from",
"a",
"string",
"of",
"text",
"."
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/parsing.py#L723-L746 | [
"def",
"datetime_parsing",
"(",
"text",
",",
"base_date",
"=",
"datetime",
".",
"now",
"(",
")",
")",
":",
"matches",
"=",
"[",
"]",
"found_array",
"=",
"[",
"]",
"# Find the position in the string",
"for",
"expression",
",",
"function",
"in",
"regex",
":",
... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | IndexedTextSearch.search | Search for close matches to the input. Confidence scores for
subsequent results will order of increasing value.
:param input_statement: A statement.
:type input_statement: chatterbot.conversation.Statement
:param **additional_parameters: Additional parameters to be passed
t... | chatterbot/search.py | def search(self, input_statement, **additional_parameters):
"""
Search for close matches to the input. Confidence scores for
subsequent results will order of increasing value.
:param input_statement: A statement.
:type input_statement: chatterbot.conversation.Statement
... | def search(self, input_statement, **additional_parameters):
"""
Search for close matches to the input. Confidence scores for
subsequent results will order of increasing value.
:param input_statement: A statement.
:type input_statement: chatterbot.conversation.Statement
... | [
"Search",
"for",
"close",
"matches",
"to",
"the",
"input",
".",
"Confidence",
"scores",
"for",
"subsequent",
"results",
"will",
"order",
"of",
"increasing",
"value",
"."
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/search.py#L35-L89 | [
"def",
"search",
"(",
"self",
",",
"input_statement",
",",
"*",
"*",
"additional_parameters",
")",
":",
"self",
".",
"chatbot",
".",
"logger",
".",
"info",
"(",
"'Beginning search for close text match'",
")",
"input_search_text",
"=",
"input_statement",
".",
"sear... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | TkinterGUIExample.initialize | Set window layout. | examples/tkinter_gui.py | def initialize(self):
"""
Set window layout.
"""
self.grid()
self.respond = ttk.Button(self, text='Get Response', command=self.get_response)
self.respond.grid(column=0, row=0, sticky='nesw', padx=3, pady=3)
self.usr_input = ttk.Entry(self, state='normal')
... | def initialize(self):
"""
Set window layout.
"""
self.grid()
self.respond = ttk.Button(self, text='Get Response', command=self.get_response)
self.respond.grid(column=0, row=0, sticky='nesw', padx=3, pady=3)
self.usr_input = ttk.Entry(self, state='normal')
... | [
"Set",
"window",
"layout",
"."
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/examples/tkinter_gui.py#L33-L49 | [
"def",
"initialize",
"(",
"self",
")",
":",
"self",
".",
"grid",
"(",
")",
"self",
".",
"respond",
"=",
"ttk",
".",
"Button",
"(",
"self",
",",
"text",
"=",
"'Get Response'",
",",
"command",
"=",
"self",
".",
"get_response",
")",
"self",
".",
"respon... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | TkinterGUIExample.get_response | Get a response from the chatbot and display it. | examples/tkinter_gui.py | def get_response(self):
"""
Get a response from the chatbot and display it.
"""
user_input = self.usr_input.get()
self.usr_input.delete(0, tk.END)
response = self.chatbot.get_response(user_input)
self.conversation['state'] = 'normal'
self.conversation.in... | def get_response(self):
"""
Get a response from the chatbot and display it.
"""
user_input = self.usr_input.get()
self.usr_input.delete(0, tk.END)
response = self.chatbot.get_response(user_input)
self.conversation['state'] = 'normal'
self.conversation.in... | [
"Get",
"a",
"response",
"from",
"the",
"chatbot",
"and",
"display",
"it",
"."
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/examples/tkinter_gui.py#L51-L66 | [
"def",
"get_response",
"(",
"self",
")",
":",
"user_input",
"=",
"self",
".",
"usr_input",
".",
"get",
"(",
")",
"self",
".",
"usr_input",
".",
"delete",
"(",
"0",
",",
"tk",
".",
"END",
")",
"response",
"=",
"self",
".",
"chatbot",
".",
"get_respons... | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | AbstractBaseStatement.add_tags | Add a list of strings to the statement as tags.
(Overrides the method from StatementMixin) | chatterbot/ext/django_chatterbot/abstract_models.py | def add_tags(self, *tags):
"""
Add a list of strings to the statement as tags.
(Overrides the method from StatementMixin)
"""
for _tag in tags:
self.tags.get_or_create(name=_tag) | def add_tags(self, *tags):
"""
Add a list of strings to the statement as tags.
(Overrides the method from StatementMixin)
"""
for _tag in tags:
self.tags.get_or_create(name=_tag) | [
"Add",
"a",
"list",
"of",
"strings",
"to",
"the",
"statement",
"as",
"tags",
".",
"(",
"Overrides",
"the",
"method",
"from",
"StatementMixin",
")"
] | gunthercox/ChatterBot | python | https://github.com/gunthercox/ChatterBot/blob/1a03dcb45cba7bdc24d3db5e750582e0cb1518e2/chatterbot/ext/django_chatterbot/abstract_models.py#L110-L116 | [
"def",
"add_tags",
"(",
"self",
",",
"*",
"tags",
")",
":",
"for",
"_tag",
"in",
"tags",
":",
"self",
".",
"tags",
".",
"get_or_create",
"(",
"name",
"=",
"_tag",
")"
] | 1a03dcb45cba7bdc24d3db5e750582e0cb1518e2 |
train | SvelteComponent | Display svelte components in iPython.
Args:
name: name of svelte component (must match component filename when built)
path: path to compile svelte .js file or source svelte .html file.
(If html file, we try to call svelte and build the file.)
Returns:
A function mapping data to a rendered svelte... | lucid/scratch/web/svelte.py | def SvelteComponent(name, path):
"""Display svelte components in iPython.
Args:
name: name of svelte component (must match component filename when built)
path: path to compile svelte .js file or source svelte .html file.
(If html file, we try to call svelte and build the file.)
Returns:
A func... | def SvelteComponent(name, path):
"""Display svelte components in iPython.
Args:
name: name of svelte component (must match component filename when built)
path: path to compile svelte .js file or source svelte .html file.
(If html file, we try to call svelte and build the file.)
Returns:
A func... | [
"Display",
"svelte",
"components",
"in",
"iPython",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/scratch/web/svelte.py#L43-L68 | [
"def",
"SvelteComponent",
"(",
"name",
",",
"path",
")",
":",
"if",
"path",
"[",
"-",
"3",
":",
"]",
"==",
"\".js\"",
":",
"js_path",
"=",
"path",
"elif",
"path",
"[",
"-",
"5",
":",
"]",
"==",
"\".html\"",
":",
"print",
"(",
"\"Trying to build svelt... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | save_json | Save object as json on CNS. | lucid/misc/io/saving.py | def save_json(object, handle, indent=2):
"""Save object as json on CNS."""
obj_json = json.dumps(object, indent=indent, cls=NumpyJSONEncoder)
handle.write(obj_json) | def save_json(object, handle, indent=2):
"""Save object as json on CNS."""
obj_json = json.dumps(object, indent=indent, cls=NumpyJSONEncoder)
handle.write(obj_json) | [
"Save",
"object",
"as",
"json",
"on",
"CNS",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/io/saving.py#L58-L61 | [
"def",
"save_json",
"(",
"object",
",",
"handle",
",",
"indent",
"=",
"2",
")",
":",
"obj_json",
"=",
"json",
".",
"dumps",
"(",
"object",
",",
"indent",
"=",
"indent",
",",
"cls",
"=",
"NumpyJSONEncoder",
")",
"handle",
".",
"write",
"(",
"obj_json",
... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | save_npz | Save dict of numpy array as npz file. | lucid/misc/io/saving.py | def save_npz(object, handle):
"""Save dict of numpy array as npz file."""
# there is a bug where savez doesn't actually accept a file handle.
log.warning("Saving npz files currently only works locally. :/")
path = handle.name
handle.close()
if type(object) is dict:
np.savez(path, **objec... | def save_npz(object, handle):
"""Save dict of numpy array as npz file."""
# there is a bug where savez doesn't actually accept a file handle.
log.warning("Saving npz files currently only works locally. :/")
path = handle.name
handle.close()
if type(object) is dict:
np.savez(path, **objec... | [
"Save",
"dict",
"of",
"numpy",
"array",
"as",
"npz",
"file",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/io/saving.py#L69-L81 | [
"def",
"save_npz",
"(",
"object",
",",
"handle",
")",
":",
"# there is a bug where savez doesn't actually accept a file handle.",
"log",
".",
"warning",
"(",
"\"Saving npz files currently only works locally. :/\"",
")",
"path",
"=",
"handle",
".",
"name",
"handle",
".",
"... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | save_img | Save numpy array as image file on CNS. | lucid/misc/io/saving.py | def save_img(object, handle, **kwargs):
"""Save numpy array as image file on CNS."""
if isinstance(object, np.ndarray):
normalized = _normalize_array(object)
object = PIL.Image.fromarray(normalized)
if isinstance(object, PIL.Image.Image):
object.save(handle, **kwargs) # will infer... | def save_img(object, handle, **kwargs):
"""Save numpy array as image file on CNS."""
if isinstance(object, np.ndarray):
normalized = _normalize_array(object)
object = PIL.Image.fromarray(normalized)
if isinstance(object, PIL.Image.Image):
object.save(handle, **kwargs) # will infer... | [
"Save",
"numpy",
"array",
"as",
"image",
"file",
"on",
"CNS",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/io/saving.py#L84-L94 | [
"def",
"save_img",
"(",
"object",
",",
"handle",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"object",
",",
"np",
".",
"ndarray",
")",
":",
"normalized",
"=",
"_normalize_array",
"(",
"object",
")",
"object",
"=",
"PIL",
".",
"Image",
... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | save | Save object to file on CNS.
File format is inferred from path. Use save_img(), save_npy(), or save_json()
if you need to force a particular format.
Args:
obj: object to save.
path: CNS path.
Raises:
RuntimeError: If file extension not supported. | lucid/misc/io/saving.py | def save(thing, url_or_handle, **kwargs):
"""Save object to file on CNS.
File format is inferred from path. Use save_img(), save_npy(), or save_json()
if you need to force a particular format.
Args:
obj: object to save.
path: CNS path.
Raises:
RuntimeError: If file extension not... | def save(thing, url_or_handle, **kwargs):
"""Save object to file on CNS.
File format is inferred from path. Use save_img(), save_npy(), or save_json()
if you need to force a particular format.
Args:
obj: object to save.
path: CNS path.
Raises:
RuntimeError: If file extension not... | [
"Save",
"object",
"to",
"file",
"on",
"CNS",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/io/saving.py#L135-L166 | [
"def",
"save",
"(",
"thing",
",",
"url_or_handle",
",",
"*",
"*",
"kwargs",
")",
":",
"is_handle",
"=",
"hasattr",
"(",
"url_or_handle",
",",
"\"write\"",
")",
"and",
"hasattr",
"(",
"url_or_handle",
",",
"\"name\"",
")",
"if",
"is_handle",
":",
"_",
","... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | frustum | Create view frustum matrix. | lucid/misc/gl/meshutil.py | def frustum(left, right, bottom, top, znear, zfar):
"""Create view frustum matrix."""
assert right != left
assert bottom != top
assert znear != zfar
M = np.zeros((4, 4), dtype=np.float32)
M[0, 0] = +2.0 * znear / (right - left)
M[2, 0] = (right + left) / (right - left)
M[1, 1] = +2.0 * znear / (top - b... | def frustum(left, right, bottom, top, znear, zfar):
"""Create view frustum matrix."""
assert right != left
assert bottom != top
assert znear != zfar
M = np.zeros((4, 4), dtype=np.float32)
M[0, 0] = +2.0 * znear / (right - left)
M[2, 0] = (right + left) / (right - left)
M[1, 1] = +2.0 * znear / (top - b... | [
"Create",
"view",
"frustum",
"matrix",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/gl/meshutil.py#L8-L22 | [
"def",
"frustum",
"(",
"left",
",",
"right",
",",
"bottom",
",",
"top",
",",
"znear",
",",
"zfar",
")",
":",
"assert",
"right",
"!=",
"left",
"assert",
"bottom",
"!=",
"top",
"assert",
"znear",
"!=",
"zfar",
"M",
"=",
"np",
".",
"zeros",
"(",
"(",
... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | anorm | Compute L2 norms alogn specified axes. | lucid/misc/gl/meshutil.py | def anorm(x, axis=None, keepdims=False):
"""Compute L2 norms alogn specified axes."""
return np.sqrt((x*x).sum(axis=axis, keepdims=keepdims)) | def anorm(x, axis=None, keepdims=False):
"""Compute L2 norms alogn specified axes."""
return np.sqrt((x*x).sum(axis=axis, keepdims=keepdims)) | [
"Compute",
"L2",
"norms",
"alogn",
"specified",
"axes",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/gl/meshutil.py#L33-L35 | [
"def",
"anorm",
"(",
"x",
",",
"axis",
"=",
"None",
",",
"keepdims",
"=",
"False",
")",
":",
"return",
"np",
".",
"sqrt",
"(",
"(",
"x",
"*",
"x",
")",
".",
"sum",
"(",
"axis",
"=",
"axis",
",",
"keepdims",
"=",
"keepdims",
")",
")"
] | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | normalize | L2 Normalize along specified axes. | lucid/misc/gl/meshutil.py | def normalize(v, axis=None, eps=1e-10):
"""L2 Normalize along specified axes."""
return v / max(anorm(v, axis=axis, keepdims=True), eps) | def normalize(v, axis=None, eps=1e-10):
"""L2 Normalize along specified axes."""
return v / max(anorm(v, axis=axis, keepdims=True), eps) | [
"L2",
"Normalize",
"along",
"specified",
"axes",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/gl/meshutil.py#L38-L40 | [
"def",
"normalize",
"(",
"v",
",",
"axis",
"=",
"None",
",",
"eps",
"=",
"1e-10",
")",
":",
"return",
"v",
"/",
"max",
"(",
"anorm",
"(",
"v",
",",
"axis",
"=",
"axis",
",",
"keepdims",
"=",
"True",
")",
",",
"eps",
")"
] | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | lookat | Generate LookAt modelview matrix. | lucid/misc/gl/meshutil.py | def lookat(eye, target=[0, 0, 0], up=[0, 1, 0]):
"""Generate LookAt modelview matrix."""
eye = np.float32(eye)
forward = normalize(target - eye)
side = normalize(np.cross(forward, up))
up = np.cross(side, forward)
M = np.eye(4, dtype=np.float32)
R = M[:3, :3]
R[:] = [side, up, -forward]
M[:3, 3] = -R.... | def lookat(eye, target=[0, 0, 0], up=[0, 1, 0]):
"""Generate LookAt modelview matrix."""
eye = np.float32(eye)
forward = normalize(target - eye)
side = normalize(np.cross(forward, up))
up = np.cross(side, forward)
M = np.eye(4, dtype=np.float32)
R = M[:3, :3]
R[:] = [side, up, -forward]
M[:3, 3] = -R.... | [
"Generate",
"LookAt",
"modelview",
"matrix",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/gl/meshutil.py#L43-L53 | [
"def",
"lookat",
"(",
"eye",
",",
"target",
"=",
"[",
"0",
",",
"0",
",",
"0",
"]",
",",
"up",
"=",
"[",
"0",
",",
"1",
",",
"0",
"]",
")",
":",
"eye",
"=",
"np",
".",
"float32",
"(",
"eye",
")",
"forward",
"=",
"normalize",
"(",
"target",
... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | sample_view | Sample random camera position.
Sample origin directed camera position in given distance
range from the origin. ModelView matrix is returned. | lucid/misc/gl/meshutil.py | def sample_view(min_dist, max_dist=None):
'''Sample random camera position.
Sample origin directed camera position in given distance
range from the origin. ModelView matrix is returned.
'''
if max_dist is None:
max_dist = min_dist
dist = np.random.uniform(min_dist, max_dist)
eye = np.random.normal(... | def sample_view(min_dist, max_dist=None):
'''Sample random camera position.
Sample origin directed camera position in given distance
range from the origin. ModelView matrix is returned.
'''
if max_dist is None:
max_dist = min_dist
dist = np.random.uniform(min_dist, max_dist)
eye = np.random.normal(... | [
"Sample",
"random",
"camera",
"position",
".",
"Sample",
"origin",
"directed",
"camera",
"position",
"in",
"given",
"distance",
"range",
"from",
"the",
"origin",
".",
"ModelView",
"matrix",
"is",
"returned",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/gl/meshutil.py#L56-L67 | [
"def",
"sample_view",
"(",
"min_dist",
",",
"max_dist",
"=",
"None",
")",
":",
"if",
"max_dist",
"is",
"None",
":",
"max_dist",
"=",
"min_dist",
"dist",
"=",
"np",
".",
"random",
".",
"uniform",
"(",
"min_dist",
",",
"max_dist",
")",
"eye",
"=",
"np",
... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | _parse_vertex_tuple | Parse vertex indices in '/' separated form (like 'i/j/k', 'i//k' ...). | lucid/misc/gl/meshutil.py | def _parse_vertex_tuple(s):
"""Parse vertex indices in '/' separated form (like 'i/j/k', 'i//k' ...)."""
vt = [0, 0, 0]
for i, c in enumerate(s.split('/')):
if c:
vt[i] = int(c)
return tuple(vt) | def _parse_vertex_tuple(s):
"""Parse vertex indices in '/' separated form (like 'i/j/k', 'i//k' ...)."""
vt = [0, 0, 0]
for i, c in enumerate(s.split('/')):
if c:
vt[i] = int(c)
return tuple(vt) | [
"Parse",
"vertex",
"indices",
"in",
"/",
"separated",
"form",
"(",
"like",
"i",
"/",
"j",
"/",
"k",
"i",
"//",
"k",
"...",
")",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/gl/meshutil.py#L78-L84 | [
"def",
"_parse_vertex_tuple",
"(",
"s",
")",
":",
"vt",
"=",
"[",
"0",
",",
"0",
",",
"0",
"]",
"for",
"i",
",",
"c",
"in",
"enumerate",
"(",
"s",
".",
"split",
"(",
"'/'",
")",
")",
":",
"if",
"c",
":",
"vt",
"[",
"i",
"]",
"=",
"int",
"... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | _unify_rows | Unify lengths of each row of a. | lucid/misc/gl/meshutil.py | def _unify_rows(a):
"""Unify lengths of each row of a."""
lens = np.fromiter(map(len, a), np.int32)
if not (lens[0] == lens).all():
out = np.zeros((len(a), lens.max()), np.float32)
for i, row in enumerate(a):
out[i, :lens[i]] = row
else:
out = np.float32(a)
return out | def _unify_rows(a):
"""Unify lengths of each row of a."""
lens = np.fromiter(map(len, a), np.int32)
if not (lens[0] == lens).all():
out = np.zeros((len(a), lens.max()), np.float32)
for i, row in enumerate(a):
out[i, :lens[i]] = row
else:
out = np.float32(a)
return out | [
"Unify",
"lengths",
"of",
"each",
"row",
"of",
"a",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/gl/meshutil.py#L87-L96 | [
"def",
"_unify_rows",
"(",
"a",
")",
":",
"lens",
"=",
"np",
".",
"fromiter",
"(",
"map",
"(",
"len",
",",
"a",
")",
",",
"np",
".",
"int32",
")",
"if",
"not",
"(",
"lens",
"[",
"0",
"]",
"==",
"lens",
")",
".",
"all",
"(",
")",
":",
"out",... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | load_obj | Load 3d mesh form .obj' file.
Args:
fn: Input file name or file-like object.
Returns:
dictionary with the following keys (some of which may be missing):
position: np.float32, (n, 3) array, vertex positions
uv: np.float32, (n, 2) array, vertex uv coordinates
normal: np.float32, (n, ... | lucid/misc/gl/meshutil.py | def load_obj(fn):
"""Load 3d mesh form .obj' file.
Args:
fn: Input file name or file-like object.
Returns:
dictionary with the following keys (some of which may be missing):
position: np.float32, (n, 3) array, vertex positions
uv: np.float32, (n, 2) array, vertex uv coordinates
n... | def load_obj(fn):
"""Load 3d mesh form .obj' file.
Args:
fn: Input file name or file-like object.
Returns:
dictionary with the following keys (some of which may be missing):
position: np.float32, (n, 3) array, vertex positions
uv: np.float32, (n, 2) array, vertex uv coordinates
n... | [
"Load",
"3d",
"mesh",
"form",
".",
"obj",
"file",
".",
"Args",
":",
"fn",
":",
"Input",
"file",
"name",
"or",
"file",
"-",
"like",
"object",
".",
"Returns",
":",
"dictionary",
"with",
"the",
"following",
"keys",
"(",
"some",
"of",
"which",
"may",
"be... | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/gl/meshutil.py#L99-L158 | [
"def",
"load_obj",
"(",
"fn",
")",
":",
"position",
"=",
"[",
"np",
".",
"zeros",
"(",
"3",
",",
"dtype",
"=",
"np",
".",
"float32",
")",
"]",
"normal",
"=",
"[",
"np",
".",
"zeros",
"(",
"3",
",",
"dtype",
"=",
"np",
".",
"float32",
")",
"]"... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | normalize_mesh | Scale mesh to fit into -1..1 cube | lucid/misc/gl/meshutil.py | def normalize_mesh(mesh):
'''Scale mesh to fit into -1..1 cube'''
mesh = dict(mesh)
pos = mesh['position'][:,:3].copy()
pos -= (pos.max(0)+pos.min(0)) / 2.0
pos /= np.abs(pos).max()
mesh['position'] = pos
return mesh | def normalize_mesh(mesh):
'''Scale mesh to fit into -1..1 cube'''
mesh = dict(mesh)
pos = mesh['position'][:,:3].copy()
pos -= (pos.max(0)+pos.min(0)) / 2.0
pos /= np.abs(pos).max()
mesh['position'] = pos
return mesh | [
"Scale",
"mesh",
"to",
"fit",
"into",
"-",
"1",
"..",
"1",
"cube"
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/gl/meshutil.py#L161-L168 | [
"def",
"normalize_mesh",
"(",
"mesh",
")",
":",
"mesh",
"=",
"dict",
"(",
"mesh",
")",
"pos",
"=",
"mesh",
"[",
"'position'",
"]",
"[",
":",
",",
":",
"3",
"]",
".",
"copy",
"(",
")",
"pos",
"-=",
"(",
"pos",
".",
"max",
"(",
"0",
")",
"+",
... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | Layer.activations | Loads sampled activations, which requires network access. | lucid/modelzoo/vision_base.py | def activations(self):
"""Loads sampled activations, which requires network access."""
if self._activations is None:
self._activations = _get_aligned_activations(self)
return self._activations | def activations(self):
"""Loads sampled activations, which requires network access."""
if self._activations is None:
self._activations = _get_aligned_activations(self)
return self._activations | [
"Loads",
"sampled",
"activations",
"which",
"requires",
"network",
"access",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/modelzoo/vision_base.py#L71-L75 | [
"def",
"activations",
"(",
"self",
")",
":",
"if",
"self",
".",
"_activations",
"is",
"None",
":",
"self",
".",
"_activations",
"=",
"_get_aligned_activations",
"(",
"self",
")",
"return",
"self",
".",
"_activations"
] | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | Model.create_input | Create input tensor. | lucid/modelzoo/vision_base.py | def create_input(self, t_input=None, forget_xy_shape=True):
"""Create input tensor."""
if t_input is None:
t_input = tf.placeholder(tf.float32, self.image_shape)
t_prep_input = t_input
if len(t_prep_input.shape) == 3:
t_prep_input = tf.expand_dims(t_prep_input, 0)
if forget_xy_shape:
... | def create_input(self, t_input=None, forget_xy_shape=True):
"""Create input tensor."""
if t_input is None:
t_input = tf.placeholder(tf.float32, self.image_shape)
t_prep_input = t_input
if len(t_prep_input.shape) == 3:
t_prep_input = tf.expand_dims(t_prep_input, 0)
if forget_xy_shape:
... | [
"Create",
"input",
"tensor",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/modelzoo/vision_base.py#L161-L174 | [
"def",
"create_input",
"(",
"self",
",",
"t_input",
"=",
"None",
",",
"forget_xy_shape",
"=",
"True",
")",
":",
"if",
"t_input",
"is",
"None",
":",
"t_input",
"=",
"tf",
".",
"placeholder",
"(",
"tf",
".",
"float32",
",",
"self",
".",
"image_shape",
")... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | Model.import_graph | Import model GraphDef into the current graph. | lucid/modelzoo/vision_base.py | def import_graph(self, t_input=None, scope='import', forget_xy_shape=True):
"""Import model GraphDef into the current graph."""
graph = tf.get_default_graph()
assert graph.unique_name(scope, False) == scope, (
'Scope "%s" already exists. Provide explicit scope names when '
'importing multipl... | def import_graph(self, t_input=None, scope='import', forget_xy_shape=True):
"""Import model GraphDef into the current graph."""
graph = tf.get_default_graph()
assert graph.unique_name(scope, False) == scope, (
'Scope "%s" already exists. Provide explicit scope names when '
'importing multipl... | [
"Import",
"model",
"GraphDef",
"into",
"the",
"current",
"graph",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/modelzoo/vision_base.py#L176-L185 | [
"def",
"import_graph",
"(",
"self",
",",
"t_input",
"=",
"None",
",",
"scope",
"=",
"'import'",
",",
"forget_xy_shape",
"=",
"True",
")",
":",
"graph",
"=",
"tf",
".",
"get_default_graph",
"(",
")",
"assert",
"graph",
".",
"unique_name",
"(",
"scope",
",... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | normalize_layout | Removes outliers and scales layout to between [0,1]. | lucid/recipes/activation_atlas/layout.py | def normalize_layout(layout, min_percentile=1, max_percentile=99, relative_margin=0.1):
"""Removes outliers and scales layout to between [0,1]."""
# compute percentiles
mins = np.percentile(layout, min_percentile, axis=(0))
maxs = np.percentile(layout, max_percentile, axis=(0))
# add margins
m... | def normalize_layout(layout, min_percentile=1, max_percentile=99, relative_margin=0.1):
"""Removes outliers and scales layout to between [0,1]."""
# compute percentiles
mins = np.percentile(layout, min_percentile, axis=(0))
maxs = np.percentile(layout, max_percentile, axis=(0))
# add margins
m... | [
"Removes",
"outliers",
"and",
"scales",
"layout",
"to",
"between",
"[",
"0",
"1",
"]",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/recipes/activation_atlas/layout.py#L25-L43 | [
"def",
"normalize_layout",
"(",
"layout",
",",
"min_percentile",
"=",
"1",
",",
"max_percentile",
"=",
"99",
",",
"relative_margin",
"=",
"0.1",
")",
":",
"# compute percentiles",
"mins",
"=",
"np",
".",
"percentile",
"(",
"layout",
",",
"min_percentile",
",",... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | aligned_umap | `activations` can be a list of ndarrays. In that case a list of layouts is returned. | lucid/recipes/activation_atlas/layout.py | def aligned_umap(activations, umap_options={}, normalize=True, verbose=False):
"""`activations` can be a list of ndarrays. In that case a list of layouts is returned."""
umap_defaults = dict(
n_components=2, n_neighbors=50, min_dist=0.05, verbose=verbose, metric="cosine"
)
umap_defaults.update(... | def aligned_umap(activations, umap_options={}, normalize=True, verbose=False):
"""`activations` can be a list of ndarrays. In that case a list of layouts is returned."""
umap_defaults = dict(
n_components=2, n_neighbors=50, min_dist=0.05, verbose=verbose, metric="cosine"
)
umap_defaults.update(... | [
"activations",
"can",
"be",
"a",
"list",
"of",
"ndarrays",
".",
"In",
"that",
"case",
"a",
"list",
"of",
"layouts",
"is",
"returned",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/recipes/activation_atlas/layout.py#L46-L74 | [
"def",
"aligned_umap",
"(",
"activations",
",",
"umap_options",
"=",
"{",
"}",
",",
"normalize",
"=",
"True",
",",
"verbose",
"=",
"False",
")",
":",
"umap_defaults",
"=",
"dict",
"(",
"n_components",
"=",
"2",
",",
"n_neighbors",
"=",
"50",
",",
"min_di... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | render_tile | Render each cell in the tile and stitch it into a single image | lucid/scratch/atlas_pipeline/render_tile.py | def render_tile(cells, ti, tj, render, params, metadata, layout, summary):
"""
Render each cell in the tile and stitch it into a single image
"""
image_size = params["cell_size"] * params["n_tile"]
tile = Image.new("RGB", (image_size, image_size), (255,255,255))
keys = cells.keys()
for i,key in enumerat... | def render_tile(cells, ti, tj, render, params, metadata, layout, summary):
"""
Render each cell in the tile and stitch it into a single image
"""
image_size = params["cell_size"] * params["n_tile"]
tile = Image.new("RGB", (image_size, image_size), (255,255,255))
keys = cells.keys()
for i,key in enumerat... | [
"Render",
"each",
"cell",
"in",
"the",
"tile",
"and",
"stitch",
"it",
"into",
"a",
"single",
"image"
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/scratch/atlas_pipeline/render_tile.py#L11-L51 | [
"def",
"render_tile",
"(",
"cells",
",",
"ti",
",",
"tj",
",",
"render",
",",
"params",
",",
"metadata",
",",
"layout",
",",
"summary",
")",
":",
"image_size",
"=",
"params",
"[",
"\"cell_size\"",
"]",
"*",
"params",
"[",
"\"n_tile\"",
"]",
"tile",
"="... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | aggregate_tile | Call the user defined aggregation function on each cell and combine into a single json object | lucid/scratch/atlas_pipeline/render_tile.py | def aggregate_tile(cells, ti, tj, aggregate, params, metadata, layout, summary):
"""
Call the user defined aggregation function on each cell and combine into a single json object
"""
tile = []
keys = cells.keys()
for i,key in enumerate(keys):
print("cell", i+1, "/", len(keys), end='\r')
cell_json ... | def aggregate_tile(cells, ti, tj, aggregate, params, metadata, layout, summary):
"""
Call the user defined aggregation function on each cell and combine into a single json object
"""
tile = []
keys = cells.keys()
for i,key in enumerate(keys):
print("cell", i+1, "/", len(keys), end='\r')
cell_json ... | [
"Call",
"the",
"user",
"defined",
"aggregation",
"function",
"on",
"each",
"cell",
"and",
"combine",
"into",
"a",
"single",
"json",
"object"
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/scratch/atlas_pipeline/render_tile.py#L54-L64 | [
"def",
"aggregate_tile",
"(",
"cells",
",",
"ti",
",",
"tj",
",",
"aggregate",
",",
"params",
",",
"metadata",
",",
"layout",
",",
"summary",
")",
":",
"tile",
"=",
"[",
"]",
"keys",
"=",
"cells",
".",
"keys",
"(",
")",
"for",
"i",
",",
"key",
"i... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | create_opengl_context | Create offscreen OpenGL context and make it current.
Users are expected to directly use EGL API in case more advanced
context management is required.
Args:
surface_size: (width, height), size of the offscreen rendering surface. | lucid/misc/gl/glcontext.py | def create_opengl_context(surface_size=(640, 480)):
"""Create offscreen OpenGL context and make it current.
Users are expected to directly use EGL API in case more advanced
context management is required.
Args:
surface_size: (width, height), size of the offscreen rendering surface.
"""
egl_display = e... | def create_opengl_context(surface_size=(640, 480)):
"""Create offscreen OpenGL context and make it current.
Users are expected to directly use EGL API in case more advanced
context management is required.
Args:
surface_size: (width, height), size of the offscreen rendering surface.
"""
egl_display = e... | [
"Create",
"offscreen",
"OpenGL",
"context",
"and",
"make",
"it",
"current",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/gl/glcontext.py#L79-L120 | [
"def",
"create_opengl_context",
"(",
"surface_size",
"=",
"(",
"640",
",",
"480",
")",
")",
":",
"egl_display",
"=",
"egl",
".",
"eglGetDisplay",
"(",
"egl",
".",
"EGL_DEFAULT_DISPLAY",
")",
"major",
",",
"minor",
"=",
"egl",
".",
"EGLint",
"(",
")",
","... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | collapse_shape | Collapse `shape` outside the interval (`a`,`b`).
This function collapses `shape` outside the interval (`a`,`b`) by
multiplying the dimensions before `a` into a single dimension,
and mutliplying the dimensions after `b` into a single dimension.
Args:
shape: a tensor shape
a: integer, position in shape
... | lucid/optvis/param/resize_bilinear_nd.py | def collapse_shape(shape, a, b):
"""Collapse `shape` outside the interval (`a`,`b`).
This function collapses `shape` outside the interval (`a`,`b`) by
multiplying the dimensions before `a` into a single dimension,
and mutliplying the dimensions after `b` into a single dimension.
Args:
shape: a tensor sh... | def collapse_shape(shape, a, b):
"""Collapse `shape` outside the interval (`a`,`b`).
This function collapses `shape` outside the interval (`a`,`b`) by
multiplying the dimensions before `a` into a single dimension,
and mutliplying the dimensions after `b` into a single dimension.
Args:
shape: a tensor sh... | [
"Collapse",
"shape",
"outside",
"the",
"interval",
"(",
"a",
"b",
")",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/param/resize_bilinear_nd.py#L35-L65 | [
"def",
"collapse_shape",
"(",
"shape",
",",
"a",
",",
"b",
")",
":",
"shape",
"=",
"list",
"(",
"shape",
")",
"if",
"a",
"<",
"0",
":",
"n_pad",
"=",
"-",
"a",
"pad",
"=",
"n_pad",
"*",
"[",
"1",
"]",
"return",
"collapse_shape",
"(",
"pad",
"+"... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | resize_bilinear_nd | Bilinear resizes a tensor t to have shape target_shape.
This function bilinearly resizes a n-dimensional tensor by iteratively
applying tf.image.resize_bilinear (which can only resize 2 dimensions).
For bilinear interpolation, the order in which it is applied does not matter.
Args:
t: tensor to be resized... | lucid/optvis/param/resize_bilinear_nd.py | def resize_bilinear_nd(t, target_shape):
"""Bilinear resizes a tensor t to have shape target_shape.
This function bilinearly resizes a n-dimensional tensor by iteratively
applying tf.image.resize_bilinear (which can only resize 2 dimensions).
For bilinear interpolation, the order in which it is applied does no... | def resize_bilinear_nd(t, target_shape):
"""Bilinear resizes a tensor t to have shape target_shape.
This function bilinearly resizes a n-dimensional tensor by iteratively
applying tf.image.resize_bilinear (which can only resize 2 dimensions).
For bilinear interpolation, the order in which it is applied does no... | [
"Bilinear",
"resizes",
"a",
"tensor",
"t",
"to",
"have",
"shape",
"target_shape",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/param/resize_bilinear_nd.py#L68-L116 | [
"def",
"resize_bilinear_nd",
"(",
"t",
",",
"target_shape",
")",
":",
"shape",
"=",
"t",
".",
"get_shape",
"(",
")",
".",
"as_list",
"(",
")",
"target_shape",
"=",
"list",
"(",
"target_shape",
")",
"assert",
"len",
"(",
"shape",
")",
"==",
"len",
"(",
... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | get_aligned_activations | Downloads 100k activations of the specified layer sampled from iterating over
ImageNet. Activations of all layers where sampled at the same spatial positions for
each image, allowing the calculation of correlations. | lucid/modelzoo/aligned_activations.py | def get_aligned_activations(layer):
"""Downloads 100k activations of the specified layer sampled from iterating over
ImageNet. Activations of all layers where sampled at the same spatial positions for
each image, allowing the calculation of correlations."""
activation_paths = [
PATH_TEMPLATE.for... | def get_aligned_activations(layer):
"""Downloads 100k activations of the specified layer sampled from iterating over
ImageNet. Activations of all layers where sampled at the same spatial positions for
each image, allowing the calculation of correlations."""
activation_paths = [
PATH_TEMPLATE.for... | [
"Downloads",
"100k",
"activations",
"of",
"the",
"specified",
"layer",
"sampled",
"from",
"iterating",
"over",
"ImageNet",
".",
"Activations",
"of",
"all",
"layers",
"where",
"sampled",
"at",
"the",
"same",
"spatial",
"positions",
"for",
"each",
"image",
"allowi... | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/modelzoo/aligned_activations.py#L35-L47 | [
"def",
"get_aligned_activations",
"(",
"layer",
")",
":",
"activation_paths",
"=",
"[",
"PATH_TEMPLATE",
".",
"format",
"(",
"sanitize",
"(",
"layer",
".",
"model_class",
".",
"name",
")",
",",
"sanitize",
"(",
"layer",
".",
"name",
")",
",",
"page",
")",
... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | layer_covariance | Computes the covariance matrix between the neurons of two layers. If only one
layer is passed, computes the symmetric covariance matrix of that layer. | lucid/modelzoo/aligned_activations.py | def layer_covariance(layer1, layer2=None):
"""Computes the covariance matrix between the neurons of two layers. If only one
layer is passed, computes the symmetric covariance matrix of that layer."""
layer2 = layer2 or layer1
act1, act2 = layer1.activations, layer2.activations
num_datapoints = act1.... | def layer_covariance(layer1, layer2=None):
"""Computes the covariance matrix between the neurons of two layers. If only one
layer is passed, computes the symmetric covariance matrix of that layer."""
layer2 = layer2 or layer1
act1, act2 = layer1.activations, layer2.activations
num_datapoints = act1.... | [
"Computes",
"the",
"covariance",
"matrix",
"between",
"the",
"neurons",
"of",
"two",
"layers",
".",
"If",
"only",
"one",
"layer",
"is",
"passed",
"computes",
"the",
"symmetric",
"covariance",
"matrix",
"of",
"that",
"layer",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/modelzoo/aligned_activations.py#L51-L57 | [
"def",
"layer_covariance",
"(",
"layer1",
",",
"layer2",
"=",
"None",
")",
":",
"layer2",
"=",
"layer2",
"or",
"layer1",
"act1",
",",
"act2",
"=",
"layer1",
".",
"activations",
",",
"layer2",
".",
"activations",
"num_datapoints",
"=",
"act1",
".",
"shape",... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | push_activations | Push activations from one model to another using prerecorded correlations | lucid/modelzoo/aligned_activations.py | def push_activations(activations, from_layer, to_layer):
"""Push activations from one model to another using prerecorded correlations"""
inverse_covariance_matrix = layer_inverse_covariance(from_layer)
activations_decorrelated = np.dot(inverse_covariance_matrix, activations.T).T
covariance_matrix = laye... | def push_activations(activations, from_layer, to_layer):
"""Push activations from one model to another using prerecorded correlations"""
inverse_covariance_matrix = layer_inverse_covariance(from_layer)
activations_decorrelated = np.dot(inverse_covariance_matrix, activations.T).T
covariance_matrix = laye... | [
"Push",
"activations",
"from",
"one",
"model",
"to",
"another",
"using",
"prerecorded",
"correlations"
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/modelzoo/aligned_activations.py#L66-L72 | [
"def",
"push_activations",
"(",
"activations",
",",
"from_layer",
",",
"to_layer",
")",
":",
"inverse_covariance_matrix",
"=",
"layer_inverse_covariance",
"(",
"from_layer",
")",
"activations_decorrelated",
"=",
"np",
".",
"dot",
"(",
"inverse_covariance_matrix",
",",
... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | multi_interpolation_basis | A paramaterization for interpolating between each pair of N objectives.
Sometimes you want to interpolate between optimizing a bunch of objectives,
in a paramaterization that encourages images to align.
Args:
n_objectives: number of objectives you want interpolate between
n_interp_steps: number of inter... | lucid/recipes/image_interpolation_params.py | def multi_interpolation_basis(n_objectives=6, n_interp_steps=5, width=128,
channels=3):
"""A paramaterization for interpolating between each pair of N objectives.
Sometimes you want to interpolate between optimizing a bunch of objectives,
in a paramaterization that encourages images... | def multi_interpolation_basis(n_objectives=6, n_interp_steps=5, width=128,
channels=3):
"""A paramaterization for interpolating between each pair of N objectives.
Sometimes you want to interpolate between optimizing a bunch of objectives,
in a paramaterization that encourages images... | [
"A",
"paramaterization",
"for",
"interpolating",
"between",
"each",
"pair",
"of",
"N",
"objectives",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/recipes/image_interpolation_params.py#L22-L82 | [
"def",
"multi_interpolation_basis",
"(",
"n_objectives",
"=",
"6",
",",
"n_interp_steps",
"=",
"5",
",",
"width",
"=",
"128",
",",
"channels",
"=",
"3",
")",
":",
"N",
",",
"M",
",",
"W",
",",
"Ch",
"=",
"n_objectives",
",",
"n_interp_steps",
",",
"wid... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | register_to_random_name | Register a gradient function to a random string.
In order to use a custom gradient in TensorFlow, it must be registered to a
string. This is both a hassle, and -- because only one function can every be
registered to a string -- annoying to iterate on in an interactive
environemnt.
This function registers a ... | lucid/optvis/overrides/gradient_override.py | def register_to_random_name(grad_f):
"""Register a gradient function to a random string.
In order to use a custom gradient in TensorFlow, it must be registered to a
string. This is both a hassle, and -- because only one function can every be
registered to a string -- annoying to iterate on in an interactive
... | def register_to_random_name(grad_f):
"""Register a gradient function to a random string.
In order to use a custom gradient in TensorFlow, it must be registered to a
string. This is both a hassle, and -- because only one function can every be
registered to a string -- annoying to iterate on in an interactive
... | [
"Register",
"a",
"gradient",
"function",
"to",
"a",
"random",
"string",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/overrides/gradient_override.py#L50-L73 | [
"def",
"register_to_random_name",
"(",
"grad_f",
")",
":",
"grad_f_name",
"=",
"grad_f",
".",
"__name__",
"+",
"\"_\"",
"+",
"str",
"(",
"uuid",
".",
"uuid4",
"(",
")",
")",
"tf",
".",
"RegisterGradient",
"(",
"grad_f_name",
")",
"(",
"grad_f",
")",
"ret... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | gradient_override_map | Convenience wrapper for graph.gradient_override_map().
This functions provides two conveniences over normal tensorflow gradient
overrides: it auomatically uses the default graph instead of you needing to
find the graph, and it automatically
Example:
def _foo_grad_alt(op, grad): ...
with gradient_ove... | lucid/optvis/overrides/gradient_override.py | def gradient_override_map(override_dict):
"""Convenience wrapper for graph.gradient_override_map().
This functions provides two conveniences over normal tensorflow gradient
overrides: it auomatically uses the default graph instead of you needing to
find the graph, and it automatically
Example:
def _foo... | def gradient_override_map(override_dict):
"""Convenience wrapper for graph.gradient_override_map().
This functions provides two conveniences over normal tensorflow gradient
overrides: it auomatically uses the default graph instead of you needing to
find the graph, and it automatically
Example:
def _foo... | [
"Convenience",
"wrapper",
"for",
"graph",
".",
"gradient_override_map",
"()",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/overrides/gradient_override.py#L77-L104 | [
"def",
"gradient_override_map",
"(",
"override_dict",
")",
":",
"override_dict_by_name",
"=",
"{",
"}",
"for",
"(",
"op_name",
",",
"grad_f",
")",
"in",
"override_dict",
".",
"items",
"(",
")",
":",
"if",
"isinstance",
"(",
"grad_f",
",",
"str",
")",
":",
... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | use_gradient | Decorator for easily setting custom gradients for TensorFlow functions.
* DO NOT use this function if you need to serialize your graph.
* This function will cause the decorated function to run slower.
Example:
def _foo_grad(op, grad): ...
@use_gradient(_foo_grad)
def foo(x1, x2, x3): ...
Args:
... | lucid/optvis/overrides/gradient_override.py | def use_gradient(grad_f):
"""Decorator for easily setting custom gradients for TensorFlow functions.
* DO NOT use this function if you need to serialize your graph.
* This function will cause the decorated function to run slower.
Example:
def _foo_grad(op, grad): ...
@use_gradient(_foo_grad)
def... | def use_gradient(grad_f):
"""Decorator for easily setting custom gradients for TensorFlow functions.
* DO NOT use this function if you need to serialize your graph.
* This function will cause the decorated function to run slower.
Example:
def _foo_grad(op, grad): ...
@use_gradient(_foo_grad)
def... | [
"Decorator",
"for",
"easily",
"setting",
"custom",
"gradients",
"for",
"TensorFlow",
"functions",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/overrides/gradient_override.py#L107-L178 | [
"def",
"use_gradient",
"(",
"grad_f",
")",
":",
"grad_f_name",
"=",
"register_to_random_name",
"(",
"grad_f",
")",
"def",
"function_wrapper",
"(",
"f",
")",
":",
"def",
"inner",
"(",
"*",
"inputs",
")",
":",
"# TensorFlow only supports (as of writing) overriding the... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | pixel_image | A naive, pixel-based image parameterization.
Defaults to a random initialization, but can take a supplied init_val argument
instead.
Args:
shape: shape of resulting image, [batch, width, height, channels].
sd: standard deviation of param initialization noise.
init_val: an initial value to... | lucid/optvis/param/spatial.py | def pixel_image(shape, sd=None, init_val=None):
"""A naive, pixel-based image parameterization.
Defaults to a random initialization, but can take a supplied init_val argument
instead.
Args:
shape: shape of resulting image, [batch, width, height, channels].
sd: standard deviation of param in... | def pixel_image(shape, sd=None, init_val=None):
"""A naive, pixel-based image parameterization.
Defaults to a random initialization, but can take a supplied init_val argument
instead.
Args:
shape: shape of resulting image, [batch, width, height, channels].
sd: standard deviation of param in... | [
"A",
"naive",
"pixel",
"-",
"based",
"image",
"parameterization",
".",
"Defaults",
"to",
"a",
"random",
"initialization",
"but",
"can",
"take",
"a",
"supplied",
"init_val",
"argument",
"instead",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/param/spatial.py#L24-L45 | [
"def",
"pixel_image",
"(",
"shape",
",",
"sd",
"=",
"None",
",",
"init_val",
"=",
"None",
")",
":",
"if",
"sd",
"is",
"not",
"None",
"and",
"init_val",
"is",
"not",
"None",
":",
"warnings",
".",
"warn",
"(",
"\"`pixel_image` received both an initial value an... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | rfft2d_freqs | Computes 2D spectrum frequencies. | lucid/optvis/param/spatial.py | def rfft2d_freqs(h, w):
"""Computes 2D spectrum frequencies."""
fy = np.fft.fftfreq(h)[:, None]
# when we have an odd input dimension we need to keep one additional
# frequency and later cut off 1 pixel
if w % 2 == 1:
fx = np.fft.fftfreq(w)[: w // 2 + 2]
else:
fx = np.fft.fftfre... | def rfft2d_freqs(h, w):
"""Computes 2D spectrum frequencies."""
fy = np.fft.fftfreq(h)[:, None]
# when we have an odd input dimension we need to keep one additional
# frequency and later cut off 1 pixel
if w % 2 == 1:
fx = np.fft.fftfreq(w)[: w // 2 + 2]
else:
fx = np.fft.fftfre... | [
"Computes",
"2D",
"spectrum",
"frequencies",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/param/spatial.py#L48-L58 | [
"def",
"rfft2d_freqs",
"(",
"h",
",",
"w",
")",
":",
"fy",
"=",
"np",
".",
"fft",
".",
"fftfreq",
"(",
"h",
")",
"[",
":",
",",
"None",
"]",
"# when we have an odd input dimension we need to keep one additional",
"# frequency and later cut off 1 pixel",
"if",
"w",... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | fft_image | An image paramaterization using 2D Fourier coefficients. | lucid/optvis/param/spatial.py | def fft_image(shape, sd=None, decay_power=1):
"""An image paramaterization using 2D Fourier coefficients."""
sd = sd or 0.01
batch, h, w, ch = shape
freqs = rfft2d_freqs(h, w)
init_val_size = (2, ch) + freqs.shape
images = []
for _ in range(batch):
# Create a random variable holdin... | def fft_image(shape, sd=None, decay_power=1):
"""An image paramaterization using 2D Fourier coefficients."""
sd = sd or 0.01
batch, h, w, ch = shape
freqs = rfft2d_freqs(h, w)
init_val_size = (2, ch) + freqs.shape
images = []
for _ in range(batch):
# Create a random variable holdin... | [
"An",
"image",
"paramaterization",
"using",
"2D",
"Fourier",
"coefficients",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/param/spatial.py#L61-L93 | [
"def",
"fft_image",
"(",
"shape",
",",
"sd",
"=",
"None",
",",
"decay_power",
"=",
"1",
")",
":",
"sd",
"=",
"sd",
"or",
"0.01",
"batch",
",",
"h",
",",
"w",
",",
"ch",
"=",
"shape",
"freqs",
"=",
"rfft2d_freqs",
"(",
"h",
",",
"w",
")",
"init_... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | laplacian_pyramid_image | Simple laplacian pyramid paramaterization of an image.
For more flexibility, use a sum of lowres_tensor()s.
Args:
shape: shape of resulting image, [batch, width, height, channels].
n_levels: number of levels of laplacian pyarmid.
sd: standard deviation of param initialization.
Returns:
... | lucid/optvis/param/spatial.py | def laplacian_pyramid_image(shape, n_levels=4, sd=None):
"""Simple laplacian pyramid paramaterization of an image.
For more flexibility, use a sum of lowres_tensor()s.
Args:
shape: shape of resulting image, [batch, width, height, channels].
n_levels: number of levels of laplacian pyarmid.
... | def laplacian_pyramid_image(shape, n_levels=4, sd=None):
"""Simple laplacian pyramid paramaterization of an image.
For more flexibility, use a sum of lowres_tensor()s.
Args:
shape: shape of resulting image, [batch, width, height, channels].
n_levels: number of levels of laplacian pyarmid.
... | [
"Simple",
"laplacian",
"pyramid",
"paramaterization",
"of",
"an",
"image",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/param/spatial.py#L96-L115 | [
"def",
"laplacian_pyramid_image",
"(",
"shape",
",",
"n_levels",
"=",
"4",
",",
"sd",
"=",
"None",
")",
":",
"batch_dims",
"=",
"shape",
"[",
":",
"-",
"3",
"]",
"w",
",",
"h",
",",
"ch",
"=",
"shape",
"[",
"-",
"3",
":",
"]",
"pyramid",
"=",
"... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | bilinearly_sampled_image | Build bilinear texture sampling graph.
Coordinate transformation rules match OpenGL GL_REPEAT wrapping and GL_LINEAR
interpolation modes.
Args:
texture: [tex_h, tex_w, channel_n] tensor.
uv: [frame_h, frame_h, 2] tensor with per-pixel UV coordinates in range [0..1]
Returns:
[frame_h... | lucid/optvis/param/spatial.py | def bilinearly_sampled_image(texture, uv):
"""Build bilinear texture sampling graph.
Coordinate transformation rules match OpenGL GL_REPEAT wrapping and GL_LINEAR
interpolation modes.
Args:
texture: [tex_h, tex_w, channel_n] tensor.
uv: [frame_h, frame_h, 2] tensor with per-pixel UV coordi... | def bilinearly_sampled_image(texture, uv):
"""Build bilinear texture sampling graph.
Coordinate transformation rules match OpenGL GL_REPEAT wrapping and GL_LINEAR
interpolation modes.
Args:
texture: [tex_h, tex_w, channel_n] tensor.
uv: [frame_h, frame_h, 2] tensor with per-pixel UV coordi... | [
"Build",
"bilinear",
"texture",
"sampling",
"graph",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/param/spatial.py#L118-L149 | [
"def",
"bilinearly_sampled_image",
"(",
"texture",
",",
"uv",
")",
":",
"h",
",",
"w",
"=",
"tf",
".",
"unstack",
"(",
"tf",
".",
"shape",
"(",
"texture",
")",
"[",
":",
"2",
"]",
")",
"u",
",",
"v",
"=",
"tf",
".",
"split",
"(",
"uv",
",",
"... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | _linear_decorelate_color | Multiply input by sqrt of emperical (ImageNet) color correlation matrix.
If you interpret t's innermost dimension as describing colors in a
decorrelated version of the color space (which is a very natural way to
describe colors -- see discussion in Feature Visualization article) the way
to map back to normal... | lucid/optvis/param/color.py | def _linear_decorelate_color(t):
"""Multiply input by sqrt of emperical (ImageNet) color correlation matrix.
If you interpret t's innermost dimension as describing colors in a
decorrelated version of the color space (which is a very natural way to
describe colors -- see discussion in Feature Visualization ar... | def _linear_decorelate_color(t):
"""Multiply input by sqrt of emperical (ImageNet) color correlation matrix.
If you interpret t's innermost dimension as describing colors in a
decorrelated version of the color space (which is a very natural way to
describe colors -- see discussion in Feature Visualization ar... | [
"Multiply",
"input",
"by",
"sqrt",
"of",
"emperical",
"(",
"ImageNet",
")",
"color",
"correlation",
"matrix",
".",
"If",
"you",
"interpret",
"t",
"s",
"innermost",
"dimension",
"as",
"describing",
"colors",
"in",
"a",
"decorrelated",
"version",
"of",
"the",
... | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/param/color.py#L32-L46 | [
"def",
"_linear_decorelate_color",
"(",
"t",
")",
":",
"# check that inner dimension is 3?",
"t_flat",
"=",
"tf",
".",
"reshape",
"(",
"t",
",",
"[",
"-",
"1",
",",
"3",
"]",
")",
"color_correlation_normalized",
"=",
"color_correlation_svd_sqrt",
"/",
"max_norm_sv... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | to_valid_rgb | Transform inner dimension of t to valid rgb colors.
In practice this consistes of two parts:
(1) If requested, transform the colors from a decorrelated color space to RGB.
(2) Constrain the color channels to be in [0,1], either using a sigmoid
function or clipping.
Args:
t: input tensor, innerm... | lucid/optvis/param/color.py | def to_valid_rgb(t, decorrelate=False, sigmoid=True):
"""Transform inner dimension of t to valid rgb colors.
In practice this consistes of two parts:
(1) If requested, transform the colors from a decorrelated color space to RGB.
(2) Constrain the color channels to be in [0,1], either using a sigmoid
f... | def to_valid_rgb(t, decorrelate=False, sigmoid=True):
"""Transform inner dimension of t to valid rgb colors.
In practice this consistes of two parts:
(1) If requested, transform the colors from a decorrelated color space to RGB.
(2) Constrain the color channels to be in [0,1], either using a sigmoid
f... | [
"Transform",
"inner",
"dimension",
"of",
"t",
"to",
"valid",
"rgb",
"colors",
".",
"In",
"practice",
"this",
"consistes",
"of",
"two",
"parts",
":",
"(",
"1",
")",
"If",
"requested",
"transform",
"the",
"colors",
"from",
"a",
"decorrelated",
"color",
"spac... | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/param/color.py#L49-L75 | [
"def",
"to_valid_rgb",
"(",
"t",
",",
"decorrelate",
"=",
"False",
",",
"sigmoid",
"=",
"True",
")",
":",
"if",
"decorrelate",
":",
"t",
"=",
"_linear_decorelate_color",
"(",
"t",
")",
"if",
"decorrelate",
"and",
"not",
"sigmoid",
":",
"t",
"+=",
"color_... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | _populate_inception_bottlenecks | Add Inception bottlenecks and their pre-Relu versions to the graph. | lucid/modelzoo/other_models/InceptionV1.py | def _populate_inception_bottlenecks(scope):
"""Add Inception bottlenecks and their pre-Relu versions to the graph."""
graph = tf.get_default_graph()
for op in graph.get_operations():
if op.name.startswith(scope+'/') and 'Concat' in op.type:
name = op.name.split('/')[1]
pre_relus = []
for tow... | def _populate_inception_bottlenecks(scope):
"""Add Inception bottlenecks and their pre-Relu versions to the graph."""
graph = tf.get_default_graph()
for op in graph.get_operations():
if op.name.startswith(scope+'/') and 'Concat' in op.type:
name = op.name.split('/')[1]
pre_relus = []
for tow... | [
"Add",
"Inception",
"bottlenecks",
"and",
"their",
"pre",
"-",
"Relu",
"versions",
"to",
"the",
"graph",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/modelzoo/other_models/InceptionV1.py#L22-L34 | [
"def",
"_populate_inception_bottlenecks",
"(",
"scope",
")",
":",
"graph",
"=",
"tf",
".",
"get_default_graph",
"(",
")",
"for",
"op",
"in",
"graph",
".",
"get_operations",
"(",
")",
":",
"if",
"op",
".",
"name",
".",
"startswith",
"(",
"scope",
"+",
"'/... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | wrap_objective | Decorator for creating Objective factories.
Changes f from the closure: (args) => () => TF Tensor
into an Obejective factory: (args) => Objective
while perserving function name, arg info, docs... for interactive python. | lucid/optvis/objectives.py | def wrap_objective(f, *args, **kwds):
"""Decorator for creating Objective factories.
Changes f from the closure: (args) => () => TF Tensor
into an Obejective factory: (args) => Objective
while perserving function name, arg info, docs... for interactive python.
"""
objective_func = f(*args, **kwds)
objec... | def wrap_objective(f, *args, **kwds):
"""Decorator for creating Objective factories.
Changes f from the closure: (args) => () => TF Tensor
into an Obejective factory: (args) => Objective
while perserving function name, arg info, docs... for interactive python.
"""
objective_func = f(*args, **kwds)
objec... | [
"Decorator",
"for",
"creating",
"Objective",
"factories",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/objectives.py#L117-L129 | [
"def",
"wrap_objective",
"(",
"f",
",",
"*",
"args",
",",
"*",
"*",
"kwds",
")",
":",
"objective_func",
"=",
"f",
"(",
"*",
"args",
",",
"*",
"*",
"kwds",
")",
"objective_name",
"=",
"f",
".",
"__name__",
"args_str",
"=",
"\" [\"",
"+",
"\", \"",
"... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | neuron | Visualize a single neuron of a single channel.
Defaults to the center neuron. When width and height are even numbers, we
choose the neuron in the bottom right of the center 2x2 neurons.
Odd width & height: Even width & height:
+---+---+---+ +---+---+---+---+
| | | | ... | lucid/optvis/objectives.py | def neuron(layer_name, channel_n, x=None, y=None, batch=None):
"""Visualize a single neuron of a single channel.
Defaults to the center neuron. When width and height are even numbers, we
choose the neuron in the bottom right of the center 2x2 neurons.
Odd width & height: Even width & height:
... | def neuron(layer_name, channel_n, x=None, y=None, batch=None):
"""Visualize a single neuron of a single channel.
Defaults to the center neuron. When width and height are even numbers, we
choose the neuron in the bottom right of the center 2x2 neurons.
Odd width & height: Even width & height:
... | [
"Visualize",
"a",
"single",
"neuron",
"of",
"a",
"single",
"channel",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/objectives.py#L133-L161 | [
"def",
"neuron",
"(",
"layer_name",
",",
"channel_n",
",",
"x",
"=",
"None",
",",
"y",
"=",
"None",
",",
"batch",
"=",
"None",
")",
":",
"def",
"inner",
"(",
"T",
")",
":",
"layer",
"=",
"T",
"(",
"layer_name",
")",
"shape",
"=",
"tf",
".",
"sh... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | channel | Visualize a single channel | lucid/optvis/objectives.py | def channel(layer, n_channel, batch=None):
"""Visualize a single channel"""
if batch is None:
return lambda T: tf.reduce_mean(T(layer)[..., n_channel])
else:
return lambda T: tf.reduce_mean(T(layer)[batch, ..., n_channel]) | def channel(layer, n_channel, batch=None):
"""Visualize a single channel"""
if batch is None:
return lambda T: tf.reduce_mean(T(layer)[..., n_channel])
else:
return lambda T: tf.reduce_mean(T(layer)[batch, ..., n_channel]) | [
"Visualize",
"a",
"single",
"channel"
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/objectives.py#L165-L170 | [
"def",
"channel",
"(",
"layer",
",",
"n_channel",
",",
"batch",
"=",
"None",
")",
":",
"if",
"batch",
"is",
"None",
":",
"return",
"lambda",
"T",
":",
"tf",
".",
"reduce_mean",
"(",
"T",
"(",
"layer",
")",
"[",
"...",
",",
"n_channel",
"]",
")",
... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | direction | Visualize a direction | lucid/optvis/objectives.py | def direction(layer, vec, batch=None, cossim_pow=0):
"""Visualize a direction"""
if batch is None:
vec = vec[None, None, None]
return lambda T: _dot_cossim(T(layer), vec)
else:
vec = vec[None, None]
return lambda T: _dot_cossim(T(layer)[batch], vec) | def direction(layer, vec, batch=None, cossim_pow=0):
"""Visualize a direction"""
if batch is None:
vec = vec[None, None, None]
return lambda T: _dot_cossim(T(layer), vec)
else:
vec = vec[None, None]
return lambda T: _dot_cossim(T(layer)[batch], vec) | [
"Visualize",
"a",
"direction"
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/objectives.py#L189-L196 | [
"def",
"direction",
"(",
"layer",
",",
"vec",
",",
"batch",
"=",
"None",
",",
"cossim_pow",
"=",
"0",
")",
":",
"if",
"batch",
"is",
"None",
":",
"vec",
"=",
"vec",
"[",
"None",
",",
"None",
",",
"None",
"]",
"return",
"lambda",
"T",
":",
"_dot_c... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | direction_neuron | Visualize a single (x, y) position along the given direction | lucid/optvis/objectives.py | def direction_neuron(layer_name, vec, batch=None, x=None, y=None, cossim_pow=0):
"""Visualize a single (x, y) position along the given direction"""
def inner(T):
layer = T(layer_name)
shape = tf.shape(layer)
x_ = shape[1] // 2 if x is None else x
y_ = shape[2] // 2 if y is None else y
if batch i... | def direction_neuron(layer_name, vec, batch=None, x=None, y=None, cossim_pow=0):
"""Visualize a single (x, y) position along the given direction"""
def inner(T):
layer = T(layer_name)
shape = tf.shape(layer)
x_ = shape[1] // 2 if x is None else x
y_ = shape[2] // 2 if y is None else y
if batch i... | [
"Visualize",
"a",
"single",
"(",
"x",
"y",
")",
"position",
"along",
"the",
"given",
"direction"
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/objectives.py#L200-L211 | [
"def",
"direction_neuron",
"(",
"layer_name",
",",
"vec",
",",
"batch",
"=",
"None",
",",
"x",
"=",
"None",
",",
"y",
"=",
"None",
",",
"cossim_pow",
"=",
"0",
")",
":",
"def",
"inner",
"(",
"T",
")",
":",
"layer",
"=",
"T",
"(",
"layer_name",
")... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | direction_cossim | Visualize a direction (cossine similarity) | lucid/optvis/objectives.py | def direction_cossim(layer, vec, batch=None):
"""Visualize a direction (cossine similarity)"""
def inner(T):
act_mags = tf.sqrt(tf.reduce_sum(T(layer)**2, -1, keepdims=True))
vec_mag = tf.sqrt(tf.reduce_sum(vec**2))
mags = act_mags * vec_mag
if batch is None:
return tf.reduce_mean(T(layer) * v... | def direction_cossim(layer, vec, batch=None):
"""Visualize a direction (cossine similarity)"""
def inner(T):
act_mags = tf.sqrt(tf.reduce_sum(T(layer)**2, -1, keepdims=True))
vec_mag = tf.sqrt(tf.reduce_sum(vec**2))
mags = act_mags * vec_mag
if batch is None:
return tf.reduce_mean(T(layer) * v... | [
"Visualize",
"a",
"direction",
"(",
"cossine",
"similarity",
")"
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/objectives.py#L214-L224 | [
"def",
"direction_cossim",
"(",
"layer",
",",
"vec",
",",
"batch",
"=",
"None",
")",
":",
"def",
"inner",
"(",
"T",
")",
":",
"act_mags",
"=",
"tf",
".",
"sqrt",
"(",
"tf",
".",
"reduce_sum",
"(",
"T",
"(",
"layer",
")",
"**",
"2",
",",
"-",
"1... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | L1 | L1 norm of layer. Generally used as penalty. | lucid/optvis/objectives.py | def L1(layer="input", constant=0, batch=None):
"""L1 norm of layer. Generally used as penalty."""
if batch is None:
return lambda T: tf.reduce_sum(tf.abs(T(layer) - constant))
else:
return lambda T: tf.reduce_sum(tf.abs(T(layer)[batch] - constant)) | def L1(layer="input", constant=0, batch=None):
"""L1 norm of layer. Generally used as penalty."""
if batch is None:
return lambda T: tf.reduce_sum(tf.abs(T(layer) - constant))
else:
return lambda T: tf.reduce_sum(tf.abs(T(layer)[batch] - constant)) | [
"L1",
"norm",
"of",
"layer",
".",
"Generally",
"used",
"as",
"penalty",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/objectives.py#L247-L252 | [
"def",
"L1",
"(",
"layer",
"=",
"\"input\"",
",",
"constant",
"=",
"0",
",",
"batch",
"=",
"None",
")",
":",
"if",
"batch",
"is",
"None",
":",
"return",
"lambda",
"T",
":",
"tf",
".",
"reduce_sum",
"(",
"tf",
".",
"abs",
"(",
"T",
"(",
"layer",
... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | L2 | L2 norm of layer. Generally used as penalty. | lucid/optvis/objectives.py | def L2(layer="input", constant=0, epsilon=1e-6, batch=None):
"""L2 norm of layer. Generally used as penalty."""
if batch is None:
return lambda T: tf.sqrt(epsilon + tf.reduce_sum((T(layer) - constant) ** 2))
else:
return lambda T: tf.sqrt(epsilon + tf.reduce_sum((T(layer)[batch] - constant) ** 2)) | def L2(layer="input", constant=0, epsilon=1e-6, batch=None):
"""L2 norm of layer. Generally used as penalty."""
if batch is None:
return lambda T: tf.sqrt(epsilon + tf.reduce_sum((T(layer) - constant) ** 2))
else:
return lambda T: tf.sqrt(epsilon + tf.reduce_sum((T(layer)[batch] - constant) ** 2)) | [
"L2",
"norm",
"of",
"layer",
".",
"Generally",
"used",
"as",
"penalty",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/objectives.py#L256-L261 | [
"def",
"L2",
"(",
"layer",
"=",
"\"input\"",
",",
"constant",
"=",
"0",
",",
"epsilon",
"=",
"1e-6",
",",
"batch",
"=",
"None",
")",
":",
"if",
"batch",
"is",
"None",
":",
"return",
"lambda",
"T",
":",
"tf",
".",
"sqrt",
"(",
"epsilon",
"+",
"tf"... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | blur_input_each_step | Minimizing this objective is equivelant to blurring input each step.
Optimizing (-k)*blur_input_each_step() is equivelant to:
input <- (1-k)*input + k*blur(input)
An operation that was used in early feature visualization work.
See Nguyen, et al., 2015. | lucid/optvis/objectives.py | def blur_input_each_step():
"""Minimizing this objective is equivelant to blurring input each step.
Optimizing (-k)*blur_input_each_step() is equivelant to:
input <- (1-k)*input + k*blur(input)
An operation that was used in early feature visualization work.
See Nguyen, et al., 2015.
"""
def inner(T):... | def blur_input_each_step():
"""Minimizing this objective is equivelant to blurring input each step.
Optimizing (-k)*blur_input_each_step() is equivelant to:
input <- (1-k)*input + k*blur(input)
An operation that was used in early feature visualization work.
See Nguyen, et al., 2015.
"""
def inner(T):... | [
"Minimizing",
"this",
"objective",
"is",
"equivelant",
"to",
"blurring",
"input",
"each",
"step",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/objectives.py#L277-L291 | [
"def",
"blur_input_each_step",
"(",
")",
":",
"def",
"inner",
"(",
"T",
")",
":",
"t_input",
"=",
"T",
"(",
"\"input\"",
")",
"t_input_blurred",
"=",
"tf",
".",
"stop_gradient",
"(",
"_tf_blur",
"(",
"t_input",
")",
")",
"return",
"0.5",
"*",
"tf",
"."... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | channel_interpolate | Interpolate between layer1, n_channel1 and layer2, n_channel2.
Optimize for a convex combination of layer1, n_channel1 and
layer2, n_channel2, transitioning across the batch.
Args:
layer1: layer to optimize 100% at batch=0.
n_channel1: neuron index to optimize 100% at batch=0.
layer2: layer to optim... | lucid/optvis/objectives.py | def channel_interpolate(layer1, n_channel1, layer2, n_channel2):
"""Interpolate between layer1, n_channel1 and layer2, n_channel2.
Optimize for a convex combination of layer1, n_channel1 and
layer2, n_channel2, transitioning across the batch.
Args:
layer1: layer to optimize 100% at batch=0.
n_channel1... | def channel_interpolate(layer1, n_channel1, layer2, n_channel2):
"""Interpolate between layer1, n_channel1 and layer2, n_channel2.
Optimize for a convex combination of layer1, n_channel1 and
layer2, n_channel2, transitioning across the batch.
Args:
layer1: layer to optimize 100% at batch=0.
n_channel1... | [
"Interpolate",
"between",
"layer1",
"n_channel1",
"and",
"layer2",
"n_channel2",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/objectives.py#L303-L328 | [
"def",
"channel_interpolate",
"(",
"layer1",
",",
"n_channel1",
",",
"layer2",
",",
"n_channel2",
")",
":",
"def",
"inner",
"(",
"T",
")",
":",
"batch_n",
"=",
"T",
"(",
"layer1",
")",
".",
"get_shape",
"(",
")",
".",
"as_list",
"(",
")",
"[",
"0",
... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | penalize_boundary_complexity | Encourage the boundaries of an image to have less variation and of color C.
Args:
shp: shape of T("input") because this may not be known.
w: width of boundary to penalize. Ignored if mask is set.
mask: mask describing what area should be penalized.
Returns:
Objective. | lucid/optvis/objectives.py | def penalize_boundary_complexity(shp, w=20, mask=None, C=0.5):
"""Encourage the boundaries of an image to have less variation and of color C.
Args:
shp: shape of T("input") because this may not be known.
w: width of boundary to penalize. Ignored if mask is set.
mask: mask describing what area should be... | def penalize_boundary_complexity(shp, w=20, mask=None, C=0.5):
"""Encourage the boundaries of an image to have less variation and of color C.
Args:
shp: shape of T("input") because this may not be known.
w: width of boundary to penalize. Ignored if mask is set.
mask: mask describing what area should be... | [
"Encourage",
"the",
"boundaries",
"of",
"an",
"image",
"to",
"have",
"less",
"variation",
"and",
"of",
"color",
"C",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/objectives.py#L332-L358 | [
"def",
"penalize_boundary_complexity",
"(",
"shp",
",",
"w",
"=",
"20",
",",
"mask",
"=",
"None",
",",
"C",
"=",
"0.5",
")",
":",
"def",
"inner",
"(",
"T",
")",
":",
"arr",
"=",
"T",
"(",
"\"input\"",
")",
"# print shp",
"if",
"mask",
"is",
"None",... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | alignment | Encourage neighboring images to be similar.
When visualizing the interpolation between two objectives, it's often
desireable to encourage analagous boejcts to be drawn in the same position,
to make them more comparable.
This term penalizes L2 distance between neighboring images, as evaluated at
layer.
In... | lucid/optvis/objectives.py | def alignment(layer, decay_ratio=2):
"""Encourage neighboring images to be similar.
When visualizing the interpolation between two objectives, it's often
desireable to encourage analagous boejcts to be drawn in the same position,
to make them more comparable.
This term penalizes L2 distance between neighbor... | def alignment(layer, decay_ratio=2):
"""Encourage neighboring images to be similar.
When visualizing the interpolation between two objectives, it's often
desireable to encourage analagous boejcts to be drawn in the same position,
to make them more comparable.
This term penalizes L2 distance between neighbor... | [
"Encourage",
"neighboring",
"images",
"to",
"be",
"similar",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/objectives.py#L362-L393 | [
"def",
"alignment",
"(",
"layer",
",",
"decay_ratio",
"=",
"2",
")",
":",
"def",
"inner",
"(",
"T",
")",
":",
"batch_n",
"=",
"T",
"(",
"layer",
")",
".",
"get_shape",
"(",
")",
".",
"as_list",
"(",
")",
"[",
"0",
"]",
"arr",
"=",
"T",
"(",
"... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | diversity | Encourage diversity between each batch element.
A neural net feature often responds to multiple things, but naive feature
visualization often only shows us one. If you optimize a batch of images,
this objective will encourage them all to be different.
In particular, it caculuates the correlation matrix of act... | lucid/optvis/objectives.py | def diversity(layer):
"""Encourage diversity between each batch element.
A neural net feature often responds to multiple things, but naive feature
visualization often only shows us one. If you optimize a batch of images,
this objective will encourage them all to be different.
In particular, it caculuates th... | def diversity(layer):
"""Encourage diversity between each batch element.
A neural net feature often responds to multiple things, but naive feature
visualization often only shows us one. If you optimize a batch of images,
this objective will encourage them all to be different.
In particular, it caculuates th... | [
"Encourage",
"diversity",
"between",
"each",
"batch",
"element",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/objectives.py#L396-L425 | [
"def",
"diversity",
"(",
"layer",
")",
":",
"def",
"inner",
"(",
"T",
")",
":",
"layer_t",
"=",
"T",
"(",
"layer",
")",
"batch_n",
",",
"_",
",",
"_",
",",
"channels",
"=",
"layer_t",
".",
"get_shape",
"(",
")",
".",
"as_list",
"(",
")",
"flatten... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | input_diff | Average L2 difference between optimized image and orig_img.
This objective is usually mutliplied by a negative number and used as a
penalty in making advarsarial counterexamples. | lucid/optvis/objectives.py | def input_diff(orig_img):
"""Average L2 difference between optimized image and orig_img.
This objective is usually mutliplied by a negative number and used as a
penalty in making advarsarial counterexamples.
"""
def inner(T):
diff = T("input") - orig_img
return tf.sqrt(tf.reduce_mean(diff**2))
retu... | def input_diff(orig_img):
"""Average L2 difference between optimized image and orig_img.
This objective is usually mutliplied by a negative number and used as a
penalty in making advarsarial counterexamples.
"""
def inner(T):
diff = T("input") - orig_img
return tf.sqrt(tf.reduce_mean(diff**2))
retu... | [
"Average",
"L2",
"difference",
"between",
"optimized",
"image",
"and",
"orig_img",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/objectives.py#L429-L438 | [
"def",
"input_diff",
"(",
"orig_img",
")",
":",
"def",
"inner",
"(",
"T",
")",
":",
"diff",
"=",
"T",
"(",
"\"input\"",
")",
"-",
"orig_img",
"return",
"tf",
".",
"sqrt",
"(",
"tf",
".",
"reduce_mean",
"(",
"diff",
"**",
"2",
")",
")",
"return",
... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | class_logit | Like channel, but for softmax layers.
Args:
layer: A layer name string.
label: Either a string (refering to a label in model.labels) or an int
label position.
Returns:
Objective maximizing a logit. | lucid/optvis/objectives.py | def class_logit(layer, label):
"""Like channel, but for softmax layers.
Args:
layer: A layer name string.
label: Either a string (refering to a label in model.labels) or an int
label position.
Returns:
Objective maximizing a logit.
"""
def inner(T):
if isinstance(label, int):
cla... | def class_logit(layer, label):
"""Like channel, but for softmax layers.
Args:
layer: A layer name string.
label: Either a string (refering to a label in model.labels) or an int
label position.
Returns:
Objective maximizing a logit.
"""
def inner(T):
if isinstance(label, int):
cla... | [
"Like",
"channel",
"but",
"for",
"softmax",
"layers",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/objectives.py#L442-L461 | [
"def",
"class_logit",
"(",
"layer",
",",
"label",
")",
":",
"def",
"inner",
"(",
"T",
")",
":",
"if",
"isinstance",
"(",
"label",
",",
"int",
")",
":",
"class_n",
"=",
"label",
"else",
":",
"class_n",
"=",
"T",
"(",
"\"labels\"",
")",
".",
"index",... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | as_objective | Convert obj into Objective class.
Strings of the form "layer:n" become the Objective channel(layer, n).
Objectives are returned unchanged.
Args:
obj: string or Objective.
Returns:
Objective | lucid/optvis/objectives.py | def as_objective(obj):
"""Convert obj into Objective class.
Strings of the form "layer:n" become the Objective channel(layer, n).
Objectives are returned unchanged.
Args:
obj: string or Objective.
Returns:
Objective
"""
if isinstance(obj, Objective):
return obj
elif callable(obj):
ret... | def as_objective(obj):
"""Convert obj into Objective class.
Strings of the form "layer:n" become the Objective channel(layer, n).
Objectives are returned unchanged.
Args:
obj: string or Objective.
Returns:
Objective
"""
if isinstance(obj, Objective):
return obj
elif callable(obj):
ret... | [
"Convert",
"obj",
"into",
"Objective",
"class",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/objectives.py#L464-L483 | [
"def",
"as_objective",
"(",
"obj",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"Objective",
")",
":",
"return",
"obj",
"elif",
"callable",
"(",
"obj",
")",
":",
"return",
"obj",
"elif",
"isinstance",
"(",
"obj",
",",
"str",
")",
":",
"layer",
",",... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | _constrain_L2_grad | Gradient for constrained optimization on an L2 unit ball.
This function projects the gradient onto the ball if you are on the boundary
(or outside!), but leaves it untouched if you are inside the ball.
Args:
op: the tensorflow op we're computing the gradient for.
grad: gradient we need to backprop
Re... | lucid/optvis/param/unit_balls.py | def _constrain_L2_grad(op, grad):
"""Gradient for constrained optimization on an L2 unit ball.
This function projects the gradient onto the ball if you are on the boundary
(or outside!), but leaves it untouched if you are inside the ball.
Args:
op: the tensorflow op we're computing the gradient for.
g... | def _constrain_L2_grad(op, grad):
"""Gradient for constrained optimization on an L2 unit ball.
This function projects the gradient onto the ball if you are on the boundary
(or outside!), but leaves it untouched if you are inside the ball.
Args:
op: the tensorflow op we're computing the gradient for.
g... | [
"Gradient",
"for",
"constrained",
"optimization",
"on",
"an",
"L2",
"unit",
"ball",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/param/unit_balls.py#L20-L47 | [
"def",
"_constrain_L2_grad",
"(",
"op",
",",
"grad",
")",
":",
"inp",
"=",
"op",
".",
"inputs",
"[",
"0",
"]",
"inp_norm",
"=",
"tf",
".",
"norm",
"(",
"inp",
")",
"unit_inp",
"=",
"inp",
"/",
"inp_norm",
"grad_projection",
"=",
"dot",
"(",
"unit_inp... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | unit_ball_L2 | A tensorflow variable tranfomed to be constrained in a L2 unit ball.
EXPERIMENTAL: Do not use for adverserial examples if you need to be confident
they are strong attacks. We are not yet confident in this code. | lucid/optvis/param/unit_balls.py | def unit_ball_L2(shape):
"""A tensorflow variable tranfomed to be constrained in a L2 unit ball.
EXPERIMENTAL: Do not use for adverserial examples if you need to be confident
they are strong attacks. We are not yet confident in this code.
"""
x = tf.Variable(tf.zeros(shape))
return constrain_L2(x) | def unit_ball_L2(shape):
"""A tensorflow variable tranfomed to be constrained in a L2 unit ball.
EXPERIMENTAL: Do not use for adverserial examples if you need to be confident
they are strong attacks. We are not yet confident in this code.
"""
x = tf.Variable(tf.zeros(shape))
return constrain_L2(x) | [
"A",
"tensorflow",
"variable",
"tranfomed",
"to",
"be",
"constrained",
"in",
"a",
"L2",
"unit",
"ball",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/param/unit_balls.py#L55-L62 | [
"def",
"unit_ball_L2",
"(",
"shape",
")",
":",
"x",
"=",
"tf",
".",
"Variable",
"(",
"tf",
".",
"zeros",
"(",
"shape",
")",
")",
"return",
"constrain_L2",
"(",
"x",
")"
] | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | unit_ball_L_inf | A tensorflow variable tranfomed to be constrained in a L_inf unit ball.
Note that this code also preconditions the gradient to go in the L_inf
direction of steepest descent.
EXPERIMENTAL: Do not use for adverserial examples if you need to be confident
they are strong attacks. We are not yet confident in this ... | lucid/optvis/param/unit_balls.py | def unit_ball_L_inf(shape, precondition=True):
"""A tensorflow variable tranfomed to be constrained in a L_inf unit ball.
Note that this code also preconditions the gradient to go in the L_inf
direction of steepest descent.
EXPERIMENTAL: Do not use for adverserial examples if you need to be confident
they a... | def unit_ball_L_inf(shape, precondition=True):
"""A tensorflow variable tranfomed to be constrained in a L_inf unit ball.
Note that this code also preconditions the gradient to go in the L_inf
direction of steepest descent.
EXPERIMENTAL: Do not use for adverserial examples if you need to be confident
they a... | [
"A",
"tensorflow",
"variable",
"tranfomed",
"to",
"be",
"constrained",
"in",
"a",
"L_inf",
"unit",
"ball",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/param/unit_balls.py#L106-L119 | [
"def",
"unit_ball_L_inf",
"(",
"shape",
",",
"precondition",
"=",
"True",
")",
":",
"x",
"=",
"tf",
".",
"Variable",
"(",
"tf",
".",
"zeros",
"(",
"shape",
")",
")",
"if",
"precondition",
":",
"return",
"constrain_L_inf_precondition",
"(",
"x",
")",
"els... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | render_vis | Flexible optimization-base feature vis.
There's a lot of ways one might wish to customize otpimization-based
feature visualization. It's hard to create an abstraction that stands up
to all the things one might wish to try.
This function probably can't do *everything* you want, but it's much more
flexible th... | lucid/optvis/render.py | def render_vis(model, objective_f, param_f=None, optimizer=None,
transforms=None, thresholds=(512,), print_objectives=None,
verbose=True, relu_gradient_override=True, use_fixed_seed=False):
"""Flexible optimization-base feature vis.
There's a lot of ways one might wish to customize ot... | def render_vis(model, objective_f, param_f=None, optimizer=None,
transforms=None, thresholds=(512,), print_objectives=None,
verbose=True, relu_gradient_override=True, use_fixed_seed=False):
"""Flexible optimization-base feature vis.
There's a lot of ways one might wish to customize ot... | [
"Flexible",
"optimization",
"-",
"base",
"feature",
"vis",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/render.py#L44-L115 | [
"def",
"render_vis",
"(",
"model",
",",
"objective_f",
",",
"param_f",
"=",
"None",
",",
"optimizer",
"=",
"None",
",",
"transforms",
"=",
"None",
",",
"thresholds",
"=",
"(",
"512",
",",
")",
",",
"print_objectives",
"=",
"None",
",",
"verbose",
"=",
... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | make_vis_T | Even more flexible optimization-base feature vis.
This function is the inner core of render_vis(), and can be used
when render_vis() isn't flexible enough. Unfortunately, it's a bit more
tedious to use:
> with tf.Graph().as_default() as graph, tf.Session() as sess:
>
> T = make_vis_T(model, "mixed4a_p... | lucid/optvis/render.py | def make_vis_T(model, objective_f, param_f=None, optimizer=None,
transforms=None, relu_gradient_override=False):
"""Even more flexible optimization-base feature vis.
This function is the inner core of render_vis(), and can be used
when render_vis() isn't flexible enough. Unfortunately, it's a bit ... | def make_vis_T(model, objective_f, param_f=None, optimizer=None,
transforms=None, relu_gradient_override=False):
"""Even more flexible optimization-base feature vis.
This function is the inner core of render_vis(), and can be used
when render_vis() isn't flexible enough. Unfortunately, it's a bit ... | [
"Even",
"more",
"flexible",
"optimization",
"-",
"base",
"feature",
"vis",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/render.py#L118-L192 | [
"def",
"make_vis_T",
"(",
"model",
",",
"objective_f",
",",
"param_f",
"=",
"None",
",",
"optimizer",
"=",
"None",
",",
"transforms",
"=",
"None",
",",
"relu_gradient_override",
"=",
"False",
")",
":",
"# pylint: disable=unused-variable",
"t_image",
"=",
"make_t... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | grid | layout: numpy arrays x, y
metadata: user-defined numpy arrays with metadata
n_layer: number of cells in the layer (squared)
n_tile: number of cells in the tile (squared) | lucid/scratch/atlas_pipeline/grid.py | def grid(metadata, layout, params):
"""
layout: numpy arrays x, y
metadata: user-defined numpy arrays with metadata
n_layer: number of cells in the layer (squared)
n_tile: number of cells in the tile (squared)
"""
x = layout["x"]
y = layout["y"]
x_min = np.min(x)
x_max = np.max(x)
y_min = np.min(y... | def grid(metadata, layout, params):
"""
layout: numpy arrays x, y
metadata: user-defined numpy arrays with metadata
n_layer: number of cells in the layer (squared)
n_tile: number of cells in the tile (squared)
"""
x = layout["x"]
y = layout["y"]
x_min = np.min(x)
x_max = np.max(x)
y_min = np.min(y... | [
"layout",
":",
"numpy",
"arrays",
"x",
"y",
"metadata",
":",
"user",
"-",
"defined",
"numpy",
"arrays",
"with",
"metadata",
"n_layer",
":",
"number",
"of",
"cells",
"in",
"the",
"layer",
"(",
"squared",
")",
"n_tile",
":",
"number",
"of",
"cells",
"in",
... | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/scratch/atlas_pipeline/grid.py#L12-L68 | [
"def",
"grid",
"(",
"metadata",
",",
"layout",
",",
"params",
")",
":",
"x",
"=",
"layout",
"[",
"\"x\"",
"]",
"y",
"=",
"layout",
"[",
"\"y\"",
"]",
"x_min",
"=",
"np",
".",
"min",
"(",
"x",
")",
"x_max",
"=",
"np",
".",
"max",
"(",
"x",
")"... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | write_grid_local | Write a file for each tile | lucid/scratch/atlas_pipeline/grid.py | def write_grid_local(tiles, params):
"""
Write a file for each tile
"""
# TODO: this isn't being used right now, will need to be
# ported to gfile if we want to keep it
for ti,tj,tile in enumerate_tiles(tiles):
filename = "{directory}/{name}/tile_{n_layer}_{n_tile}_{ti}_{tj}".format(ti=ti, tj=tj, **para... | def write_grid_local(tiles, params):
"""
Write a file for each tile
"""
# TODO: this isn't being used right now, will need to be
# ported to gfile if we want to keep it
for ti,tj,tile in enumerate_tiles(tiles):
filename = "{directory}/{name}/tile_{n_layer}_{n_tile}_{ti}_{tj}".format(ti=ti, tj=tj, **para... | [
"Write",
"a",
"file",
"for",
"each",
"tile"
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/scratch/atlas_pipeline/grid.py#L70-L84 | [
"def",
"write_grid_local",
"(",
"tiles",
",",
"params",
")",
":",
"# TODO: this isn't being used right now, will need to be",
"# ported to gfile if we want to keep it",
"for",
"ti",
",",
"tj",
",",
"tile",
"in",
"enumerate_tiles",
"(",
"tiles",
")",
":",
"filename",
"="... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | enumerate_tiles | Convenience | lucid/scratch/atlas_pipeline/grid.py | def enumerate_tiles(tiles):
"""
Convenience
"""
enumerated = []
for key in tiles.keys():
enumerated.append((key[0], key[1], tiles[key]))
return enumerated | def enumerate_tiles(tiles):
"""
Convenience
"""
enumerated = []
for key in tiles.keys():
enumerated.append((key[0], key[1], tiles[key]))
return enumerated | [
"Convenience"
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/scratch/atlas_pipeline/grid.py#L86-L93 | [
"def",
"enumerate_tiles",
"(",
"tiles",
")",
":",
"enumerated",
"=",
"[",
"]",
"for",
"key",
"in",
"tiles",
".",
"keys",
"(",
")",
":",
"enumerated",
".",
"append",
"(",
"(",
"key",
"[",
"0",
"]",
",",
"key",
"[",
"1",
"]",
",",
"tiles",
"[",
"... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | _load_img | Load image file as numpy array. | lucid/misc/io/loading.py | def _load_img(handle, target_dtype=np.float32, size=None, **kwargs):
"""Load image file as numpy array."""
image_pil = PIL.Image.open(handle, **kwargs)
# resize the image to the requested size, if one was specified
if size is not None:
if len(size) > 2:
size = size[:2]
... | def _load_img(handle, target_dtype=np.float32, size=None, **kwargs):
"""Load image file as numpy array."""
image_pil = PIL.Image.open(handle, **kwargs)
# resize the image to the requested size, if one was specified
if size is not None:
if len(size) > 2:
size = size[:2]
... | [
"Load",
"image",
"file",
"as",
"numpy",
"array",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/io/loading.py#L47-L78 | [
"def",
"_load_img",
"(",
"handle",
",",
"target_dtype",
"=",
"np",
".",
"float32",
",",
"size",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"image_pil",
"=",
"PIL",
".",
"Image",
".",
"open",
"(",
"handle",
",",
"*",
"*",
"kwargs",
")",
"# resi... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | _load_text | Load and decode a string. | lucid/misc/io/loading.py | def _load_text(handle, split=False, encoding="utf-8"):
"""Load and decode a string."""
string = handle.read().decode(encoding)
return string.splitlines() if split else string | def _load_text(handle, split=False, encoding="utf-8"):
"""Load and decode a string."""
string = handle.read().decode(encoding)
return string.splitlines() if split else string | [
"Load",
"and",
"decode",
"a",
"string",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/io/loading.py#L86-L89 | [
"def",
"_load_text",
"(",
"handle",
",",
"split",
"=",
"False",
",",
"encoding",
"=",
"\"utf-8\"",
")",
":",
"string",
"=",
"handle",
".",
"read",
"(",
")",
".",
"decode",
"(",
"encoding",
")",
"return",
"string",
".",
"splitlines",
"(",
")",
"if",
"... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | _load_graphdef_protobuf | Load GraphDef from a binary proto file. | lucid/misc/io/loading.py | def _load_graphdef_protobuf(handle, **kwargs):
"""Load GraphDef from a binary proto file."""
# as_graph_def
graph_def = tf.GraphDef.FromString(handle.read())
# check if this is a lucid-saved model
# metadata = modelzoo.util.extract_metadata(graph_def)
# if metadata is not None:
# url = ha... | def _load_graphdef_protobuf(handle, **kwargs):
"""Load GraphDef from a binary proto file."""
# as_graph_def
graph_def = tf.GraphDef.FromString(handle.read())
# check if this is a lucid-saved model
# metadata = modelzoo.util.extract_metadata(graph_def)
# if metadata is not None:
# url = ha... | [
"Load",
"GraphDef",
"from",
"a",
"binary",
"proto",
"file",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/io/loading.py#L92-L104 | [
"def",
"_load_graphdef_protobuf",
"(",
"handle",
",",
"*",
"*",
"kwargs",
")",
":",
"# as_graph_def",
"graph_def",
"=",
"tf",
".",
"GraphDef",
".",
"FromString",
"(",
"handle",
".",
"read",
"(",
")",
")",
"# check if this is a lucid-saved model",
"# metadata = mod... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | load | Load a file.
File format is inferred from url. File retrieval strategy is inferred from
URL. Returned object type is inferred from url extension.
Args:
url_or_handle: a (reachable) URL, or an already open file handle
Raises:
RuntimeError: If file extension or URL is not supported. | lucid/misc/io/loading.py | def load(url_or_handle, cache=None, **kwargs):
"""Load a file.
File format is inferred from url. File retrieval strategy is inferred from
URL. Returned object type is inferred from url extension.
Args:
url_or_handle: a (reachable) URL, or an already open file handle
Raises:
RuntimeErr... | def load(url_or_handle, cache=None, **kwargs):
"""Load a file.
File format is inferred from url. File retrieval strategy is inferred from
URL. Returned object type is inferred from url extension.
Args:
url_or_handle: a (reachable) URL, or an already open file handle
Raises:
RuntimeErr... | [
"Load",
"a",
"file",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/io/loading.py#L120-L152 | [
"def",
"load",
"(",
"url_or_handle",
",",
"cache",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"ext",
"=",
"get_extension",
"(",
"url_or_handle",
")",
"try",
":",
"loader",
"=",
"loaders",
"[",
"ext",
".",
"lower",
"(",
")",
"]",
"message",
"=",
... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | crop_or_pad_to | Ensures the specified spatial shape by either padding or cropping.
Meant to be used as a last transform for architectures insisting on a specific
spatial shape of their inputs. | lucid/optvis/transform.py | def crop_or_pad_to(height, width):
"""Ensures the specified spatial shape by either padding or cropping.
Meant to be used as a last transform for architectures insisting on a specific
spatial shape of their inputs.
"""
def inner(t_image):
return tf.image.resize_image_with_crop_or_pad(t_image... | def crop_or_pad_to(height, width):
"""Ensures the specified spatial shape by either padding or cropping.
Meant to be used as a last transform for architectures insisting on a specific
spatial shape of their inputs.
"""
def inner(t_image):
return tf.image.resize_image_with_crop_or_pad(t_image... | [
"Ensures",
"the",
"specified",
"spatial",
"shape",
"by",
"either",
"padding",
"or",
"cropping",
".",
"Meant",
"to",
"be",
"used",
"as",
"a",
"last",
"transform",
"for",
"architectures",
"insisting",
"on",
"a",
"specific",
"spatial",
"shape",
"of",
"their",
"... | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/transform.py#L154-L161 | [
"def",
"crop_or_pad_to",
"(",
"height",
",",
"width",
")",
":",
"def",
"inner",
"(",
"t_image",
")",
":",
"return",
"tf",
".",
"image",
".",
"resize_image_with_crop_or_pad",
"(",
"t_image",
",",
"height",
",",
"width",
")",
"return",
"inner"
] | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | _normalize_array | Given an arbitrary rank-3 NumPy array, produce one representing an image.
This ensures the resulting array has a dtype of uint8 and a domain of 0-255.
Args:
array: NumPy array representing the image
domain: expected range of values in array,
defaults to (0, 1), if explicitly set to None will use the... | lucid/misc/io/serialize_array.py | def _normalize_array(array, domain=(0, 1)):
"""Given an arbitrary rank-3 NumPy array, produce one representing an image.
This ensures the resulting array has a dtype of uint8 and a domain of 0-255.
Args:
array: NumPy array representing the image
domain: expected range of values in array,
defaults ... | def _normalize_array(array, domain=(0, 1)):
"""Given an arbitrary rank-3 NumPy array, produce one representing an image.
This ensures the resulting array has a dtype of uint8 and a domain of 0-255.
Args:
array: NumPy array representing the image
domain: expected range of values in array,
defaults ... | [
"Given",
"an",
"arbitrary",
"rank",
"-",
"3",
"NumPy",
"array",
"produce",
"one",
"representing",
"an",
"image",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/io/serialize_array.py#L31-L77 | [
"def",
"_normalize_array",
"(",
"array",
",",
"domain",
"=",
"(",
"0",
",",
"1",
")",
")",
":",
"# first copy the input so we're never mutating the user's data",
"array",
"=",
"np",
".",
"array",
"(",
"array",
")",
"# squeeze helps both with batch=1 and B/W and PIL's mo... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | _serialize_normalized_array | Given a normalized array, returns byte representation of image encoding.
Args:
array: NumPy array of dtype uint8 and range 0 to 255
fmt: string describing desired file format, defaults to 'png'
quality: specifies compression quality from 0 to 100 for lossy formats
Returns:
image data as BytesIO bu... | lucid/misc/io/serialize_array.py | def _serialize_normalized_array(array, fmt='png', quality=70):
"""Given a normalized array, returns byte representation of image encoding.
Args:
array: NumPy array of dtype uint8 and range 0 to 255
fmt: string describing desired file format, defaults to 'png'
quality: specifies compression quality from... | def _serialize_normalized_array(array, fmt='png', quality=70):
"""Given a normalized array, returns byte representation of image encoding.
Args:
array: NumPy array of dtype uint8 and range 0 to 255
fmt: string describing desired file format, defaults to 'png'
quality: specifies compression quality from... | [
"Given",
"a",
"normalized",
"array",
"returns",
"byte",
"representation",
"of",
"image",
"encoding",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/io/serialize_array.py#L80-L101 | [
"def",
"_serialize_normalized_array",
"(",
"array",
",",
"fmt",
"=",
"'png'",
",",
"quality",
"=",
"70",
")",
":",
"dtype",
"=",
"array",
".",
"dtype",
"assert",
"np",
".",
"issubdtype",
"(",
"dtype",
",",
"np",
".",
"unsignedinteger",
")",
"assert",
"np... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | serialize_array | Given an arbitrary rank-3 NumPy array,
returns the byte representation of the encoded image.
Args:
array: NumPy array of dtype uint8 and range 0 to 255
domain: expected range of values in array, see `_normalize_array()`
fmt: string describing desired file format, defaults to 'png'
quality: specifie... | lucid/misc/io/serialize_array.py | def serialize_array(array, domain=(0, 1), fmt='png', quality=70):
"""Given an arbitrary rank-3 NumPy array,
returns the byte representation of the encoded image.
Args:
array: NumPy array of dtype uint8 and range 0 to 255
domain: expected range of values in array, see `_normalize_array()`
fmt: string ... | def serialize_array(array, domain=(0, 1), fmt='png', quality=70):
"""Given an arbitrary rank-3 NumPy array,
returns the byte representation of the encoded image.
Args:
array: NumPy array of dtype uint8 and range 0 to 255
domain: expected range of values in array, see `_normalize_array()`
fmt: string ... | [
"Given",
"an",
"arbitrary",
"rank",
"-",
"3",
"NumPy",
"array",
"returns",
"the",
"byte",
"representation",
"of",
"the",
"encoded",
"image",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/io/serialize_array.py#L104-L118 | [
"def",
"serialize_array",
"(",
"array",
",",
"domain",
"=",
"(",
"0",
",",
"1",
")",
",",
"fmt",
"=",
"'png'",
",",
"quality",
"=",
"70",
")",
":",
"normalized",
"=",
"_normalize_array",
"(",
"array",
",",
"domain",
"=",
"domain",
")",
"return",
"_se... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | array_to_jsbuffer | Serialize 1d NumPy array to JS TypedArray.
Data is serialized to base64-encoded string, which is much faster
and memory-efficient than json list serialization.
Args:
array: 1d NumPy array, dtype must be one of JS_ARRAY_TYPES.
Returns:
JS code that evaluates to a TypedArray as string.
Raises:
T... | lucid/misc/io/serialize_array.py | def array_to_jsbuffer(array):
"""Serialize 1d NumPy array to JS TypedArray.
Data is serialized to base64-encoded string, which is much faster
and memory-efficient than json list serialization.
Args:
array: 1d NumPy array, dtype must be one of JS_ARRAY_TYPES.
Returns:
JS code that evaluates to a Typ... | def array_to_jsbuffer(array):
"""Serialize 1d NumPy array to JS TypedArray.
Data is serialized to base64-encoded string, which is much faster
and memory-efficient than json list serialization.
Args:
array: 1d NumPy array, dtype must be one of JS_ARRAY_TYPES.
Returns:
JS code that evaluates to a Typ... | [
"Serialize",
"1d",
"NumPy",
"array",
"to",
"JS",
"TypedArray",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/io/serialize_array.py#L126-L161 | [
"def",
"array_to_jsbuffer",
"(",
"array",
")",
":",
"if",
"array",
".",
"ndim",
"!=",
"1",
":",
"raise",
"TypeError",
"(",
"'Only 1d arrays can be converted JS TypedArray.'",
")",
"if",
"array",
".",
"dtype",
".",
"name",
"not",
"in",
"JS_ARRAY_TYPES",
":",
"r... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | ChannelReducer._apply_flat | Utility for applying f to inner dimension of acts.
Flattens acts into a 2D tensor, applies f, then unflattens so that all
dimesnions except innermost are unchanged. | lucid/misc/channel_reducer.py | def _apply_flat(cls, f, acts):
"""Utility for applying f to inner dimension of acts.
Flattens acts into a 2D tensor, applies f, then unflattens so that all
dimesnions except innermost are unchanged.
"""
orig_shape = acts.shape
acts_flat = acts.reshape([-1, acts.shape[-1]])
new_flat = f(acts... | def _apply_flat(cls, f, acts):
"""Utility for applying f to inner dimension of acts.
Flattens acts into a 2D tensor, applies f, then unflattens so that all
dimesnions except innermost are unchanged.
"""
orig_shape = acts.shape
acts_flat = acts.reshape([-1, acts.shape[-1]])
new_flat = f(acts... | [
"Utility",
"for",
"applying",
"f",
"to",
"inner",
"dimension",
"of",
"acts",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/channel_reducer.py#L52-L64 | [
"def",
"_apply_flat",
"(",
"cls",
",",
"f",
",",
"acts",
")",
":",
"orig_shape",
"=",
"acts",
".",
"shape",
"acts_flat",
"=",
"acts",
".",
"reshape",
"(",
"[",
"-",
"1",
",",
"acts",
".",
"shape",
"[",
"-",
"1",
"]",
"]",
")",
"new_flat",
"=",
... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | StyleLoss.set_style | Set target style variables.
Expected usage:
style_loss = StyleLoss(style_layers)
...
init_op = tf.global_variables_initializer()
init_op.run()
feeds = {... session.run() 'feeds' argument that will make 'style_layers'
tensors evaluate to activation values of ... | lucid/optvis/style.py | def set_style(self, input_feeds):
"""Set target style variables.
Expected usage:
style_loss = StyleLoss(style_layers)
...
init_op = tf.global_variables_initializer()
init_op.run()
feeds = {... session.run() 'feeds' argument that will make 'style_layers'
... | def set_style(self, input_feeds):
"""Set target style variables.
Expected usage:
style_loss = StyleLoss(style_layers)
...
init_op = tf.global_variables_initializer()
init_op.run()
feeds = {... session.run() 'feeds' argument that will make 'style_layers'
... | [
"Set",
"target",
"style",
"variables",
".",
"Expected",
"usage",
":",
"style_loss",
"=",
"StyleLoss",
"(",
"style_layers",
")",
"...",
"init_op",
"=",
"tf",
".",
"global_variables_initializer",
"()",
"init_op",
".",
"run",
"()",
"feeds",
"=",
"{",
"...",
"se... | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/optvis/style.py#L74-L90 | [
"def",
"set_style",
"(",
"self",
",",
"input_feeds",
")",
":",
"sess",
"=",
"tf",
".",
"get_default_session",
"(",
")",
"computed",
"=",
"sess",
".",
"run",
"(",
"self",
".",
"input_grams",
",",
"input_feeds",
")",
"for",
"v",
",",
"g",
"in",
"zip",
... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | _image_url | Create a data URL representing an image from a PIL.Image.
Args:
image: a numpy
mode: presently only supports "data" for data URL
Returns:
URL representing image | lucid/misc/io/showing.py | def _image_url(array, fmt='png', mode="data", quality=90, domain=None):
"""Create a data URL representing an image from a PIL.Image.
Args:
image: a numpy
mode: presently only supports "data" for data URL
Returns:
URL representing image
"""
supported_modes = ("data")
if mode not in supported_mo... | def _image_url(array, fmt='png', mode="data", quality=90, domain=None):
"""Create a data URL representing an image from a PIL.Image.
Args:
image: a numpy
mode: presently only supports "data" for data URL
Returns:
URL representing image
"""
supported_modes = ("data")
if mode not in supported_mo... | [
"Create",
"a",
"data",
"URL",
"representing",
"an",
"image",
"from",
"a",
"PIL",
".",
"Image",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/io/showing.py#L39-L56 | [
"def",
"_image_url",
"(",
"array",
",",
"fmt",
"=",
"'png'",
",",
"mode",
"=",
"\"data\"",
",",
"quality",
"=",
"90",
",",
"domain",
"=",
"None",
")",
":",
"supported_modes",
"=",
"(",
"\"data\"",
")",
"if",
"mode",
"not",
"in",
"supported_modes",
":",... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | image | Display an image.
Args:
array: NumPy array representing the image
fmt: Image format e.g. png, jpeg
domain: Domain of pixel values, inferred from min & max values if None
w: width of output image, scaled using nearest neighbor interpolation.
size unchanged if None | lucid/misc/io/showing.py | def image(array, domain=None, width=None, format='png', **kwargs):
"""Display an image.
Args:
array: NumPy array representing the image
fmt: Image format e.g. png, jpeg
domain: Domain of pixel values, inferred from min & max values if None
w: width of output image, scaled using nearest neighbor int... | def image(array, domain=None, width=None, format='png', **kwargs):
"""Display an image.
Args:
array: NumPy array representing the image
fmt: Image format e.g. png, jpeg
domain: Domain of pixel values, inferred from min & max values if None
w: width of output image, scaled using nearest neighbor int... | [
"Display",
"an",
"image",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/io/showing.py#L62-L75 | [
"def",
"image",
"(",
"array",
",",
"domain",
"=",
"None",
",",
"width",
"=",
"None",
",",
"format",
"=",
"'png'",
",",
"*",
"*",
"kwargs",
")",
":",
"image_data",
"=",
"serialize_array",
"(",
"array",
",",
"fmt",
"=",
"format",
",",
"domain",
"=",
... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
train | images | Display a list of images with optional labels.
Args:
arrays: A list of NumPy arrays representing images
labels: A list of strings to label each image.
Defaults to show index if None
domain: Domain of pixel values, inferred from min & max values if None
w: width of output image, scaled using nea... | lucid/misc/io/showing.py | def images(arrays, labels=None, domain=None, w=None):
"""Display a list of images with optional labels.
Args:
arrays: A list of NumPy arrays representing images
labels: A list of strings to label each image.
Defaults to show index if None
domain: Domain of pixel values, inferred from min & max va... | def images(arrays, labels=None, domain=None, w=None):
"""Display a list of images with optional labels.
Args:
arrays: A list of NumPy arrays representing images
labels: A list of strings to label each image.
Defaults to show index if None
domain: Domain of pixel values, inferred from min & max va... | [
"Display",
"a",
"list",
"of",
"images",
"with",
"optional",
"labels",
"."
] | tensorflow/lucid | python | https://github.com/tensorflow/lucid/blob/d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e/lucid/misc/io/showing.py#L78-L99 | [
"def",
"images",
"(",
"arrays",
",",
"labels",
"=",
"None",
",",
"domain",
"=",
"None",
",",
"w",
"=",
"None",
")",
":",
"s",
"=",
"'<div style=\"display: flex; flex-direction: row;\">'",
"for",
"i",
",",
"array",
"in",
"enumerate",
"(",
"arrays",
")",
":"... | d1a1e2e4fd4be61b89b8cba20dc425a5ae34576e |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.