def __init__(self,**kwargs): self.kwargs = kwargs self.name = kwargs['name'] self.filters = kwargs['filters'] self.kernel = kwargs['kernel_size'] self.activation = 'linear' if 'activation' in kwargs: self.activation = kwargs['activation'] kwargs['activation'] = 'linear' if isinstance(self.kernel, int): ks = self.kernel self.kernel = (ks, ks, ks) ks = self.kernel kwargs['kernel_size'] = (1, ks[1], ks[2]) kwargs['name'] = self.name + '_x_axis' kwargs['data_format'] = 'channels_first' self.convx = KL.Convolution3D(**kwargs) kwargs['kernel_size'] = (ks[0], 1, ks[2]) kwargs['name'] = self.name + '_y_axis' kwargs['data_format'] = 'channels_first' self.convy = KL.Convolution3D(**kwargs) kwargs['kernel_size'] = (ks[0], ks[1], 1) kwargs['name'] = self.name + '_z_axis' kwargs['data_format'] = 'channels_first' self.convz = KL.Convolution3D(**kwargs) self.addLayer = KL.Add(name=self.name + '_add')
def _build_model(self): inputs = layers.Input(shape=(3, self.sequence_size, self.img_size, self.img_size)) x = layers.Convolution3D(16, 3, 3, 3, activation=Relu, border_mode="same")(inputs) x = layers.Convolution3D(1, 3, 3, 3, activation=Relu, border_mode="same")(x) x = layers.Reshape([self.sequence_size,321,321])(x) x = layers.Convolution2D(64, 3, 3, activation=Relu, border_mode="same")(x) x = layers.MaxPooling2D((2, 2))(x) x = layers.Convolution2D(32, 3, 3, activation=Relu, border_mode="same")(x) x = layers.Convolution2D(32, 3, 3, activation=Relu)(x) x = layers.Convolution2D(4, 3, 3, activation=Relu, border_mode="same")(x) x = layers.Convolution2D(1, 3, 3, activation='sigmoid', border_mode="same")(x) model = Model(input=inputs, output=x) return model
def make_model(): model = models.Sequential() model.add( layers.Convolution3D(16, 1, 3, 3, input_shape=(1, 24, 128, 128), activation='relu')) model.add(layers.Convolution3D(32, 1, 3, 3, activation='relu')) model.add(layers.MaxPooling3D(pool_size=(1, 2, 2))) model.add(layers.Convolution3D(32, 1, 3, 3, activation='relu')) model.add(layers.Convolution3D(64, 1, 3, 3, activation='relu')) model.add(layers.MaxPooling3D(pool_size=(1, 2, 2))) model.add(layers.Convolution3D(64, 1, 3, 3, activation='relu')) model.add(layers.Convolution3D(128, 1, 3, 3, activation='relu')) model.add(layers.MaxPooling3D(pool_size=(1, 2, 2))) model.add(layers.Convolution3D(128, 1, 3, 3, activation='relu')) model.add(layers.MaxPooling3D(pool_size=(1, 2, 2))) model.add(layers.Flatten()) model.add(layers.Dense(512, activation='relu')) model.add(layers.Dropout(0.5)) model.add(layers.Dense(2, activation='softmax')) model.compile(loss='categorical_crossentropy', optimizer='adadelta', metrics=['accuracy']) model.fit(trn_x, trn_y, batch_size=24, nb_epoch=10, verbose=1, validation_data=(val_x, val_y))
def build_model(self): inputs = layers.Input(shape=(3, self.sequence_size, self.img_size, self.img_size)) x = layers.Convolution3D(16, 3, 3, 3, activation=Relu, border_mode="same")(inputs) x = layers.Convolution3D(1, 3, 3, 3, activation=Relu, border_mode="same")(x) print(x.get_shape()) x = layers.Reshape([self.sequence_size, 321, 321])(x) print(x.get_shape()) x = layers.Convolution2D(64, 3, 3, activation=Relu, border_mode="same")(x) x = layers.MaxPooling2D((2, 2))(x) print(x.get_shape()) x = layers.Convolution2D(32, 3, 3, activation=Relu, border_mode="same")(x) x = layers.Convolution2D(32, 3, 3, activation=Relu)(x) x = layers.Convolution2D(4, 3, 3, activation=Relu, border_mode="same")(x) x = layers.Convolution2D(1, 3, 3, activation='sigmoid', border_mode="same")(x) print(x.get_shape()) model = Model(input=inputs, output=x) model.compile(optimizer='rmsprop', loss=self.loss_DSSIS_tf11, metrics=['accuracy']) return model