コード例 #1
0
    def build_net(self,is_train):
        super(NetU_ResNet,self).build_net(is_train)
        locals()['in0']=Input(shape=(self.row_in,self.col_in,self.dep_in))
        locals()['pre0']=self.preproc(locals()['in0'],'pre0',0,self.fs[0],self.act)
        creater,numbers=self.config[self.variation]
        base_model=creater(input_tensor=locals()['pre0'],include_top=False,weights='imagenet' if self.pre_trained else None)
        # print(base_model.summary())
        for layer in base_model.layers: layer.trainable=True  # allow training on pre-trained weights
        locals()['dmerge0']=locals()['dconv0']=None
        locals()['dproc1']=locals()['djoin1']=locals()['dsamp1']=base_model.get_layer("activation_1").output

        locals()['dmerge1']=locals()['dconv1']=None
        locals()['dproc2']=locals()['djoin2']=locals()['dsamp2']=base_model.get_layer("max_pooling2d_1").output

        for i in range(2,5):
            key="activation_%d"%(numbers[i-1])
            locals()['dmerge%d'%i]=locals()['dconv%d'%i]=base_model.get_layer(key).output
            locals()['dproc%d'%(i+1)]=locals()['djoin%d'%(i+1)]=None
        locals()['djoin5']=locals()['uproc5']=base_model.get_layer("activation_%d"%numbers[-1]).output

        for i in range(4,-1,-1):
            locals()['uconv%d'%(i+1)]=self.upconv(locals()['uproc%d'%(i+1)],'uconv%d'%(i+1),i,self.fs[i+1],self.act)
            locals()['ujoin%d'%(i+1)]=self.upjoin(locals()['uconv%d'%(i+1)],locals()['djoin%d'%(i+1)],'ujoin%d'%(i+1),i,self.fs[i+1],self.act)
            locals()['usamp%d'%i]=self.upsamp(locals()['ujoin%d'%(i+1)],self.ps[i],'usamp%d'%i,i,self.fs[i+1],self.act)
            locals()['umerge%d'%i]=self.upmerge(locals()['usamp%d'%i],locals()['dmerge%d'%i],'umerge%d'%i,i,self.fs[i],self.act)
            locals()['uproc%d'%i]=self.upproc(locals()['umerge%d'%i],'uproc%d'%i,i,self.fs[i],self.act)

        locals()['post0']=self.postproc(locals()['uproc0'],'post0',0,self.fs[0],self.act)
        locals()['out0']=cvac(locals()['post0'],'out0',0,self.dep_out,self.out,size=1)
        self.net=Model(locals()['in0'],locals()['out0'])
コード例 #2
0
    def build_net(self,is_train):
        super(NetUBack,self).build_net(is_train)
        locals()['in0']=Input((self.row_in, self.col_in, self.dep_in))
        # locals()['pre0']=self.preproc(locals()['in0'],'pre0',0,self.fs[0],self.act)
        # for i in range(len(self.fs)-1):
        #     prev_layer=locals()['pre%d'%i] if i==0 else locals()['dproc%d'%i]
        #     locals()['dconv%d'%i]=self.downconv(prev_layer, 'dconv%d'%i, i, self.fs[i], self.act)
        #     locals()['djoin%d'%i]=self.downjoin(locals()['dconv%d'%i], prev_layer, 'djoin%d'%i, i, self.fs[i], self.act)
        #     locals()['dsamp%d'%(i+1)]=self.downsamp(locals()['djoin%d'%i], self.ps[i], 'dsamp%d'%(i+1), i, self.fs[i], self.act)
        #     locals()['dmerge%d'%(i+1)]=self.downmerge(locals()['dsamp%d'%(i+1)], prev_layer, 'dmerge%d'%(i+1), i+1, self.fs[i+1], self.act, stride=self.ps[i])
        #     locals()['dproc%d'%(i+1)]=self.downproc(locals()['dmerge%d'%(i+1)], 'dproc%d'%(i+1), i+1, self.fs[i+1], self.act)
        locals()['join1'],locals()['join2'],locals()['join3'],locals()['join4'],locals()['join5']=self.backbone(locals()['in0'])

        for i in range(len(self.fs)-2, -1, -1):
            prev_layer = locals()['join%d'%(i+1)] if i==len(self.fs)-2 else locals()['uproc%d'%(i+1)]
            locals()['uconv%d'%(i+1)]=self.upconv(prev_layer, 'uconv%d'%(i+1), i, self.fs[i+1], self.act)
            locals()['ujoin%d'%(i+1)]=self.upjoin(locals()['uconv%d'%(i+1)],locals()['join%d'%(i+1)],'ujoin%d'%(i+1),i,self.fs[i+1],self.act)
            locals()['usamp%d'%i]=self.upsamp(locals()['uconv%d'%(i+1)], self.ps[i], 'usamp%d'%i, i, self.fs[i+1], self.act)
            locals()['uproc%d'%i]=self.upproc(locals()['usamp%d'%i], 'uproc%d'%i, i, self.fs[i], self.act)
    
        locals()['post0']=self.postproc(locals()['uproc0'],'post0',0,self.fs[0],self.act)
        locals()['out0']=cvac(locals()['post0'], 'out0', 0, self.dep_out, self.out, size=1)
        self.net=Model(locals()['in0'], locals()['out0'])

        if self.freeze_bn:
            print("Freeze All Batch Normalization Layers",sep=" ")
            for layer in self.net.layers:
                class_name=layer.__class__.__name__
                if class_name=='BatchNormalization':
                    layer.trainable=False
                    print('+',sep="")
コード例 #3
0
ファイル: c1_vgg.py プロジェクト: ruixiao85/LungNeuralNet
    def build_net(self, is_train):
        super(NetU_Vgg, self).build_net(is_train)
        locals()['in0'] = Input(shape=(self.row_in, self.col_in, self.dep_in))
        locals()['pre0'] = self.preproc(locals()['in0'], 'pre0', 0, self.fs[0],
                                        self.act)
        creater, convs = self.config[self.variation]
        base_model = creater(input_tensor=locals()['pre0'],
                             include_top=False,
                             weights='imagenet' if self.pre_trained else None)
        # print(base_model.summary())
        for layer in base_model.layers:
            layer.trainable = True  # allow training on pre-trained weights

        for i in range(5):
            locals()['dmerge%d' %
                     i] = locals()['dconv%d' % i] = base_model.get_layer(
                         "block%d_conv%d" % (i + 1, convs[i])).output
            locals()['dproc%d' %
                     (i + 1)] = locals()['djoin%d' % (i + 1)] = locals()[
                         'dsamp%d' % (i + 1)] = base_model.get_layer(
                             "block%d_pool" % (i + 1)).output

        for i in range(len(self.fs) - 2, -1, -1):
            prev_layer = locals()['dproc%d' % (i + 1)] if i == len(
                self.fs) - 2 else locals()['uproc%d' % (i + 1)]
            locals()['uconv%d' % (i + 1)] = self.upconv(
                prev_layer, 'uconv%d' % (i + 1), i, self.fs[i + 1], self.act)
            locals()['ujoin%d' % (i + 1)] = self.upjoin(
                locals()['uconv%d' % (i + 1)],
                locals()['djoin%d' % (i + 1)], 'ujoin%d' % (i + 1), i,
                self.fs[i + 1], self.act)
            locals()['usamp%d' % i] = self.upsamp(
                locals()['ujoin%d' % (i + 1)], self.ps[i], 'usamp%d' % i, i,
                self.fs[i + 1], self.act)
            locals()['umerge%d' % i] = self.upmerge(locals()['usamp%d' % i],
                                                    locals()['dmerge%d' % i],
                                                    'umerge%d' % i, i,
                                                    self.fs[i], self.act)
            locals()['uproc%d' % i] = self.upproc(locals()['umerge%d' % i],
                                                  'uproc%d' % i, i, self.fs[i],
                                                  self.act)

        locals()['post0'] = self.postproc(locals()['uproc0'], 'post0', 0,
                                          self.fs[0], self.act)
        locals()['out0'] = cvac(locals()['post0'],
                                'out0',
                                0,
                                self.dep_out,
                                self.out,
                                size=1)
        self.net = Model(locals()['in0'], locals()['out0'])
コード例 #4
0
ファイル: c1_dense.py プロジェクト: ruixiao85/LungNeuralNet
    def build_net(self, is_train):
        super(NetU_Dense, self).build_net(is_train)
        locals()['in0'] = Input(shape=(self.row_in, self.col_in, self.dep_in))
        locals()['pre0'] = self.preproc(locals()['in0'], 'pre0', 0, self.fs[0],
                                        self.act)
        creater, blocks = self.config[self.variation]
        base_model = creater(input_tensor=locals()['pre0'],
                             include_top=False,
                             weights='imagenet' if self.pre_trained else None)
        # print(base_model.summary())
        for layer in base_model.layers:
            layer.trainable = True  # allow training on pre-trained weights
        locals()['dmerge0'] = locals()['dconv0'] = None
        locals()['dproc1'] = locals()['djoin1'] = locals(
        )['dsamp1'] = base_model.get_layer("conv1/relu").output
        # locals()['dproc1']=locals()['djoin1']=locals()['dsamp1']=base_model.get_layer("conv1/conv").output

        locals()['dmerge1'] = locals()['dconv1'] = None
        locals()['dproc2'] = locals()['djoin2'] = locals(
        )['dsamp2'] = base_model.get_layer("pool1").output

        # for i in range(2,5):
        #     locals()['dmerge%d'%i]=locals()['dconv%d'%i]=base_model.get_layer("pool%d_conv"%i).output
        #     locals()['dproc%d'%(i+1)]=locals()['djoin%d'%(i+1)]=locals()['dsamp%d'%(i+1)]=base_model.get_layer("pool%d_pool"%i).output
        for i in range(2, 5):
            # locals()['dmerge%d'%i]=locals()['dconv%d'%i]=base_model.get_layer("conv%d_block%d_concat"%(i,blocks[i-2])).output
            locals()['dconv%d' % i] = base_model.get_layer(
                "conv%d_block%d_concat" % (i, blocks[i - 2])).output
            locals()['dmerge%d' % i] = locals()['dconv%d' %
                                                i] = base_model.get_layer(
                                                    "pool%d_conv" % i).output
            locals()['dproc%d' %
                     (i + 1)] = locals()['djoin%d' % (i + 1)] = locals()[
                         'dsamp%d' % (i + 1)] = base_model.get_layer(
                             "pool%d_pool" % i).output
        locals()['djoin5'] = locals()['uproc5'] = base_model.get_layer(
            "conv%d_block%d_concat" % (5, blocks[5 - 2])).output

        for i in range(len(self.fs) - 2, -1, -1):
            locals()['uconv%d' % (i + 1)] = self.upconv(
                locals()['uproc%d' % (i + 1)], 'uconv%d' % (i + 1), i,
                self.fs[i + 1], self.act)
            locals()['ujoin%d' % (i + 1)] = self.upjoin(
                locals()['uconv%d' % (i + 1)],
                locals()['djoin%d' % (i + 1)], 'ujoin%d' % (i + 1), i,
                self.fs[i + 1], self.act)
            locals()['usamp%d' % i] = self.upsamp(
                locals()['ujoin%d' % (i + 1)], self.ps[i], 'usamp%d' % i, i,
                self.fs[i + 1], self.act)
            locals()['umerge%d' % i] = self.upmerge(locals()['usamp%d' % i],
                                                    locals()['dmerge%d' % i],
                                                    'umerge%d' % i, i,
                                                    self.fs[i], self.act)
            locals()['uproc%d' % i] = self.upproc(locals()['umerge%d' % i],
                                                  'uproc%d' % i, i, self.fs[i],
                                                  self.act)

        locals()['post0'] = self.postproc(locals()['uproc0'], 'post0', 0,
                                          self.fs[0], self.act)
        locals()['out0'] = cvac(locals()['post0'],
                                'out0',
                                0,
                                self.dep_out,
                                self.out,
                                size=1)
        self.net = Model(locals()['in0'], locals()['out0'])
コード例 #5
0
def dn13r1(in_layer, name, idx, filters, act):
    x, rep=in_layer, 6**(idx+1)
    for i in range(rep-1, -1, -1):
        x=dn13(x, name+str(i)[:i+1], idx, filters, act)
    return cvac(x, name, filters, act, size=1)
コード例 #6
0
def c3t2mp(in_layer, name, idx, filters=3, act='relu'):
    x=cvac(in_layer,name+'_2',idx,filters,act)
    x=cvac(x,name+'_1',idx,filters,act)
    return mp(x,name,idx=idx,fs=None,act=None,size=2,stride=2)
コード例 #7
0
def dn13(in_layer, name, idx, filters, act):
    x=cvac(in_layer, name+'_2', idx, filters, act, size=1)
    x=cv(x, name+'_1', idx, filters, act, size=3)
    y=cv(in_layer, name+'_s', idx, filters, act, size=1)
    return adac(x,y,name,idx,filters,act)