コード例 #1
0
ファイル: nn.py プロジェクト: yjsyyyjszf/SimVascular
    def build_model(self):
        CROP_DIMS = self.config['CROP_DIMS']
        C = self.config['NUM_CHANNELS']
        LEAK = self.config['LEAK']
        LAMBDA = self.config['L2_REG']
        INIT = self.config['INIT']

        NLAYERS = int(self.config['NLAYERS'] / 2)
        NFILTERS_SMALL = self.config['NFILTERS_SMALL']
        NFILTERS_LARGE = self.config['NFILTERS_LARGE']

        NUM_POINTS = self.config['NUM_CONTOUR_POINTS']

        leaky_relu = tf.contrib.keras.layers.LeakyReLU(LEAK)

        self.x = tf.placeholder(shape=[None, CROP_DIMS, CROP_DIMS, C],
                                dtype=tf.float32)
        self.y = tf.placeholder(shape=[None, NUM_POINTS], dtype=tf.float32)

        self.yclass, self.yhat, _, _ = tf_util.resNet(
            self.x,
            nlayers_before=NLAYERS,
            nlayers_after=NLAYERS,
            nfilters=NFILTERS_SMALL,
            nfilters_large=NFILTERS_LARGE,
            output_filters=NFILTERS_LARGE,
            activation=leaky_relu,
            init=INIT)

        o = leaky_relu(self.yhat)

        d = self.config['POOL']

        o = tf.nn.pool(o, [d, d], "MAX", "VALID", strides=[d, d])

        s = o.get_shape().as_list()

        o_vec = tf.reshape(o, shape=[-1, s[1] * s[2] * s[3]])

        for i in range(self.config['FC_LAYERS']):
            if "HIDDEN_SIZES" in self.config:
                h = self.config['HIDDEN_SIZES'][i]
            else:
                h = self.config['HIDDEN_SIZE']

            o_vec = tf_util.fullyConnected(o_vec,
                                           h,
                                           leaky_relu,
                                           std=INIT,
                                           scope='fc_' + str(i))

        self.yhat = tf_util.fullyConnected(o_vec,
                                           NUM_POINTS,
                                           tf.sigmoid,
                                           std=INIT,
                                           scope='fc_final')

        self.build_loss()

        self.saver = tf.train.Saver()
コード例 #2
0
    def build_model(self):
        CROP_DIMS   = self.config['CROP_DIMS']
        C           = self.config['NUM_CHANNELS']
        LEAK        = self.config['LEAK']
        LAMBDA      = self.config['L2_REG']
        INIT        = self.config['INIT']

        NLAYERS     = self.config['NLAYERS']
        NFILTERS    = self.config['NFILTERS']

        NUM_POINTS  = self.config['NUM_CONTOUR_POINTS']
        DIMS = [self.config['CONV_DIMS']]*2

        leaky_relu = tf.contrib.keras.layers.LeakyReLU(LEAK)

        self.x = tf.placeholder(shape=[None,CROP_DIMS,CROP_DIMS,C],dtype=tf.float32)
        self.y = tf.placeholder(shape=[None,NUM_POINTS],dtype=tf.float32)

        o = self.x

        if "INPUT_POOL" in self.config:
            d = self.config['INPUT_POOL']

            o = tf.nn.pool(o, [d,d], "MAX", "VALID", strides=[d,d])


        for i in range(NLAYERS):
            o = tf_util.conv2D(o,dims=DIMS,nfilters=NFILTERS,
                               init=INIT,
                          activation=leaky_relu,scope="conv_{}".format(i))

        s   = o.get_shape().as_list()
        o = tf.reshape(o,shape=[-1,s[1]*s[2]*s[3]])

        for i in range(self.config['FC_LAYERS']):
            if "HIDDEN_SIZES" in self.config:
                h = self.config['HIDDEN_SIZES'][i]
            else:
                h = self.config['HIDDEN_SIZE']

            o = tf_util.fullyConnected(o, h,
                leaky_relu, std=INIT, scope='fc_'+str(i))
            print(o)

            if "DROPOUT" in self.config:
                o = tf.nn.dropout(o, self.config['DROPOUT'])


        self.yhat = tf_util.fullyConnected(o, NUM_POINTS,
            tf.sigmoid, std=INIT, scope='fc_final')

        self.build_loss()

        self.saver = tf.train.Saver()
コード例 #3
0
ファイル: nn.py プロジェクト: yjsyyyjszf/SimVascular
    def build_model(self):
        CROP_DIMS = self.config['CROP_DIMS']
        C = self.config['NUM_CHANNELS']
        LEAK = self.config['LEAK']
        NUM_FILTERS = self.config['NUM_FILTERS']
        LAMBDA = self.config['L2_REG']
        INIT = self.config['INIT']
        NUM_POINTS = self.config['NUM_CONTOUR_POINTS']

        leaky_relu = tf.contrib.keras.layers.LeakyReLU(LEAK)

        self.x = tf.placeholder(shape=[None, CROP_DIMS, CROP_DIMS, C],
                                dtype=tf.float32)
        self.y = tf.placeholder(shape=[None, NUM_POINTS], dtype=tf.float32)

        self.yclass, self.yhat, _, _ = tf_util.I2INet(self.x,
                                                      nfilters=NUM_FILTERS,
                                                      activation=leaky_relu,
                                                      init=INIT)

        o = leaky_relu(self.yhat)

        s = o.get_shape().as_list()

        o_vec = tf.reshape(o, shape=[-1, s[1] * s[2] * s[3]])

        for i in range(self.config['FC_LAYERS'] - 1):
            if "HIDDEN_SIZES" in self.config:
                h = self.config['HIDDEN_SIZES'][i]
            else:
                h = self.config['HIDDEN_SIZE']

            o_vec = tf_util.fullyConnected(o_vec,
                                           h,
                                           leaky_relu,
                                           std=INIT,
                                           scope='fc_' + str(i))

        self.yhat = tf_util.fullyConnected(o_vec,
                                           NUM_POINTS,
                                           tf.identity,
                                           std=INIT,
                                           scope='fc_final')

        self.build_loss()

        self.saver = tf.train.Saver()
コード例 #4
0
ファイル: nn.py プロジェクト: yjsyyyjszf/SimVascular
    def build_model(self):
        CROP_DIMS = self.config['CROP_DIMS']
        LEAK = self.config['LEAK']
        C = self.config['NUM_CHANNELS']
        LAMBDA = self.config['L2_REG']
        INIT = self.config['INIT']
        NUM_POINTS = self.config['NUM_CONTOUR_POINTS']

        leaky_relu = tf.contrib.keras.layers.LeakyReLU(LEAK)

        self.x = tf.placeholder(shape=[None, CROP_DIMS, CROP_DIMS, C],
                                dtype=tf.float32)
        self.y = tf.placeholder(shape=[None, NUM_POINTS], dtype=tf.float32)

        o = self.x
        if "INPUT_POOL" in self.config:
            d = self.config['INPUT_POOL']

            o = tf.nn.pool(o, [d, d], "MAX", "VALID", strides=[d, d])

        s = o.get_shape().as_list()

        o_vec = tf.reshape(o, shape=[-1, s[1] * s[2] * s[3]])

        for i, h in enumerate(self.config['HIDDEN_SIZES']):

            o_vec = tf_util.fullyConnected(o_vec,
                                           h,
                                           leaky_relu,
                                           std=INIT,
                                           scope='fc_' + str(i))

            if "DROPOUT" in self.config:
                o_vec = tf.nn.dropout(o_vec, self.config['DROPOUT'])

        self.yhat = tf_util.fullyConnected(o_vec,
                                           NUM_POINTS,
                                           tf.sigmoid,
                                           std=INIT,
                                           scope='fc_final')

        self.build_loss()

        self.saver = tf.train.Saver()
コード例 #5
0
    def build_model(self):
        CROP_DIMS   = self.config['CROP_DIMS']
        C           = self.config['NUM_CHANNELS']
        LEAK        = self.config['LEAK']
        LAMBDA      = self.config['L2_REG']
        INIT        = self.config['INIT']

        NLAYERS     = int(self.config['NLAYERS']/2)
        NFILTERS    = self.config['NFILTERS']

        NUM_POINTS  = self.config['NUM_CONTOUR_POINTS']
        DIMS = [self.config['CONV_DIMS']]*2

        leaky_relu = tf.contrib.keras.layers.LeakyReLU(LEAK)

        self.x = tf.placeholder(shape=[None,CROP_DIMS,CROP_DIMS,C],dtype=tf.float32)
        self.y = tf.placeholder(shape=[None,NUM_POINTS],dtype=tf.float32)

        self.x_1 = tf.nn.pool(self.x, [2,2], "MAX", "VALID", strides=[2,2])
        self.x_2 = tf.nn.pool(self.x_1, [2,2], "MAX", "VALID", strides=[2,2])

        o = self.x

        for i in range(NLAYERS):
            o = tf_util.conv2D(o,dims=DIMS, nfilters=NFILTERS,init=INIT,activation=leaky_relu,
                scope="conv_{}".format(i))

        o_1 = self.x_1

        for i in range(NLAYERS):
            o_1 = tf_util.conv2D(o_1,dims=DIMS, nfilters=NFILTERS,init=INIT,activation=leaky_relu, scope="conv_1_{}".format(i))

        o_2 = self.x_2

        for i in range(NLAYERS):
            o_2 = tf_util.conv2D(o_2,dims=DIMS, nfilters=NFILTERS,init=INIT,activation=leaky_relu, scope="conv_2_{}".format(i))


        s = o.get_shape().as_list()
        s_1 = o_1.get_shape().as_list()
        s_2 = o_2.get_shape().as_list()

        o_vec   = tf.reshape(o,shape=[-1,s[1]*s[2]*s[3]])
        o_vec_1 = tf.reshape(o_1,shape=[-1,s_1[1]*s_1[2]*s_1[3]])
        o_vec_2 = tf.reshape(o_2,shape=[-1,s_2[1]*s_2[2]*s_2[3]])

        o = tf.concat([o_vec, o_vec_1, o_vec_2], axis=1)

        for i in range(self.config['FC_LAYERS']-1):
            if "HIDDEN_SIZES" in self.config:
                h = self.config['HIDDEN_SIZES'][i]
            else:
                h = self.config['HIDDEN_SIZE']

            o = tf_util.fullyConnected(o, h,
                leaky_relu, std=INIT, scope='fc_'+str(i))

        self.yhat = tf_util.fullyConnected(o, NUM_POINTS,
            tf.identity, std=INIT, scope='fc_final')

        self.build_loss()

        self.saver = tf.train.Saver()
コード例 #6
0
    def build_model(self):
        CROP_DIMS   = self.config['CROP_DIMS']
        C           = self.config['NUM_CHANNELS']
        LEAK        = self.config['LEAK']
        LAMBDA      = self.config['L2_REG']
        INIT        = self.config['INIT']

        NLAYERS     = int(self.config['NLAYERS']/2)
        NFILTERS_SMALL = self.config['NFILTERS_SMALL']
        NFILTERS_LARGE = self.config['NFILTERS_LARGE']

        NUM_POINTS  = self.config['NUM_CONTOUR_POINTS']

        leaky_relu = tf.contrib.keras.layers.LeakyReLU(LEAK)

        self.x = tf.placeholder(shape=[None,CROP_DIMS,CROP_DIMS,C],dtype=tf.float32)

        if self.config['MULTI_TYPE'] == "POOL":
            self.x_1 = tf.nn.pool(self.x, [2,2], "MAX", "VALID", strides=[2,2])
            self.x_2 = tf.nn.pool(self.x_1, [2,2], "MAX", "VALID", strides=[2,2])
        elif self.config['MULTI_TYPE'] == "CROP":
            self.x_1 = tf.image.central_crop(self.x, central_fraction=0.5)
            self.x_2 = tf.image.central_crop(self.x_1, central_fraction=0.5)
        else:
            raise RuntimeError("Unrecognized multi type")

        self.y = tf.placeholder(shape=[None,NUM_POINTS],dtype=tf.float32)

        self.yclass,self.yhat,_,_ = tf_util.resNet(self.x,
            nlayers_before=NLAYERS, nlayers_after=NLAYERS,
            nfilters=NFILTERS_SMALL, nfilters_large=NFILTERS_LARGE,
            output_filters=NFILTERS_LARGE, activation=leaky_relu, init=INIT)

        self.yclass_1,self.yhat_1,_,_ = tf_util.resNet(self.x_1,
            nlayers_before=NLAYERS, nlayers_after=NLAYERS,
            nfilters=NFILTERS_SMALL, nfilters_large=NFILTERS_LARGE,
            output_filters=NFILTERS_LARGE, activation=leaky_relu, init=INIT,
            scope="resnet_1")

        self.yclass_2,self.yhat_2,_,_ = tf_util.resNet(self.x_2,
            nlayers_before=NLAYERS, nlayers_after=NLAYERS,
            nfilters=NFILTERS_SMALL, nfilters_large=NFILTERS_LARGE,
            output_filters=NFILTERS_LARGE, activation=leaky_relu, init=INIT,
            scope="resnet_2")


        o   = leaky_relu(self.yhat)
        o_1 = leaky_relu(self.yhat_1)
        o_2 = leaky_relu(self.yhat_2)

        s   = o.get_shape().as_list()
        s_1 = o_1.get_shape().as_list()
        s_2 = o_2.get_shape().as_list()

        o_vec   = tf.reshape(o,shape=[-1,s[1]*s[2]*s[3]])
        o_vec_1 = tf.reshape(o_1,shape=[-1,s_1[1]*s_1[2]*s_1[3]])
        o_vec_2 = tf.reshape(o_2,shape=[-1,s_2[1]*s_2[2]*s_2[3]])

        o = tf.concat([o_vec, o_vec_1, o_vec_2], axis=1)

        print(o)

        for i in range(self.config['FC_LAYERS']-1):
            if "HIDDEN_SIZES" in self.config:
                h = self.config['HIDDEN_SIZES'][i]
            else:
                h = self.config['HIDDEN_SIZE']

            o = tf_util.fullyConnected(o, h,
                leaky_relu, std=INIT, scope='fc_'+str(i))

        self.yhat = tf_util.fullyConnected(o, NUM_POINTS,
            tf.identity, std=INIT, scope='fc_final')

        self.build_loss()

        self.saver = tf.train.Saver()