def __init__(self,): channel = 8 intermidiate_dim = 128 self.cnn1 = rm.Sequential([ # 28x28 -> 28x28 rm.Conv2d(channel=channel,filter=3,stride=1,padding=1), rm.LeakyRelu(), rm.Dropout(), # 28x28 -> 14x14 rm.Conv2d(channel=channel*2,filter=3,stride=2,padding=1), rm.LeakyRelu(), rm.Dropout(), # 14x14 -> 8x8 rm.Conv2d(channel=channel*4,filter=3,stride=2,padding=2), rm.LeakyRelu(), rm.Dropout(), # 8x8 -> 4x4 rm.Conv2d(channel=channel*8,filter=3,stride=2,padding=1), rm.LeakyRelu(), rm.Dropout(), ]) self.cnn2 = rm.Sequential([ #rm.Dropout(), rm.Flatten(), #rm.Dense(intermidiate_dim) ]) self.output = rm.Dense(1)
def __init__(self, class_map=None, cells=7, bbox=2, imsize=(224, 224), load_pretrained_weight=False, train_whole_network=False): if not hasattr(cells, "__getitem__"): cells = (cells, cells) self._cells = cells self._bbox = bbox model = Darknet() super(Yolov1, self).__init__(class_map, imsize, load_pretrained_weight, train_whole_network, model) self._last_dense_size = (self.num_class + 5 * bbox) * cells[0] * cells[1] self._freezed_network = rm.Sequential(model[:-4]) self._network = rm.Sequential([ rm.Conv2d(channel=1024, filter=3, padding=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=1024, filter=3, padding=1, stride=2, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=1024, filter=3, padding=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=1024, filter=3, padding=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.Flatten(), rm.Dense( 4096 ), # instead of locally connected layer, we are using Dense layer rm.LeakyRelu(slope=0.1), rm.Dropout(0.5), rm.Dense(self._last_dense_size) ]) self._opt = rm.Sgd(0.0005, 0.9)
def __init__( self, enc_base, dec, batch_size, latent_dim = 2, mode = 'simple', label_dim = 0, prior = 'normal', prior_dist = None, hidden = 1000, full_rate=0.1, # 全体の形を重視するかラベル毎を重視するか fm_rate=1., # full_rateと同じ目的 ): self.latent_dim = latent_dim self.mode = mode self.label_dim = label_dim self.batch_size = batch_size self.prior = prior self.prior_dist = prior_dist self.full_rate = full_rate self.fm_rate = fm_rate if self.mode=='clustering' or self.mode=='reduction': self.enc = Enc(enc_base, (latent_dim, label_dim), output_act=(None, rm.softmax)) else: self.enc = Enc(enc_base, latent_dim) self.dec = dec self.dis = rm.Sequential([ rm.Dense(hidden), rm.LeakyRelu(), rm.Dense(hidden), rm.LeakyRelu(), rm.Dense(1), rm.Sigmoid() ]) if self.mode=='clustering' or self.mode=='reduction': self.cds = rm.Sequential([ # xxx rm.BatchNormalize(), # Disの最初にBNは配置してはだめ rm.Dense(hidden), rm.LeakyRelu(), rm.BatchNormalize(), rm.Dense(hidden), rm.LeakyRelu(), #rm.BatchNormalize(), rm.Dense(1), rm.Sigmoid() ])
# --- model configuration --- enc_base = rm.Sequential([ #rm.BatchNormalize(), rm.Dense(hidden), rm.Relu(), #rm.Dropout(), rm.BatchNormalize(), rm.Dense(hidden), rm.Relu(), #rm.Dropout(), # xxx rm.BatchNormalize(), # Genの最後にBNを配置してはだめ rm.Dense(latent_dim, initializer=Uniform()) ]) dec = rm.Sequential([ #rm.BatchNormalize(), rm.Dense(hidden), rm.LeakyRelu(), rm.BatchNormalize(), rm.Dense(hidden), rm.LeakyRelu(), #rm.BatchNormalize(), rm.Dense(28 * 28), rm.Sigmoid() ]) ae = AAE(enc_base, dec, batch_size, latent_dim=latent_dim, hidden=200, prior=model_dist, mode=model_type,
def __init__(self, num_class=1000, load_pretrained_weight=False): super(Darknet, self).__init__([ # 1st Block rm.Conv2d(channel=64, filter=7, stride=2, padding=3, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.MaxPool2d(stride=2, filter=2), # 2nd Block rm.Conv2d(channel=192, filter=3, padding=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.MaxPool2d(stride=2, filter=2), # 3rd Block rm.Conv2d(channel=128, filter=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=256, filter=3, padding=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=256, filter=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=512, filter=3, padding=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.MaxPool2d(stride=2, filter=2), # 4th Block rm.Conv2d(channel=256, filter=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=512, filter=3, padding=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=256, filter=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=512, filter=3, padding=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=256, filter=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=512, filter=3, padding=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=256, filter=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=512, filter=3, padding=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=512, filter=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=1024, filter=3, padding=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.MaxPool2d(stride=2, filter=2), # 5th Block rm.Conv2d(channel=512, filter=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=1024, filter=3, padding=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=512, filter=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=1024, filter=3, padding=1, ignore_bias=True), rm.BatchNormalize(mode='feature'), rm.LeakyRelu(slope=0.1), # layers for ImageNet rm.Conv2d(channel=num_class, filter=1), rm.LeakyRelu(slope=0.1), rm.AveragePool2d(filter=7), rm.Softmax() ]) if load_pretrained_weight: if isinstance(load_pretrained_weight, bool): load_pretrained_weight = self.__class__.__name__ + '.h5' if not os.path.exists(load_pretrained_weight): download(self.WEIGHT_URL, load_pretrained_weight) self.load(load_pretrained_weight)
def __init__(self, last_unit_size, load_weight_path=None): # TODO: Passing last_unit_size is not good. assert load_weight_path is None or isinstance(load_weight_path, str) super(Darknet, self).__init__([ # 1st Block rm.Conv2d(channel=64, filter=7, stride=2, padding=3), rm.LeakyRelu(slope=0.1), rm.MaxPool2d(stride=2, filter=2), # 2nd Block rm.Conv2d(channel=192, filter=3, padding=1), rm.LeakyRelu(slope=0.1), rm.MaxPool2d(stride=2, filter=2), # 3rd Block rm.Conv2d(channel=128, filter=1), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=256, filter=3, padding=1), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=256, filter=1), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=512, filter=3, padding=1), rm.LeakyRelu(slope=0.1), rm.MaxPool2d(stride=2, filter=2), # 4th Block rm.Conv2d(channel=256, filter=1), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=512, filter=3, padding=1), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=256, filter=1), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=512, filter=3, padding=1), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=256, filter=1), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=512, filter=3, padding=1), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=256, filter=1), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=512, filter=3, padding=1), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=512, filter=1), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=1024, filter=3, padding=1), rm.LeakyRelu(slope=0.1), rm.MaxPool2d(stride=2, filter=2), # 5th Block rm.Conv2d(channel=512, filter=1), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=1024, filter=3, padding=1), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=512, filter=1), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=1024, filter=3, padding=1), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=1024, filter=3, padding=1), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=1024, filter=3, stride=2, padding=1), rm.LeakyRelu(slope=0.1), # 6th Block rm.Conv2d(channel=1024, filter=3, padding=1), rm.LeakyRelu(slope=0.1), rm.Conv2d(channel=1024, filter=3, padding=1), rm.LeakyRelu(slope=0.1), # 7th Block rm.Flatten(), rm.Dense(1024), rm.LeakyRelu(slope=0.1), rm.Dense(4096), rm.LeakyRelu(slope=0.1), rm.Dropout(0.5), # 8th Block rm.Dense(last_unit_size), ]) if load_weight_path is not None: # Call download method. path, ext = os.path.splitext(load_weight_path) if ext: self.load(load_weight_path) else: self.load(path + '.h5')