小编Dig*_*gy.的帖子

DCGAN 调试。得到只是垃圾

介绍:

我正在尝试让 CDCGAN(条件深度卷积生成对抗网络)处理 MNIST 数据集,考虑到我使用的库(PyTorch)在其网站上有教程,这应该相当容易。
但我似乎无法让它工作,它只会产生垃圾或模型崩溃或两者兼而有之。

我试过的:

  • 使模型有条件的半监督学习
  • 使用批处理规范
  • 除了生成器和鉴别器上的输入/输出层之外,在每一层上使用 dropout
  • 标签平滑以打击过度自信
  • 向图像添加噪声(我猜你称之为实例噪声)以获得更好的数据分布
  • 使用leaky relu来避免梯度消失
  • 使用重放缓冲区来防止忘记学到的东西和过度拟合
  • 玩超参数
  • 将其与 PyTorch 教程中的模型进行比较
  • 除了嵌入层等一些事情之外,基本上我做了什么。

我的模型生成的图像:

超参数:

batch_size=50, learning_rate_discrimiantor=0.0001, learning_rate_generator=0.0003, shuffle=True, ndf=64, ngf=64, dropout=0.5
在此处输入图片说明 在此处输入图片说明 在此处输入图片说明 在此处输入图片说明

batch_size=50, learning_rate_discriminator=0.0003, learning_rate_generator=0.0003, shuffle=True, ndf=64, ngf=64, dropout=0
在此处输入图片说明 在此处输入图片说明 在此处输入图片说明 在此处输入图片说明

图片Pytorch 教程 模型生成:

pytorch 教程 dcgan 模型的代码
作为比较,这里是来自 pytorch turoial 的 DCGAN 的图像:
在此处输入图片说明 在此处输入图片说明 在此处输入图片说明

我的代码:

import torch
import torch.nn as nn
import torchvision
from torchvision import transforms, datasets
import torch.nn.functional as F
from torch import optim as optim
from torch.utils.tensorboard import SummaryWriter …
Run Code Online (Sandbox Code Playgroud)

python neural-network pytorch generative-adversarial-network

30
推荐指数
1
解决办法
664
查看次数

Python:检查元素是否不在两个列表中?

我需要检查一个元素是否不在两个列表中.我目前有:

if ele not in lista:
    if ele not in listb:
        do stuff
Run Code Online (Sandbox Code Playgroud)

使用以下代码不起作用.有没有更有效的方法来完成上面的python?

if ele not in lista and listb:
    do stuff
Run Code Online (Sandbox Code Playgroud)

python if-statement list

7
推荐指数
1
解决办法
9410
查看次数

在每个 s3 存储桶中搜索并查看给定文件夹是否存在

我正在尝试从 s3 Buckets 中的特定文件夹中获取文件:

我在 s3 中有 4 个存储桶,名称如下:

1 - 'PDF'
2 - 'TXT'
3 - 'PNG'
4 - 'JPG'
Run Code Online (Sandbox Code Playgroud)

所有 s3 存储桶的文件夹结构如下所示:

1- PDF/analysis/pdf-to-img/processed/files
2- TXT/report/processed/files
3- PNG/analysis/reports/png-to-txt/processed/files
4- JPG/jpg-to-txt/empty
Run Code Online (Sandbox Code Playgroud)

我必须检查processed/files存储桶中是否存在此文件夹前缀,如果存在,我将读取这些目录中存在的文件,否则我将忽略它们。


代码:

buckets = ['PDF','TXT','PNG','JPG']

client = boto3.client('s3')
for i in bucket:
    result = client.list_objects(Bucket=i,Prefix = 'processed/files', Delimiter='/')
    print(result)
Run Code Online (Sandbox Code Playgroud)

如果文件夹结构相同,我可以进入每个目录,但是当每个存储桶的文件夹结构不同时,我该如何处理?

python amazon-s3 amazon-web-services python-3.x

6
推荐指数
1
解决办法
393
查看次数

如何在discord.py中循环任务

我正在尝试制作我自己的小不和谐机器人,它可以从 Twitch 获取信息,但我对如何使机器人循环并检查条件感到困惑。

我希望机器人每隔几秒钟循环一段代码,以检查指定的 twitch 频道是否处于活动状态。


代码

import discord
from discord.ext import commands, tasks
from twitch import TwitchClient
from pprint import pformat


