Permute examples (#731)

* examples: use permute instead of transpose

* Use transpose but change args
This commit is contained in:
Jacky Lee 2023-03-28 18:07:06 -07:00 committed by GitHub
parent 39d6e1525f
commit 156640e90d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 3 deletions

View File

@ -72,7 +72,7 @@ class Conv3x3Biased:
# Not outChannel,inChannel,Y,X. # Not outChannel,inChannel,Y,X.
# Therefore, transpose it before assignment. # Therefore, transpose it before assignment.
# I have long since forgotten how I worked this out. # I have long since forgotten how I worked this out.
self.weight.assign(Tensor(layer["weight"]).reshape(shape=self.weight.shape).transpose(order=(0, 1, 3, 2))) self.weight.assign(Tensor(layer["weight"]).reshape(shape=self.weight.shape).transpose(2, 3))
self.bias.assign(Tensor(layer["bias"]).reshape(shape=self.bias.shape)) self.bias.assign(Tensor(layer["bias"]).reshape(shape=self.bias.shape))
class Vgg7: class Vgg7:

View File

@ -174,8 +174,7 @@ def predict_transform(prediction, inp_dim, anchors, num_classes):
bbox_attrs = 5 + num_classes bbox_attrs = 5 + num_classes
num_anchors = len(anchors) num_anchors = len(anchors)
prediction = prediction.reshape(shape=(batch_size, bbox_attrs*num_anchors, grid_size*grid_size)) prediction = prediction.reshape(shape=(batch_size, bbox_attrs*num_anchors, grid_size*grid_size))
# Original PyTorch: transpose(1, 2) -> For some reason numpy.transpose order has to be reversed? prediction = prediction.transpose(1, 2)
prediction = prediction.transpose(order=(0,2,1))
prediction = prediction.reshape(shape=(batch_size, grid_size*grid_size*num_anchors, bbox_attrs)) prediction = prediction.reshape(shape=(batch_size, grid_size*grid_size*num_anchors, bbox_attrs))
prediction_cpu = prediction.cpu().numpy() prediction_cpu = prediction.cpu().numpy()
for i in (0, 1, 4): for i in (0, 1, 4):