介绍:
我正在尝试让 CDCGAN(条件深度卷积生成对抗网络)处理 MNIST 数据集,考虑到我使用的库(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
我需要检查一个元素是否不在两个列表中.我目前有:
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) 我正在尝试从 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)
如果文件夹结构相同,我可以进入每个目录,但是当每个存储桶的文件夹结构不同时,我该如何处理?
我正在尝试制作我自己的小不和谐机器人,它可以从 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) 我正在使用 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'
我已经浏览了所有文档和此处的所有类似问题,但仍然没有解决方案!
有人可以帮忙吗?
@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) 这是我试过的代码:
@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)
但它似乎不起作用。
我正在制作一个程序,可以将您的体重从公斤转换为磅,反之亦然。它会提示你输入一个重量,询问它是公斤还是磅,然后给你结果。
代码如下:
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)
如果我输入公斤并说它是公斤,转换器工作正常,但是当我将我的体重输入磅并说它以磅为单位时,它假定该值以公斤为单位并以磅为单位给出答案。谁能告诉我这是什么问题?
我需要检查discord.Member此命令中的 a 是否是机器人:
async def kick(ctx, user: discord.Member, *, reason="No Reason Provided"):
Run Code Online (Sandbox Code Playgroud)
提前致谢!
如何通过discord.py获取Discord用户自定义状态?
我看过discord.py 文档。我唯一能找到的是Member.status
它返回的状态为:在线/离线/空闲/dnd。
但不是新的自定义状态值。我也不是在寻找定制的存在。
python ×8
discord ×4
discord.py ×4
python-3.x ×4
if-statement ×2
amazon-s3 ×1
generative-adversarial-network ×1
list ×1
pytorch ×1
twitch ×1
twitch-api ×1