Comments (4)
Hi @crossknight
Add a conv2d layer with 1x1 kernel to make them equal (look at resnet architecture).
from segmentation_models.pytorch.
Hi @qubvel,
Thanks for your reply. I tried your solution and It seems to be working fine but I'm sure that I implemented it correctly. Could you please review my codes?
Encoder
def forward(self, x):
x0 = self.conv1(x)
x0 = self.bn1(x0)
x0 = self.relu(x0)
x1 = self.maxpool(x0)
out_tensor = x1
x1 = self.layer1(x1)
in_tensor = x1
x1 = x1 + out_tensor.to('cuda')
x2 = self.layer2(x1)
conv2 = nn.Conv2d(64, 128, 1).to('cuda')
maxpool2 = nn.MaxPool2d(2).to('cuda')
out_tensor = conv2(in_tensor)
out_tensor = maxpool2(out_tensor)
in_tensor = x2
x2 = x2 + out_tensor.to('cuda')
x3 = self.layer3(x2)
conv3 = nn.Conv2d(128, 256, 1).to('cuda')
maxpool3 = nn.MaxPool2d(2).to('cuda')
out_tensor = conv3(in_tensor)
out_tensor = maxpool3(out_tensor)
in_tensor = x3
x3 = x3 + out_tensor.to('cuda')
x4 = self.layer4(x3)
conv4 = nn.Conv2d(256, 512, 1).to('cuda')
maxpool4 = nn.MaxPool2d(2).to('cuda')
out_tensor = conv4(in_tensor)
out_tensor = maxpool4(out_tensor)
x4 = x4 + out_tensor.to('cuda’)
return [x4, x3, x2, x1, x0]
Decoder
def forward(self, x):
encoder_head = x[0]
skips = x[1:]
in_tensor = encoder_head
m = nn.ConstantPad2d((8, 8, 8, 8), 0)
out_tensor = self.conv1(in_tensor)
out_tensor = m(out_tensor)
x = self.layer1([encoder_head, skips[0]])
in_tensor = x
x = x + out_tensor.to('cuda')
m = nn.ConstantPad2d((16, 16, 16, 16), 0)
out_tensor = self.conv2(in_tensor)
out_tensor = m(out_tensor)
x = self.layer2([x, skips[1]])
in_tensor = x
x = x + out_tensor.to('cuda')
m = nn.ConstantPad2d((32, 32, 32, 32), 0)
out_tensor = self.conv3(in_tensor)
out_tensor = m(out_tensor)
x = self.layer3([x, skips[2]])
in_tensor = x
x = x + out_tensor.to('cuda')
m = nn.ConstantPad2d((64, 64, 64, 64), 0)
out_tensor = self.conv4(in_tensor)
out_tensor = m(out_tensor)
x = self.layer4([x, skips[3]])
in_tensor = x
x = x + out_tensor.to('cuda')
m = nn.ConstantPad2d((128, 128, 128, 128), 0)
out_tensor = self.conv5(in_tensor)
out_tensor = m(out_tensor)
x = self.layer5([x, None])
x = x + out_tensor.to('cuda')
x = self.final_conv(x)
return x
from segmentation_models.pytorch.
Hi @crossknight
It is hard to read your code, look at some style guidlines/examples how to use pytorch to create a model in pytorch.
Why did you pad tensors?
Why did you move them to cuda in forward?
Make it step by step, print tensor shapes, use some tool for network architecture visualization (e.g. hiddenlayers
)
from segmentation_models.pytorch.
Hi @qubvel
Why did you pad tensors?
- (Decoder) because the 3rd,4th dimension of tensor are not the same size after passed the layer
Why did you move them to cuda in forward?
- because it will shows error about data are not on the same gpu/cpu
from segmentation_models.pytorch.
Related Issues (20)
- Segmentation fault (core dumped) Probelm HOT 2
- modify the code for instance segmentation HOT 2
- Clarify Error Message for Condition Checking 'threshold' in metrics/functional.py HOT 2
- Training interruption HOT 2
- UnetDecoder upsampling HOT 2
- Class weights specification on IoU metric HOT 2
- Is this library still maintained? HOT 7
- Using "segmentation_models_pytorch" with Unet++ HOT 2
- Error in loss calculation when using ignore_index HOT 2
- ModuleNotFoundError: No module named 'segmentation_models_pytorch.unetplusplus' HOT 2
- How to correct contribute example with pt-lightning from my fork to original repo HOT 1
- tracing mit-b1 on cpu and then running on gpu fails HOT 1
- epsilon in jaccardscore and dicescore is not read as a torch tensor HOT 1
- data preproccessing : mask = to_tensor HOT 4
- examples (notebooks) have not been updated HOT 1
- More classes result in smaller model?
- Extracting features from the model
- Get score per class
- Adding FeatUp
- get_preprocessing_fn
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from segmentation_models.pytorch.