pytorch定义datase多次重复采样

有的时候训练需要对样本重复抽样为一个batch,可以按如下格式定义:

bash 复制代码
class TrainLoader(Dataset):
    def __init__(self, fns, repeat=1):
        super(TrainLoader, self).__init__()
        self.length = len(fns) # 数据数量
        self.repeat = repeat # 数据重复次数
    def __getitem__(self, idx):
        idx = idx % self.length 
    def __len__(self):
        return self.length * self.repeat           
相关推荐
“初生”4 分钟前
用 Codex 做一致性 AI 动画:5 步工作流,角色不再漂移
人工智能·ai·chatgpt
AI_小站16 分钟前
刚面完百度的 Agent 开发岗,我才发现:世界就是个巨大的草台班子
java·开发语言·人工智能·spring·百度·langchain
随风而飘18620 分钟前
KEITHLEY吉时利 2400 数字源表
人工智能·功能测试·科技·测试工具
HyperAI超神经28 分钟前
【Triton 教程】triton_language.fdiv
人工智能·深度学习·triton
心无旁骛~32 分钟前
anywhere-labs/deepseek-harness-desktop 如何围绕上游演进:Submodule、版本溯源与非 Fork 架构
人工智能·架构
xiaohaiAIgeo38 分钟前
【2026年】医药研发实验室GLP的通风设计要求:稳定性可验证性与合规性
网络·人工智能·科普知识
ZGIAI40 分钟前
ZGI Runner 与 Sandbox:两层运行边界
人工智能·架构
ZGIAI1 小时前
ZGI Workspace:统一组织 Agent 资源
人工智能·架构
芯小途20261 小时前
微短剧新规 9 月 1 日施行:AIGC 微短剧的「AI 标识 + 占比追溯」怎么在制作流水线里落地(附自查脚本)
人工智能·aigc
微小冷1 小时前
在不同空间中展示数据(欧式、球面、庞加莱圆盘)
python·双曲空间·微分几何·geomstats·庞加莱圆盘·球面