Пример #1
0
 def _construct_model(self, model_path):
     model = get_network('multilabel', NUMCLASS)
     statedic = torch.load(model_path, map_location='cpu')
     model.load_state_dict(statedic)
     model.to(self.device)
     model.eval()
     return model
Пример #2
0
 def _construct_model(self, model_path):
     model = get_network('resnext101_32x8d', 22)
     statedic = torch.load(model_path, map_location='cpu')
     model.load_state_dict(statedic)
     model.to(self.device)
     model.eval()
     return model
Пример #3
0
def frozen_model(dictpath):
    name = dictpath.split('/')[-1]
    epoch = name.split('_')[1]
    epoch = epoch.split('.')[0]
    model = get_network(MODELNAME, NUMCLASS)
    model.load_state_dict(torch.load(dictpath, map_location='cpu'))
    model.eval()
    model.cuda()
    example = torch.randn(1, 3, HEIGHT, WIDTH)
    with torch.no_grad():
        trace_script_module = torch.jit.trace(model, example.cuda())
        trace_script_module.save(os.path.join(MODELSAVEPATH, 'model_{}_frozen.pt'.format(epoch)))
    print('[*]! the jit is create now')
Пример #4
0
from config.value_config import *
from utils.model_select import get_network
import torch
from utils.lr_scheduler import WarmUpLR, get_lr_scheduler
from utils.eval import eval_fuse, displaymetric
import time
from utils.mixup import mixup_data, mixup_criterion

os.environ['CUDA_VISIBLE_DEVICES'] = GPUS
os.makedirs(LOGPATH, exist_ok=True)
summary_writer = SummaryWriter(LOGPATH)
os.makedirs(MODELSAVEPATH, exist_ok=True)

trainloader, testloader = loader(LOADERNAME)
beg = time.time()
net = get_network(MODELNAME, NUMCLASS)
if LOADING:
    net.load_state_dict(torch.load(LOADPATH, map_location='cpu'))
net.cuda()
if torch.cuda.device_count() > 1:
    net = DataParallel(net)
end = time.time()
print('[*]! model load time is{}'.format(end - beg))
iters = len(trainloader)
optimizer = torch.optim.SGD(net.parameters(),
                            lr=INITLR,
                            momentum=0.9,
                            weight_decay=WD)
scheduler = get_lr_scheduler(optimizer, LRTAG)
warmup = WarmUpLR(optimizer, iters * WARM)
Пример #5
0
    plt.xticks([])
    plt.yticks([])
    plt.title(title)
    return fig


def main(data, label):
    tsne = TSNE(n_components=2, init='pca', random_state=0)
    t0 = time()
    result = tsne.fit_transform(data)
    fig = plot_embedding(
        result, label,
        't-SNE embedding of the digits (time %.2fs)' % (time() - t0))
    plt.show(fig)


if __name__ == '__main__':
    dirpath = '/home/pc/gitcode/batch-dropblock-network/data/eyeData/bounding_box_test'
    state_path = '/home/pc/gitcode/multi_label/vgg16_multi_eye_shape_concetration/epoch139_test_acc0.5077519379844961.pth'
    net = get_network('vgg16', 5)
    tag = 'classifier.3'
    state_dic = torch.load(state_path, map_location='cpu')
    net.load_state_dict(state_dic)
    net = net.cpu()
    net.eval()
    hook_feature = HookFeature(dirpath, net)
    vecs, label = hook_feature.get_data(tag)
    print(vecs)
    print(label)
    main(vecs, label)