API_Net代码的train.txt与val.txt

import os

if __name__=="__main__":
    path = "/home/yjys/datasets/CUB_200_2011"
    train_test_file = "train_test_split.txt"
    image_class_label = "image_class_labels.txt"
    image = "images.txt"
    image_path = "/home/yjys/datasets/CUB_200_2011/images"

    image_name = []
    with open(os.path.join(path,image), 'r') as f:
        for line in f.readlines():
            img_name = os.path.join(image_path, line.strip("\n").split(" ")[1])
            image_name.append(img_name)

    train_test = []
    with open(os.path.join(path, train_test_file)) as f:
        for line in f.readlines():
            t_t = line.strip("\n").split(" ")[1]
            train_test.append(int(t_t))

    img_class_label = []
    with open(os.path.join(path, image_class_label)) as f:
        for line in f.readlines():
            c_l = line.strip("\n").split(" ")[1]
            img_class_label.append(int(c_l))

    with open("train.txt", 'w') as f:
        with open("val.txt", 'w') as fv:
            for index, name in enumerate(image_name):
                if train_test[index]:
                    f.write(name+" "+str(img_class_label[index]-1)+"\n")
                else:
                    fv.write(name+" "+str(img_class_label[index]-1)+"\n")


#IndexError: Target 200 is out of bounds.使用cpu炮程序后,出现的错误,也就是在计算🔠input和targets的损失函数的时候出现的错误
#RuntimeError: cuda runtime error (710) : device-side assert triggered 使用gpu炮程序,出现的错误,看不出来
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值