1 Star 0 Fork 0

WilliamLiPro / SparseConvNet

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
VGGplus.py 1.47 KB
一键复制 编辑 原始数据 按行查看 历史
Benjamin Graham 提交于 2018-12-18 09:30 . BSD license
# Copyright 2016-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import sparseconvnet as scn
from data import get_iterators
# two-dimensional SparseConvNet
class Model(nn.Module):
def __init__(self):
nn.Module.__init__(self)
self.sparseModel = scn.Sequential(
scn.SparseVggNet(2, 3, [
['C', 8, ], ['C', 8], 'MP',
['C', 16], ['C', 16], 'MP',
['C', 16, 8], ['C', 16, 8], 'MP',
['C', 24, 8], ['C', 24, 8], 'MP']),
scn.Convolution(2, 32, 64, 5, 1, False),
scn.BatchNormReLU(64),
scn.SparseToDense(2, 64))
self.spatial_size= self.sparseModel.input_spatial_size(torch.LongTensor([1, 1]))
self.inputLayer = scn.InputLayer(2,self.spatial_size,2)
self.linear = nn.Linear(64, 183)
def forward(self, x):
x = self.inputLayer(x)
x = self.sparseModel(x)
x = x.view(-1, 64)
x = self.linear(x)
return x
model = Model()
scale=63
dataset = get_iterators(model.spatial_size, scale)
print('Input spatial size:', model.spatial_size, 'Data scale:', scale)
scn.ClassificationTrainValidate(
model, dataset,
{'n_epochs': 100,
'initial_lr': 0.1,
'lr_decay': 0.05,
'weight_decay': 1e-4,
'use_cuda': torch.cuda.is_available(),
'check_point': False, })
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/WilliamLiPro/SparseConvNet.git
git@gitee.com:WilliamLiPro/SparseConvNet.git
WilliamLiPro
SparseConvNet
SparseConvNet
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891