-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from skumra/release/0.2.1
Release/0.2.1
- Loading branch information
Showing
17 changed files
with
205 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.96 filter=lfs diff=lfs merge=lfs -text | ||
.97 filter=lfs diff=lfs merge=lfs -text | ||
.98 filter=lfs diff=lfs merge=lfs -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import torch.nn as nn | ||
import torch.nn.functional as F | ||
|
||
|
||
class GraspModel(nn.Module): | ||
""" | ||
An abstract model for grasp network in a common format. | ||
""" | ||
|
||
def __init__(self): | ||
super(GraspModel, self).__init__() | ||
|
||
def forward(self, x_in): | ||
raise NotImplementedError() | ||
|
||
def compute_loss(self, xc, yc): | ||
y_pos, y_cos, y_sin, y_width = yc | ||
pos_pred, cos_pred, sin_pred, width_pred = self(xc) | ||
|
||
p_loss = F.smooth_l1_loss(pos_pred, y_pos) | ||
cos_loss = F.smooth_l1_loss(cos_pred, y_cos) | ||
sin_loss = F.smooth_l1_loss(sin_pred, y_sin) | ||
width_loss = F.smooth_l1_loss(width_pred, y_width) | ||
|
||
return { | ||
'loss': p_loss + cos_loss + sin_loss + width_loss, | ||
'losses': { | ||
'p_loss': p_loss, | ||
'cos_loss': cos_loss, | ||
'sin_loss': sin_loss, | ||
'width_loss': width_loss | ||
}, | ||
'pred': { | ||
'pos': pos_pred, | ||
'cos': cos_pred, | ||
'sin': sin_pred, | ||
'width': width_pred | ||
} | ||
} | ||
|
||
def predict(self, xc): | ||
pos_pred, cos_pred, sin_pred, width_pred = self(xc) | ||
return { | ||
'pos': pos_pred, | ||
'cos': cos_pred, | ||
'sin': sin_pred, | ||
'width': width_pred | ||
} | ||
|
||
|
||
class ResidualBlock(nn.Module): | ||
""" | ||
A residual block with dropout option | ||
""" | ||
|
||
def __init__(self, in_channels, out_channels, kernel_size=3, dropout=False, prob=0.0): | ||
super(ResidualBlock, self).__init__() | ||
self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size, padding=1) | ||
self.bn1 = nn.BatchNorm2d(in_channels) | ||
self.conv2 = nn.Conv2d(in_channels, out_channels, kernel_size, padding=1) | ||
self.bn2 = nn.BatchNorm2d(in_channels) | ||
|
||
self.dropout = dropout | ||
self.dropout1 = nn.Dropout(p=prob) | ||
|
||
def forward(self, x_in): | ||
x = self.bn1(self.conv1(x_in)) | ||
x = F.relu(x) | ||
if self.dropout: | ||
x = self.dropout1(x) | ||
x = self.bn2(self.conv2(x)) | ||
return x + x_in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.