adds nn.Crop1d, nn.Crop2d, nn.Crop3d, see #1331#1349
adds nn.Crop1d, nn.Crop2d, nn.Crop3d, see #1331#1349bodokaiser wants to merge 7 commits intopytorch:masterfrom
Conversation
test/test_nn.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/nn/modules/crop.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/nn/modules/crop.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/nn/modules/crop.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/nn/modules/crop.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/nn/modules/crop.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/nn/modules/crop.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/nn/modules/crop.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/nn/modules/crop.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/nn/modules/crop.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
a10c8f8 to
cc21afa
Compare
|
With the latest build I get: ERROR: test_crop (__main__.TestNN)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_nn.py", line 693, in test_crop
self.assertEqual(c1(v1).sum(), v1[:, :, 3:7].sum())
File "/Users/bodokaiser/.pyenv/versions/pytorch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 207, in __call__
for hook in self._forward_hooks.values():
File "/Users/bodokaiser/.pyenv/versions/pytorch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 238, in __getattr__
type(self).__name__, name))
AttributeError: 'Crop1d' object has no attribute '_forward_hooks'Is this an inheritance problem? |
torch/nn/functional.py
Outdated
| def center_crop(x, *args): | ||
| ndim = len(x.size()[2:]) | ||
| if ndim == 1: | ||
| return Crop1d(args)(x) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/nn/modules/crop.py
Outdated
|
|
||
| def forward(self, x): | ||
| height, width, depth = x.size()[:2] | ||
| return F.pad(x, [ |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/nn/modules/crop.py
Outdated
| raise NotImplementedError("CropNd only supports mode center crop") | ||
|
|
||
| def _offset(self, initial, target): | ||
| crop = torch.FloatTensor([initial]).sub(target).div(-2) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
I also thought of a version which would supports arbitrary dimensions (passes tests too). def center_crop(x, *args):
size = x.size()[2:]
ndim = len(size)
assert ndim == len(args), 'Crop dimensions do not match input dimensions'
def crop(y, dim):
offset = math.ceil((size[dim] - args[dim]) / 2)
length = size[dim] - offset
indices = torch.arange(offset, length)
if isinstance(x, autograd.Variable):
indices = autograd.Variable(indices)
y = y.index_select(2 + dim, indices.long())
if dim == 0:
return y
return crop(y, dim - 1)
return crop(x, ndim - 1) |
|
We've discussed this PR and decided that it'd be best to only add |
|
|
I think we should support |
|
I'm closing this for now. Feel free to reopen when you update your branch. |
|
Yeah its still on my list I hope I find time for it the next weeks. Sorry for the delay. |
* Refactor War Sync Insertion Pass (pytorch#1339) * Remove kir::Expr::scope_ (pytorch#1341) * Fusion IR Refactor (pytorch#1343) * Refactor KIR Step 1 - Remove kir::Node (pytorch#1347) * Refactor KIR Step 2 - TMP IrUtils change (pytorch#1348) * Refactor KIR Step 3 - Remove kir::Expr and kir::Val. (pytorch#1349) * Refactor KIR Step 4 - Remove kir::Bool,Double,Int,NamedScalar. (pytorch#1350) * Refactor KIR Step 5 - Remove kir::IterDomain/TensorDomain/TensorView (pytorch#1351) * Refactor KIR Step 6 - Remove kir::UnaryOp/BinaryOp/TernaryOp/ReductionOp/WelfordOp/BroadcastOp. (pytorch#1352) * Refactor KIR Step 7 - Remove kir dispatch (pytorch#1353) * Refactor KIR Step 8 - Clean up lower_utils (pytorch#1355) * Refactor KIR Step 9 - lower_utils ir_utils::applyReplacements. (pytorch#1354) * Refactor KIR Step 10 - Remove kir_printer in favor of io_stream (pytorch#1356)
* add test * destroy model parallel was missing
No description provided.