client = TwitchClient(client_id='<twitch token>')

bot = commands.Bot(command_prefix='$')

@bot.event
async def on_ready():
    print('We have logged in as {0.user}'.format(bot))

@bot.command()
async def info(ctx, username):
    response = await ctx.send("Querying twitch database...")
    try:
        users = client.users.translate_usernames_to_ids(username)
        for user in users:
            print(user.id)
            userid = user.id
        twitchinfo = client.users.get_by_id(userid)
        status = client.streams.get_stream_by_user(userid)
        if status == None:
            print("Not live")
            livestat = twitchinfo.display_name + "is not …
Run Code Online (Sandbox Code Playgroud)

python-3.x twitch discord twitch-api

5
推荐指数
3
解决办法
2万
查看次数

如何让机器人加入语音频道 discord.py

我正在使用 discord.py 创建音乐机器人,但我无法将机器人连接到语音通道。我使用 Cog 将音乐功能与其他功能区分开来。

@commands.command()
async def join_voice(self, ctx):
    channel = ctx.author.voice.channel
    print(channel.id)
    await self.client.VoiceChannel.connect()
Run Code Online (Sandbox Code Playgroud)

但我收到错误: AttributeError: 'NoneType' object has no attribute 'channel'

我已经浏览了所有文档和此处的所有类似问题,但仍然没有解决方案!

有人可以帮忙吗?

python python-3.x discord.py discord.py-rewrite

3
推荐指数
1
解决办法
9129
查看次数

Discord.py @bot.event

@bot.event所以我有一个同时使用和 的脚本@bot.command()。问题是,当我等待时,@bot.event@bot.command()不会运行。

这是我的代码:

@bot.event
async def on_ready():
    print("Bot Is Ready And Online!")
    
async def react(message): 
    if message.content == "Meeting":
        await message.add_reaction("")

@bot.command()
async def info(ctx):
    await ctx.send("Hello, thanks for testing out our bot. ~ techNOlogics")

@bot.command(pass_context=True)
async def meet(ctx,time):
    if ctx.message.author.name == "techNOlogics":
        await ctx.channel.purge(limit=1)
        await ctx.send("**Meeting at " + time + " today!** React if you read.")

@bot.event ##THIS ONE HOLDS UP THE WHOLE SCRIPT
async def on_message(message):
    await react(message)
Run Code Online (Sandbox Code Playgroud)

python discord discord.py

3
推荐指数
1
解决办法
2万
查看次数

当有人提到它时,我如何让机器人做出回应?不和谐.py

这是我试过的代码:

@client.event
async def on_message(message):
    if client.user.mention in message.content.split():
        await client.say("You can type `!vx help` for more info.")
Run Code Online (Sandbox Code Playgroud)

但它似乎不起作用。

discord.py discord.py-rewrite

2
推荐指数
1
解决办法
7319
查看次数

关于我做的一个小转换器的 IF 语句问题

我正在制作一个程序,可以将您的体重从公斤转换为磅,反之亦然。它会提示你输入一个重量,询问它是公斤还是磅,然后给你结果。

代码如下:

weight = int(input("What is your weight? "))
unit = input ("(L)bs or (K)g? ")
unit = unit.upper
if unit == "L":
    converted = (weight * 0.45)
    print(converted)

else:
    converted = (weight // 0.45)
    print(converted)
Run Code Online (Sandbox Code Playgroud)

如果我输入公斤并说它是公斤,转换器工作正常,但是当我将我的体重输入磅并说它以磅为单位时,它假定该值以公斤为单位并以磅为单位给出答案。谁能告诉我这是什么问题?

python if-statement python-3.x

1
推荐指数
1
解决办法
143
查看次数

Discord.py 重写 - 如何检查 Discord.Member 是否是机器人

我需要检查discord.Member此命令中的 a 是否是机器人:

async def kick(ctx, user: discord.Member, *, reason="No Reason Provided"):
Run Code Online (Sandbox Code Playgroud)

提前致谢!

python discord discord.py

1
推荐指数
1
解决办法
1万
查看次数

Discord.py 获取自定义状态

如何通过discord.py获取Discord用户自定义状态?

我看过discord.py 文档。我唯一能找到的是Member.status 它返回的状态为:在线/离线/空闲/dnd。

但不是新的自定义状态值。我也不是在寻找定制的存在。

python discord

1
推荐指数
1
解决办法
4081
查看次数