1 Star 0 Fork 0

desperadoxhy/SAM-Adapt

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
check_token.py 2.94 KB
一键复制 编辑 原始数据 按行查看 历史
desperadoxhy 提交于 2023-10-27 23:48 . 使用五通道
# train.py
#!/usr/bin/env python3
""" train network using pytorch
Junde Wu
"""
import os
import sys
import argparse
from datetime import datetime
from collections import OrderedDict
import numpy as np
import torch
import torch.nn as nn
import torch.optim as optim
from sklearn.metrics import roc_auc_score, accuracy_score, confusion_matrix
import torchvision
import torchvision.transforms as transforms
from skimage import io
from sklearn.model_selection import KFold
from torch.utils.data import DataLoader, DistributedSampler, ConcatDataset
#from dataset import *
from torch.autograd import Variable
from PIL import Image
# from tensorboardX import SummaryWriter
#from models.discriminatorlayer import discriminator
from dataset import *
from conf import settings
import time
import cfg
from tqdm import tqdm
from torch.utils.data import DataLoader, random_split
from utils import *
import function
'''定义了一些图像预处理的操作,用于在训练和测试过程中对图像进行变换'''
transform_train = transforms.Compose([
transforms.Resize((args.image_size,args.image_size)),
transforms.ToTensor(),
])
transform_train_seg = transforms.Compose([
transforms.Resize((args.out_size,args.out_size)),
transforms.ToTensor(),
])
random_dataset = RandomDataset('DualModal2019/RGB/Training')
skip_iterations = args.skip
kf = KFold(n_splits=5, shuffle=True, random_state=42)
for fold, (train_index, test_index) in enumerate(kf.split(random_dataset)):
if fold < skip_iterations:
continue
print('开始第' + str(fold) + '次交叉验证')
train_subset = torch.utils.data.Subset(random_dataset, [train_index[0]])
test_subset = torch.utils.data.Subset(random_dataset, test_index)
train_subset = list(train_subset)
test_temp = list(test_subset)
test_list = [f"{i.split('.png')[0]}-{j}.png" for i in test_temp for j in range(29, 30)]
train_list = [f"{i.split('.png')[0]}-{j}.png" for i in train_subset for j in range(29, 30)]
args.dataset = '3c'
train_dataset_rgb = DualModalMultNfoldRGB(args, data_list=train_list, transform=transform_train, transform_msk=transform_train_seg)
train_dataset_3c = DualModalMultNfold3C(args, data_list=train_list, transform=transform_train, transform_msk=transform_train_seg)
net = get_network(args, args.net, use_gpu=args.gpu, gpu_device=device, distribution=args.distributed)
for ind, pack in enumerate(train_dataset_rgb):
imgsw = pack['image'].to(dtype=torch.float32, device=device)
imgsw_2 = train_dataset_3c[ind]['image'].to(dtype=torch.float32, device=device).unsqueeze(0)
print(imgsw_2.shape)
name = pack['image_meta_dict']['filename_or_obj']
print(name)
buoy = 0
mask_type = torch.float32
ind += 1
imgsw = imgsw.to(dtype=mask_type, device=device).unsqueeze(0)
with torch.no_grad():
print(imgsw.shape)
a = net.image_encoder(imgsw, imgsw_2)
print(a.shape)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/xuhengyuplus/SAM-Adapt.git
[email protected]:xuhengyuplus/SAM-Adapt.git
xuhengyuplus
SAM-Adapt
SAM-Adapt
multout

搜索帮助