Coder Social home page Coder Social logo

ccnet_pytorch's Introduction

CCNet_PyTorch

实验版本简介

  • 环境: Python3.6, Pytorch1.0
  • 各版本通用代码: MyData_kfold.py, MIouv0217.py, predict.py
  • CCNet0403代码: CC.py, ccnet.py, train_kfold.py
  • CCNet0509代码: CC.py, ccnet.py, ccnet_v3_0509.py, train_cc_v3_0509.py

实验数据集介绍

  • 一副无人机拍摄的高分辨率矿区影像图
  • 实验室进行标注的对应label
  • 进行裁剪后的320 x 320的图像与label数据

实验代码说明

  • MyData_kfold.py:数据载入代码,采用k折交叉验证载入数据
  • CC.py:CCNet中Criss-Cross Attention模块的实现
  • ccnet.py: 整个CCNet的实现代码,基于resnet
  • ccnet_v3_0509.py:实现CCA模块与aspp模块并行,CCA模块加入deeplabv3
  • train_kfold.py:CCNet0403版本训练代码,5折交叉验证方式读取训练
  • train_cc_v3_0509.py:CCNet0509版本训练代码,5折交叉验证方式训练
  • MIoUData.py:为计算MIoU载入label和预测数据
  • MIouv0217.py:计算Acc、MIoU等指标的代码,需使用MIoUData.py载入的数据
  • predict.py:使用训练好的模型进行预测,给预测结果涂色

实验版本及结果记录

  • CCNet参考版本:参考代码,使用了辅助loss,对结果的两个输出拼接成list,分别求loss,得到的模型效果很差。
    • ps:应该是自己对该代码实验的理解有误,后期改为论文中的样例,将x与x_dsn进行cat,再分割
  • CCNet_0403版本:放弃辅助loss,将两个输出cat,再进行分割,效果还算可以,实验结果如下表
  • CCNet_v3_0509版本:将CCA模块加入deeplabv3模块,与aspp模块并行,cat两者的输出,再分割,结果如下
  • CCNet0607: deeplabv3-ccnet-resnet152 + 5折交叉验证 + dataset3数据调整 + 使用weight减轻样本不均衡
版本&指标 Acc MIoU Kappa 地面 房屋 道路 车辆
CCnet0403 0.9412 0.6846 0.7845 0.9876 0.7803 0.9252 0.4353
CCnet0509 0.9593 0.7947 0.8593 0.9863 0.8818 0.8856 0.6740
CCNet0607 0.9603 0.8057 0.8684 0.9722 0.8907 0.9216 0.7745

实验预测结果与GT对比

  • CCNet0403版本,左至右为原图、GT、predict

  • CCNet_v3_0509版本,左至右为原图、GT、predict

    • CCNet-v3-0607版本(在0509版本加入样本权重且调整数据)实验预测图:

ccnet_pytorch's People

Contributors

yearing1017 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ccnet_pytorch's Issues

why self.gamma=zero(1)

`class CC_module(nn.Module):
def init(self,in_dim):
super(CC_module, self).init()
self.query_conv = nn.Conv2d(in_channels=in_dim, out_channels=in_dim//8, kernel_size=1)
self.key_conv = nn.Conv2d(in_channels=in_dim, out_channels=in_dim//8, kernel_size=1)
self.value_conv = nn.Conv2d(in_channels=in_dim, out_channels=in_dim, kernel_size=1)
self.softmax = Softmax(dim=3)
self.INF = INF
self.gamma = nn.Parameter(torch.zeros(1))
def forward(self, x):
m_batchsize, _, height, width = x.size()
proj_query = self.query_conv(x)
proj_query_H = proj_query.permute(0,3,1,2).contiguous().view(m_batchsizewidth,-1,height).permute(0, 2, 1)
proj_query_W = proj_query.permute(0,2,1,3).contiguous().view(m_batchsize
height,-1,width).permute(0, 2, 1)
proj_key = self.key_conv(x)
proj_key_H = proj_key.permute(0,3,1,2).contiguous().view(m_batchsizewidth,-1,height)
proj_key_W = proj_key.permute(0,2,1,3).contiguous().view(m_batchsize
height,-1,width)
proj_value = self.value_conv(x)
proj_value_H = proj_value.permute(0,3,1,2).contiguous().view(m_batchsizewidth,-1,height)
proj_value_W = proj_value.permute(0,2,1,3).contiguous().view(m_batchsize
height,-1,width)
energy_H = (torch.bmm(proj_query_H, proj_key_H)+self.INF(m_batchsize, height, width)).view(m_batchsize,width,height,height).permute(0,2,1,3)
energy_W = torch.bmm(proj_query_W, proj_key_W).view(m_batchsize,height,width,width)
concate = self.softmax(torch.cat([energy_H, energy_W], 3))

    att_H = concate[:,:,:,0:height].permute(0,2,1,3).contiguous().view(m_batchsize*width,height,height)
    #print(concate)
    #print(att_H) 
    att_W = concate[:,:,:,height:height+width].contiguous().view(m_batchsize*height,width,width)
    out_H = torch.bmm(proj_value_H, att_H.permute(0, 2, 1)).view(m_batchsize,width,-1,height).permute(0,2,3,1)
    out_W = torch.bmm(proj_value_W, att_W.permute(0, 2, 1)).view(m_batchsize,height,-1,width).permute(0,2,1,3)
    #print(out_H.size(),out_W.size())
    return self.gamma*(out_H + out_W) + x`

I am very confused with self.gamma = torch.zero(1)

关于训练数据

你好,请问你训练、验证和测试数据分别大概使用了多少张多大的图片?

关于CC-attention的实现

作者您好!
我查看了一些其他人的CC-Attention的实现,大部分似乎都需要通过什么cuda算子,不清楚为什么。 另外,我看了您的CC-attention的实现,觉得深受启发,有两个小问题咨询您:
1. energy_H = (energy_H + self.INF(m_batchsize, height, width)) , 这里为什么要加入 INF?
2. 您每个q, k, v都分成两个h, w部分,想问问这样的实现方法,是否与理论的CC-attention逻辑一致?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.