• 大小: 23.78MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-06-22
  • 语言: Python
  • 标签: ML  

资源简介

MDNET论文的pytorch实现代码,python版本python2.7,相关论文请结合我的博客进行阅读。

资源截图

代码片段和文件信息

import os
import scipy.io
import numpy as np
from collections import OrderedDict

import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
import torch

def append_params(params module prefix):
    for child in module.children():
        for kp in child._parameters.iteritems():
            if p is None: continue
            
            if isinstance(child nn.BatchNorm2d):
                name = prefix + ‘_bn_‘ + k
            else:
                name = prefix + ‘_‘ + k
            
            if name not in params:
                params[name] = p
            else:
                raise RuntimeError(“Duplicated param name: %s“ % (name))


class LRN(nn.Module):
    def __init__(self):
        super(LRN self).__init__()

    def forward(self x):
        #
        # x: N x C x H x W
        pad = Variable(x.data.new(x.size(0) 1 1 x.size(2) x.size(3)).zero_())
        x_sq = (x**2).unsqueeze(dim=1)
        x_tile = torch.cat((torch.cat((x_sqpadpadpadpad)2)
                            torch.cat((padx_sqpadpadpad)2)
                            torch.cat((padpadx_sqpadpad)2)
                            torch.cat((padpadpadx_sqpad)2)
                            torch.cat((padpadpadpadx_sq)2))1)
        x_sumsq = x_tile.sum(dim=1).squeeze(dim=1)[:2:-2::]
        x = x / ((2.+0.0001*x_sumsq)**0.75)
        return x


class MDNet(nn.Module):
    def __init__(self model_path=None K=1):
        super(MDNet self).__init__()
        self.K = K
        self.layers = nn.Sequential(OrderedDict([
                (‘conv1‘ nn.Sequential(nn.Conv2d(3 96 kernel_size=7 stride=2)
                                        nn.ReLU()
                                        LRN()
                                        nn.MaxPool2d(kernel_size=3 stride=2)))
                (‘conv2‘ nn.Sequential(nn.Conv2d(96 256 kernel_size=5 stride=2)
                                        nn.ReLU()
                                        LRN()
                                        nn.MaxPool2d(kernel_size=3 stride=2)))
                (‘conv3‘ nn.Sequential(nn.Conv2d(256 512 kernel_size=3 stride=1)
                                        nn.ReLU()))
                (‘fc4‘   nn.Sequential(nn.Dropout(0.5)
                                        nn.Linear(512 * 3 * 3 512)
                                        nn.ReLU()))
                (‘fc5‘   nn.Sequential(nn.Dropout(0.5)
                                        nn.Linear(512 512)
                                        nn.ReLU()))]))
        
        self.branches = nn.ModuleList([nn.Sequential(nn.Dropout(0.5) 
                                                     nn.Linear(512 2)) for _ in range(K)])
        
        if model_path is not None:
            if os.path.splitext(model_path)[1] == ‘.pth‘:
                self.load_model(model_path)
            elif os.path.splitext(model_path)[1] == ‘.mat‘:
                sel

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-06-06 03:52  py-MDNet-master\
     文件         112  2017-06-06 03:52  py-MDNet-master\.gitignore
     文件        2597  2017-06-06 03:52  py-MDNet-master\LICENSE
     文件        1466  2017-06-06 03:52  py-MDNet-master\README.md
     目录           0  2017-06-06 03:52  py-MDNet-master\dataset\
     目录           0  2017-06-06 03:52  py-MDNet-master\dataset\OTB\
     目录           0  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\
     文件           0  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\.gitkeep
     文件          30  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\attrs.txt
     文件        6798  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\cfg.json
     文件         869  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\cfg.mat
     文件        1490  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\groundtruth_rect.txt
     目录           0  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\img\
     文件       80538  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\img\0001.jpg
     文件       86649  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\img\0002.jpg
     文件       87579  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\img\0003.jpg
     文件       87743  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\img\0004.jpg
     文件       85623  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\img\0005.jpg
     文件       82421  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\img\0006.jpg
     文件       82730  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\img\0007.jpg
     文件       81100  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\img\0008.jpg
     文件       81830  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\img\0009.jpg
     文件       78536  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\img\0010.jpg
     文件       77630  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\img\0011.jpg
     文件       77141  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\img\0012.jpg
     文件       75724  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\img\0013.jpg
     文件       75934  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\img\0014.jpg
     文件       75277  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\img\0015.jpg
     文件       76822  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\img\0016.jpg
     文件       76316  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\img\0017.jpg
     文件       73082  2017-06-06 03:52  py-MDNet-master\dataset\OTB\DragonBaby\img\0018.jpg
............此处省略115个文件信息

评论

共有 条评论