async def send_command_help(self, command): doc = Embed.from_dict({ 'title': f'{self.clean_prefix}{command.name} {command.signature}', 'description': command.help, 'color': get_color().value }) if command.aliases: doc.add_field(name='Aliases', inline=True, value=', '.join(command.aliases)) if command.cog: doc.add_field(name='Category', inline=True, value=command.cog.qualified_name) if command._max_concurrency and getattr( command._max_concurrency, 'per', None) != BucketType.default: doc.add_field(name='Concurrency', value='**%s** time(s) per **%s**' % (command._max_concurrency.number, command._max_concurrency.per.name), inline=True) await self.get_destination().send(embed=doc)
async def meme(self, ctx, site=None): """Fetch a meme from a defined or a random resource (always an image)""" if not site: site = random.choice([*self._generators.keys()]) try: pic, info = self._generators[site]() except KeyError: raise BadArgument("Not a valid site from the list of sites") await ctx.send(embed=Embed.from_dict({ 'image': { 'url': pic }, 'title': info.get('title', ''), 'author': { 'name': info.get('author', '') }, 'timestamp': call(getattr(info.get('creation'), 'isoformat', None), ''), 'color': get_color().value }))
def projection_dim_exp_fig(): import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt for ds in ['mini', 'tiered']: ax = plt.subplot(111) with open(f'exp_projection_dim_{ds}.pickle', 'rb') as handle: exp_dict = pickle.load(handle) x = exp_dict['args'] y_lim = np.inf for part in ['val', 'test']: name = f'{part}' res, _ = exp_dict[name] plt.plot(x, res, label=name, color=get_color(name), linewidth=2) y_lim = min(y_lim, np.min(res)) ax.legend(loc='lower center', fancybox=True, shadow=True, ncol=3) # plt.ylim(bottom=y_lim - 1) plt.grid() fig = plt.figure(1) plt.xlabel("reduced dimension") plt.ylabel("accuracy") plt.savefig(f"projection-dim-exp-{ds}.png") plt.close(fig)
def n_query_exp_fig(): import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt for ds in ['mini', 'tiered']: with open(f'exp_n_queries_{ds}.pickle', 'rb') as handle: exp_dict = pickle.load(handle) x = np.array(list(exp_dict.keys())) values = np.array(list(exp_dict.values())) y = values[:, 0, :] ax = plt.subplot(111) exp_name = ['simple', 'sub', 'ica', 'ica & bkm', 'ica & msp'] y_lim = None for n in [*range(y.shape[1])]: # plt.plot(x, y[:, n].reshape(-1, ), label=exp_name[n]) plt.plot(x[1:], y[:, n].reshape(-1, )[1:], label=exp_name[n], color=get_color(exp_name[n]), linewidth=2) if exp_name[n] == 'simple': y_lim = np.min(y[:, n]) ax.legend(loc='lower center', fancybox=True, shadow=True, ncol=3) plt.ylim(bottom=y_lim - 3) plt.grid() fig = plt.figure(1) plt.xlabel("queries") plt.ylabel("accuracy") plt.savefig(f"num-query-exp-{ds}.png") plt.close(fig)
def noise_exp_fig(): import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt for ds in ['mini', 'tiered']: with open(f'exp_noise_semi_{ds}.pickle', 'rb') as handle: exp_dict = pickle.load(handle) x = np.array(list(exp_dict.keys())) values = np.array(list(exp_dict.values())) y = values[:, 0, :] x_plot = range(x.shape[0]) ax = plt.subplot(111) exp_name = ['ica', 'ica & bkm', 'ica & msp'] y_lim = None for n in [*range(y.shape[1])]: plt.plot(x_plot, y[:, n].reshape(-1, ), label=exp_name[n], color=get_color(exp_name[n]), linewidth=2) if exp_name[n] == 'ica & msp': y_lim = np.max(y[:, n]) if ds == 'mini': compare_works = { 'lst': [70.1, 68.0, 66.00, 64.0, 62.4, 60.8, 60.4, 60.0], 'tpn': [62.7, 62.4, 61.85, 61.3, 61.00, 60.7, 59.95, 59.2], 'skm': [62.1, 61.9, 61.40, 60.9, 60.45, 60.0, 59.30, 58.6], } else: compare_works = { 'lst': [77.7, 76.25, 74.88, 73.5, 72.10, 70.7, 69.35, 68.0], 'tpn': [72.1, 72.00, 71.75, 71.5, 71.20, 70.9, 69.65, 68.4], 'skm': [68.6, 67.50, 67.25, 67.0, 66.10, 65.2, 64.88, 64.0], } for k, v in compare_works.items(): plt.plot(x_plot, v, label=k, color=get_color(k), linewidth=2) ax.legend(loc='upper center', fancybox=True, shadow=True, ncol=3) plt.ylim(top=y_lim + 3) plt.xticks(x_plot, x) plt.grid() fig = plt.figure(1) plt.xlabel("distracting classes") plt.ylabel("accuracy") plt.savefig(f"exp-noise-semi-{ds}.png") plt.close(fig)
def __init__(self, cog: Cog, prefix: str, *, per_page=3): if not isinstance(cog, Cog): raise TypeError("a valid cog wasn't passed") self._prefix = prefix self._doc = Embed(title=cog.qualified_name, description=cog.description, color=get_color()) super().__init__(cog.get_commands(), per_page=per_page)
def visualize_label(label): color = get_color() mask = np.zeros(label.shape + (3, )) obj_id = np.unique(label) # embed() for obj in obj_id: if obj > 0: mask[label == obj] = color[int(obj)] return mask
def __init__(self, group: Group, prefix: str, *, per_page=3): if not isinstance(group, Group): raise TypeError("a valid group wasn't passed") self._prefix = prefix self._doc = Embed(title=f'{prefix}{group.name} {group.signature}', description=format_description(group.help), color=get_color()) super().__init__(self._flatten_commands(group.commands), per_page=per_page)
def visualize(self, label, tracker_id): # only for inference color = get_color() masks = torch.zeros(*label.size(), 3, dtype=torch.uint8) labels = torch.zeros_like(label) max_id = torch.max(label).item() for oid in range(max_id + 1): masks[label == oid] = torch.tensor(color[tracker_id[oid]]) labels[label == oid] = torch.tensor([tracker_id[oid] + 1]) masks = masks * (self.fgmask > 0.5).cpu().squeeze().unsqueeze(-1) labels = labels.float() * (self.fgmask > 0.5).cpu().squeeze().float() # embed() return masks, labels.unsqueeze(-1)
async def send_bot_help(self, mapping): doc = Embed(color=get_color()) for cog, commands in mapping.items(): command_list = '\n'.join(f'{self.clean_prefix}{cmd}' for cmd in commands) if not cog: doc.description = command_list else: doc.add_field(name=cog.qualified_name, value=command_list, inline=False) await self.get_destination().send(embed=doc)
async def send_error_message(self, error): await self.context.send( embed=Embed(description=error, color=get_color().value))