def build_model(self): """Build the model to be saved as self._model.""" assert self.labeled # build inputs self._inputs = self.build_inputs() moving_image = self._inputs["moving_image"] fixed_image = self._inputs["fixed_image"] moving_label = self._inputs["moving_label"] # build ddf backbone_inputs = self.concat_images(moving_image, fixed_image, moving_label) backbone = REGISTRY.build_backbone( config=self.config["backbone"], default_args=dict( image_size=self.fixed_image_size, out_channels=1, out_kernel_initializer="glorot_uniform", out_activation="sigmoid", ), ) # (batch, f_dim1, f_dim2, f_dim3) pred_fixed_label = backbone(inputs=backbone_inputs) pred_fixed_label = tf.squeeze(pred_fixed_label, axis=4) self._outputs = dict(pred_fixed_label=pred_fixed_label) return tf.keras.Model(inputs=self._inputs, outputs=self._outputs)
def build_model(self): """Build the model to be saved as self._model.""" # build inputs self._inputs = self.build_inputs() moving_image = self._inputs[ "moving_image"] # (batch, m_dim1, m_dim2, m_dim3) fixed_image = self._inputs[ "fixed_image"] # (batch, f_dim1, f_dim2, f_dim3) # build ddf control_points = self.config["backbone"].pop("control_points", False) backbone_inputs = self.concat_images(moving_image, fixed_image) backbone = REGISTRY.build_backbone( config=self.config["backbone"], default_args=dict( image_size=self.fixed_image_size, out_channels=3, out_kernel_initializer="zeros", out_activation=None, ), ) if isinstance(backbone, GlobalNet): # (f_dim1, f_dim2, f_dim3, 3), (4, 3) ddf, theta = backbone(inputs=backbone_inputs) self._outputs = dict(ddf=ddf, theta=theta) else: # (f_dim1, f_dim2, f_dim3, 3) ddf = backbone(inputs=backbone_inputs) ddf = (self._resize_interpolate(ddf, control_points) if control_points else ddf) self._outputs = dict(ddf=ddf) # build outputs warping = layer.Warping(fixed_image_size=self.fixed_image_size) # (f_dim1, f_dim2, f_dim3) pred_fixed_image = warping(inputs=[ddf, moving_image]) self._outputs["pred_fixed_image"] = pred_fixed_image if not self.labeled: return tf.keras.Model(inputs=self._inputs, outputs=self._outputs) # (f_dim1, f_dim2, f_dim3) moving_label = self._inputs["moving_label"] pred_fixed_label = warping(inputs=[ddf, moving_label]) self._outputs["pred_fixed_label"] = pred_fixed_label return tf.keras.Model(inputs=self._inputs, outputs=self._outputs)
def build_model(self): """Build the model to be saved as self._model.""" # build inputs self._inputs = self.build_inputs() moving_image = self._inputs["moving_image"] fixed_image = self._inputs["fixed_image"] control_points = self.config["backbone"].pop("control_points", False) # build ddf backbone_inputs = self.concat_images(moving_image, fixed_image) backbone = REGISTRY.build_backbone( config=self.config["backbone"], default_args=dict( image_size=self.fixed_image_size, out_channels=3, out_kernel_initializer="zeros", out_activation=None, ), ) dvf = backbone(inputs=backbone_inputs) dvf = self._resize_interpolate( dvf, control_points) if control_points else dvf ddf = layer.IntDVF(fixed_image_size=self.fixed_image_size)(dvf) # build outputs self._warping = layer.Warping(fixed_image_size=self.fixed_image_size) # (f_dim1, f_dim2, f_dim3, 3) pred_fixed_image = self._warping(inputs=[ddf, moving_image]) self._outputs = dict(dvf=dvf, ddf=ddf, pred_fixed_image=pred_fixed_image) if not self.labeled: return tf.keras.Model(inputs=self._inputs, outputs=self._outputs) # (f_dim1, f_dim2, f_dim3, 3) moving_label = self._inputs["moving_label"] pred_fixed_label = self._warping(inputs=[ddf, moving_label]) self._outputs["pred_fixed_label"] = pred_fixed_label return tf.keras.Model(inputs=self._inputs, outputs=self._outputs)