def apply_model(self): if self.data_is_3D: self.enc_model, _ = apply_encoder_model_3d(self.img_shape_3d, **self.kwargs) x_input = Input((self.terms, self.image_size, self.image_size, self.image_size, self.number_channels)) y_input = keras.layers.Input( (self.predict_terms, self.image_size, self.image_size, self.image_size, self.number_channels)) else: self.enc_model, _ = apply_encoder_model(self.img_shape, **self.kwargs) x_input = Input((self.terms, self.image_size, self.image_size, self.number_channels)) y_input = keras.layers.Input( (self.predict_terms, self.image_size, self.image_size, self.number_channels)) model_with_embed_dim = Sequential( [self.enc_model, Flatten(), Dense(self.code_size)]) x_encoded = TimeDistributed(model_with_embed_dim)(x_input) context = network_autoregressive(x_encoded) preds = network_prediction(context, self.code_size, self.predict_terms) y_encoded = keras.layers.TimeDistributed(model_with_embed_dim)(y_input) dot_product_probs = CPCLayer()([preds, y_encoded]) cpc_model = keras.models.Model(inputs=[x_input, y_input], outputs=dot_product_probs) return cpc_model
def apply_model(self): if self.data_is_3D: self.enc_model, self.layer_data = apply_encoder_model_3d( (*self.dim, self.number_channels), **self.kwargs) else: self.enc_model, self.layer_data = apply_encoder_model( (*self.dim, self.number_channels), **self.kwargs) input_layer = Input((3, *self.dim, self.number_channels), name="Input") anchor_input = Lambda(lambda x: x[:, 0, :], name="anchor_input")(input_layer) positive_input = Lambda(lambda x: x[:, 1, :], name="positive_input")(input_layer) negative_input = Lambda(lambda x: x[:, 2, :], name="negative_input")(input_layer) encoded_a = Dense(self.code_size, activation="sigmoid")(Flatten()( self.enc_model(anchor_input))) encoded_p = Dense(self.code_size, activation="sigmoid")(Flatten()( self.enc_model(positive_input))) encoded_n = Dense(self.code_size, activation="sigmoid")(Flatten()( self.enc_model(negative_input))) encoded_a = Reshape((1, self.code_size))(encoded_a) encoded_p = Reshape((1, self.code_size))(encoded_p) encoded_n = Reshape((1, self.code_size))(encoded_n) output = Concatenate(axis=-2)([encoded_a, encoded_p, encoded_n]) model = Model(inputs=input_layer, outputs=output) return model
def apply_model(self): if self.data_is_3D: self.enc_model, _ = apply_encoder_model_3d(self.img_shape_3d, **self.kwargs) else: self.enc_model, _ = apply_encoder_model(self.img_shape, **self.kwargs) return self.apply_prediction_model_to_encoder(self.enc_model)
def apply_model(self): if self.data_is_3D: self.enc_model, self.layer_data = apply_encoder_model_3d( self.img_shape_3d, **self.kwargs) x = Dense(10, activation="softmax") else: self.enc_model, self.layer_data = apply_encoder_model( self.img_shape, **self.kwargs) x = Dense(4, activation="softmax") return apply_prediction_model_to_encoder( self.enc_model, prediction_architecture=self.top_architecture, include_top=False, model_on_top=x)
def apply_model(self): if self.data_is_3D: self.enc_model, _ = apply_encoder_model_3d(( self.patch_dim, self.patch_dim, self.patch_dim, self.number_channels, ), **self.kwargs) else: self.enc_model, _ = apply_encoder_model(( self.patch_dim, self.patch_dim, self.number_channels, ), **self.kwargs) return self.apply_prediction_model_to_encoder(self.enc_model)
def apply_model(self): if self.data_is_3D: self.enc_model, _ = apply_encoder_model_3d(self.patch_shape, **self.kwargs) else: self.enc_model, _ = apply_encoder_model(self.patch_shape, **self.kwargs) x_input = Input(self.images_shape) enc_out = TimeDistributed(self.enc_model)(x_input) x = Dense(self.class_count, activation="softmax") return apply_prediction_model_to_encoder( Model(x_input, enc_out), prediction_architecture=self.top_architecture, include_top=False, model_on_top=x)
def apply_model(self): if self.data_is_3D: perms, _ = load_permutations_3d() input_x = Input(( self.n_patches3D, self.patch_dim, self.patch_dim, self.patch_dim, self.number_channels, )) self.enc_model, _ = apply_encoder_model_3d(( self.patch_dim, self.patch_dim, self.patch_dim, self.number_channels, ), **self.kwargs) else: perms, _ = load_permutations() input_x = Input((self.n_patches, self.patch_dim, self.patch_dim, self.number_channels)) self.enc_model, _ = apply_encoder_model(( self.patch_dim, self.patch_dim, self.number_channels, ), **self.kwargs) x = TimeDistributed(self.enc_model)(input_x) x = Flatten()(x) a = apply_prediction_model( x.shape[1:], prediction_architecture=self.top_architecture, include_top=False, ) last_layer = Dense(len(perms), activation="softmax") out = a(x) out = last_layer(out) model = Model(inputs=input_x, outputs=out, name="jigsaw_complete") return model
def apply_model(self): self.enc_model, _ = apply_encoder_model_3d(self.patch_shape_3d, **self.kwargs) return self.apply_prediction_model_to_encoder(self.enc_model)