Skip to content

Instantly share code, notes, and snippets.

@arunm8489
Created June 3, 2020 14:29
Show Gist options
  • Save arunm8489/6de48916cf8d10ab40037f66e9d2a38b to your computer and use it in GitHub Desktop.
Save arunm8489/6de48916cf8d10ab40037f66e9d2a38b to your computer and use it in GitHub Desktop.
if (block["type"] == "convolutional"):
activation = block["activation"]
filters = int(block["filters"])
kernel_size = int(block["size"])
strides = int(block["stride"])
use_bias= False if ("batch_normalize" in block) else True
pad = (kernel_size - 1) // 2
conv = nn.Conv2d(in_channels=channels, out_channels=filters, kernel_size=kernel_size,
stride=strides, padding=pad, bias = use_bias)
seq.add_module("conv_{0}".format(i), conv)
if "batch_normalize" in block:
bn = nn.BatchNorm2d(filters)
seq.add_module("batch_norm_{0}".format(i), bn)
if activation == "leaky":
activn = nn.LeakyReLU(0.1, inplace = True)
seq.add_module("leaky_{0}".format(i), activn)
elif (block["type"] == "upsample"):
upsample = nn.Upsample(scale_factor = 2, mode = "bilinear")
seq.add_module("upsample_{}".format(i), upsample)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment