diffusion训练提示Sizes of tensors must match except in dimension 1. Expected size 20 but got size 21 for

class TrainSet(Dataset):
    def __init__(self, classes):
        reader = pd.read_csv("D:/新建文件夹/train_data42.csv")
        data = reader['data'].tolist()
        label = reader['label'].tolist()
        datas = []
        for item in data:
            item = list(map(float, item.split(",")))
            datas.append(np.array(item).reshape(42, 1))
        datas = np.stack(datas)[np.array(label) == classes]
        self.datas = torch.from_numpy(datas).transpose(-1, -2).half()

    def __getitem__(self, index):
        return self.datas[index]

    def __len__(self):
        return len(self.datas)

if __name__ == '__main__':
    for i in range(10):
        # dataset = TrainSet(i)
        dim = 32
        batch_size = 32
        seq_length = 42
        channels = 1
        epoches = 100
        model = Unet1D(
            dim = dim,
            dim_mults = (1, 2, 4, 8),
            channels = channels
        )

        diffusion = GaussianDiffusion1D(
            model,
            seq_length = seq_length,
            timesteps = 1000,
            objective = 'pred_v'
        )

        dataset = TrainSet(i)

        trainer = Trainer1D(
            diffusion.to(device),
            dataset = dataset,
            train_batch_size = batch_size,
            train_lr = 8e-5,
            train_num_steps = epoches,         # total training steps
            gradient_accumulate_every = 2,    # gradient accumulation steps
            ema_decay = 0.995,                # exponential moving average decay
            amp = True,                       # turn on mixed precision
        )
        print(trainer.device)
        trainer.train()
        trainer.save(f"classes_{i}")


        # after a lot of training
        sampled_seqs = []
        for j in range(1024):
            sampled_seq = diffusion.sample(batch_size = 32)
            sampled_seqs.append(sampled_seq)
        # print(sampled_seq.shape) # (4, 32, 128)
        data = torch.cat(sampled_seqs).cpu().numpy()
        # print(data.shape)
        if not os.path.exists("results_unswnb15"):
            os.mkdir("results_unswnb15")
        # torch.save(data, f"results/data_{i}.pt")

        np.save(f"results_unswnb15\\data_{i}.npy", data)

代码如图,使用diffusion训练时提示

Traceback (most recent call last):
  File "D:\afeu\denoising-diffusion-pytorch-main\main-unswnb15.py", line 78, in <module>
    trainer.train()
  File "D:\afeu\denoising-diffusion-pytorch-main\denoising_diffusion_pytorch\denoising_diffusion_pytorch_1d.py", line 840, in train
    loss = self.model(data)
  File "D:\LenovoSoftstore\venv\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "D:\LenovoSoftstore\venv\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
  File "D:\afeu\denoising-diffusion-pytorch-main\denoising_diffusion_pytorch\denoising_diffusion_pytorch_1d.py", line 710, in forward
    return self.p_losses(img, t, *args, **kwargs)
  File "D:\afeu\denoising-diffusion-pytorch-main\denoising_diffusion_pytorch\denoising_diffusion_pytorch_1d.py", line 686, in p_losses
    model_out = self.model(x, t, x_self_cond)
  File "D:\LenovoSoftstore\venv\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "D:\LenovoSoftstore\venv\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
  File "D:\afeu\denoising-diffusion-pytorch-main\denoising_diffusion_pytorch\denoising_diffusion_pytorch_1d.py", line 370, in forward
    x = torch.cat((x, h.pop()), dim = 1)
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 20 but got size 21 for tensor number 1 in the list.

哪位大神帮帮忙呢?数据是42*1,10分类。

  • 8
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
YOLO系列是基于深度学习的端到端实时目标检测方法。 PyTorch版的YOLOv5轻量而性能高,更加灵活和易用,当前非常流行。 本课程将手把手地教大家使用labelImg标注和使用YOLOv5训练自己的数据集。课程实战分为两个项目:单目标检测(足球目标检测)和多目标检测(足球和梅西同时检测)。 本课程的YOLOv5使用ultralytics/yolov5,在Windows系统上做项目演示。包括:安装YOLOv5、标注自己的数据集、准备自己的数据集、修改配置文件、使用wandb训练可视化工具、训练自己的数据集、测试训练出的网络模型和性能统计。 希望学习Ubuntu上演示的同学,请前往 《YOLOv5(PyTorch)实战:训练自己的数据集(Ubuntu)》课程链接:https://edu.csdn.net/course/detail/30793  本人推出了有关YOLOv5目标检测的系列课程。请持续关注该系列的其它视频课程,包括:《YOLOv5(PyTorch)目标检测实战:训练自己的数据集》Ubuntu系统 https://edu.csdn.net/course/detail/30793Windows系统 https://edu.csdn.net/course/detail/30923《YOLOv5(PyTorch)目标检测:原理与源码解析》课程链接:https://edu.csdn.net/course/detail/31428《YOLOv5目标检测实战:Flask Web部署》课程链接:https://edu.csdn.net/course/detail/31087《YOLOv5(PyTorch)目标检测实战:TensorRT加速部署》课程链接:https://edu.csdn.net/course/detail/32303《YOLOv5目标检测实战:Jetson Nano部署》课程链接:https://edu.csdn.net/course/detail/32451《YOLOv5+DeepSORT多目标跟踪与计数精讲》课程链接:https://edu.csdn.net/course/detail/32669《YOLOv5实战口罩佩戴检测》课程链接:https://edu.csdn.net/course/detail/32744《YOLOv5实战中国交通标志识别》课程链接:https://edu.csdn.net/course/detail/35209《YOLOv5实战垃圾分类目标检测》课程链接:https://edu.csdn.net/course/detail/35284       

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值