Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
Extend support to Python3 and PyTorch 0.4.1 for the validation routine
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioRAgostinho committed Aug 7, 2018
1 parent 9d68352 commit a4e0add
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def load_conv(buf, start, conv_model):
num_w = conv_model.weight.numel()
num_b = conv_model.bias.numel()
conv_model.bias.data.copy_(torch.from_numpy(buf[start:start+num_b])); start = start + num_b
conv_model.weight.data.copy_(torch.from_numpy(buf[start:start+num_w])); start = start + num_w
conv_model.weight.data.copy_(torch.from_numpy(buf[start:start+num_w]).view_as(conv_model.weight.data)); start = start + num_w
return start

def save_conv(fp, conv_model):
Expand All @@ -172,7 +172,7 @@ def load_conv_bn(buf, start, conv_model, bn_model):
bn_model.weight.data.copy_(torch.from_numpy(buf[start:start+num_b])); start = start + num_b
bn_model.running_mean.copy_(torch.from_numpy(buf[start:start+num_b])); start = start + num_b
bn_model.running_var.copy_(torch.from_numpy(buf[start:start+num_b])); start = start + num_b
conv_model.weight.data.copy_(torch.from_numpy(buf[start:start+num_w])); start = start + num_w
conv_model.weight.data.copy_(torch.from_numpy(buf[start:start+num_w]).view_as(conv_model.weight.data)); start = start + num_w
return start

def save_conv_bn(fp, conv_model, bn_model):
Expand All @@ -193,7 +193,7 @@ def load_fc(buf, start, fc_model):
num_w = fc_model.weight.numel()
num_b = fc_model.bias.numel()
fc_model.bias.data.copy_(torch.from_numpy(buf[start:start+num_b])); start = start + num_b
fc_model.weight.data.copy_(torch.from_numpy(buf[start:start+num_w])); start = start + num_w
fc_model.weight.data.copy_(torch.from_numpy(buf[start:start+num_w]).view_as(fc_model.weight.data)); start = start + num_w
return start

def save_fc(fp, fc_model):
Expand Down
10 changes: 5 additions & 5 deletions darknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def forward(self, x):
assert(W % stride == 0)
ws = stride
hs = stride
x = x.view(B, C, H/hs, hs, W/ws, ws).transpose(3,4).contiguous()
x = x.view(B, C, H/hs*W/ws, hs*ws).transpose(2,3).contiguous()
x = x.view(B, C, hs*ws, H/hs, W/ws).transpose(1,2).contiguous()
x = x.view(B, hs*ws*C, H/hs, W/ws)
x = x.view(B, C, H//hs, hs, W//ws, ws).transpose(3,4).contiguous()
x = x.view(B, C, H//hs*W//ws, hs*ws).transpose(2,3).contiguous()
x = x.view(B, C, hs*ws, H//hs, W//ws).transpose(1,2).contiguous()
x = x.view(B, hs*ws*C, H//hs, W//ws)
return x

class GlobalAvgPool2d(nn.Module):
Expand Down Expand Up @@ -146,7 +146,7 @@ def create_network(self, blocks):
kernel_size = int(block['size'])
stride = int(block['stride'])
is_pad = int(block['pad'])
pad = (kernel_size-1)/2 if is_pad else 0
pad = (kernel_size-1)//2 if is_pad else 0
activation = block['activation']
model = nn.Sequential()
if batch_normalize:
Expand Down
4 changes: 2 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ def get_color(c, x, max_val):
def read_truths(lab_path):
if os.path.getsize(lab_path):
truths = np.loadtxt(lab_path)
truths = truths.reshape(truths.size/21, 21) # to avoid single truth problem
truths = truths.reshape(truths.size//21, 21) # to avoid single truth problem
return truths
else:
return np.array([])
Expand Down Expand Up @@ -1008,7 +1008,7 @@ def file_lines(thefilepath):
buffer = thefile.read(8192*1024)
if not buffer:
break
count += buffer.count('\n')
count += buffer.count(b'\n')
thefile.close( )
return count

Expand Down

0 comments on commit a4e0add

Please sign in to comment.