diff --git a/cfg.py b/cfg.py index ab7d5873..bfc68e44 100644 --- a/cfg.py +++ b/cfg.py @@ -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): @@ -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): @@ -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): diff --git a/darknet.py b/darknet.py index 623da39f..e5cb5dda 100644 --- a/darknet.py +++ b/darknet.py @@ -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): @@ -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: diff --git a/utils.py b/utils.py index c4f1b754..af074f6a 100644 --- a/utils.py +++ b/utils.py @@ -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([]) @@ -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