DDPM玩具代码调试过程(一)

DDPM玩具代码来源:https://github.com/abarankab/DDPM

1.import报错:

不能用相对引用,需要把from .ema impot xxx 改成 from ema import xxx。所有类似的相对引用都需要修改。

2.报错:ValueError: args.log_to_wandb set to True but args.project_name is None

该报错信息是因为wandb没有注册的原因,参考链接wandb使用方法以及具体设置_wandb.init_神晟的光辉的博客-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/weixin_43164054/article/details/124156206

注册wandb账号并在当前虚拟环境下输入wandb login,将key复制后输入即可正常运行

3.wandb初始化报错

将初始化步骤中的entity参数删除就可以了,参考使用wandb报错:ERROR Error while calling W&B API: project not found (<Response [404]>)_error error while calling w&b api: user is not log_菜包好次的博客-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/weixin_43835996/article/details/126955917

wandb.init(entity='',
            project='',
            name=args.exp_name,
            config=args)
改为:

wandb.init(project='',
            name=args.exp_name,
            config=args)

4.报错:AttributeError: Can't pickle local object 'BaseDataset.img_transformer.<locals>.<lambda>'.............
EOFError: Ran out of input

搜索项目里的所有.py代码文件,一个文件的Ctrl+F搜索,看代码里面是否含有workers、mutilprocessing这两个关键字。搜索到workers将其值改为0即可,参考AttributeError: Can't pickle local object 'BaseDataset.img_transformer..'_weixin_39450145的博客-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/weixin_39450145/article/details/104901193

train_loader = script_utils.cycle(DataLoader(
    train_dataset,
    batch_size=batch_size,
    shuffle=True,
    drop_last=True,
    num_workers=2,
))

将其中的num_workers=0,问题解决


 

DDPM(Diffusion Probabilistic Models)是一种用于生成模型的深度学习方法。以下是 DDPM 的 TensorFlow 2.0 实现代码示例: ```python import tensorflow as tf from tensorflow.keras import layers class GaussianDiffusion(tf.keras.Model): def __init__(self, num_filters, num_diffusion_timesteps): super(GaussianDiffusion, self).__init__() self.num_filters = num_filters self.num_diffusion_timesteps = num_diffusion_timesteps self.diffusion_step = 1 / (num_diffusion_timesteps - 1) self.net = tf.keras.Sequential([ layers.Conv2D(num_filters, 3, padding='same', activation='relu'), layers.Conv2D(num_filters, 3, padding='same', activation='relu'), layers.Conv2D(num_filters, 3, padding='same', activation='relu'), layers.Conv2D(num_filters, 3, padding='same', activation='relu'), layers.Conv2D(num_filters, 3, padding='same', activation='relu'), layers.Conv2D(num_filters, 3, padding='same', activation=None), ]) def call(self, x, t, noise=None): x = tf.cast(x, tf.float32) t = tf.cast(t, tf.float32) x_shape = tf.shape(x) batch_size = x_shape[0] height = x_shape[1] width = x_shape[2] if noise is None: noise = tf.random.normal([batch_size, height, width, 3]) for i in range(self.num_diffusion_timesteps): scale = tf.math.sqrt(1 - self.diffusion_step * i) x_noisy = x + scale * noise net_in = tf.concat([x_noisy, t[:, tf.newaxis, tf.newaxis, tf.newaxis] * tf.ones_like(x_noisy)], axis=-1) noise = noise + self.net(net_in) * tf.math.sqrt(self.diffusion_step) return x_noisy ``` 这段代码实现了一个名为 GaussianDiffusion 的 TensorFlow 2.0 模型,并且提供了一个 `call` 方法,可以用于生成模型。其中,`num_filters` 表示卷积层中的滤波器数量,`num_diffusion_timesteps` 表示扩散时间步数。模型输入 `x` 表示图像,`t` 表示时间步,`noise` 表示噪声。最终,该模型会返回一个经过扩散的图像。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值