Exemplo n.º 1
0
def train_and_predict_with_config(test_name, config_path):
    """
    Function that helps unit test whether a session with a given config
    runs the train and predict functions
    """
    tf.get_logger().setLevel(3)
    tf.keras.backend.clear_session(
    )  # needed for pytest, otherwise model output name will change
    gpu = ""
    gpu_allow_growth = False
    ckpt_path = ""
    log_dir = "pytest_train_" + test_name
    train(
        gpu=gpu,
        config_path=config_path,
        gpu_allow_growth=gpu_allow_growth,
        ckpt_path=ckpt_path,
        log_dir=log_dir,
    )
    ckpt_path = os.path.join("logs", log_dir, "save", "weights-epoch2.ckpt")
    log_dir = "pytest_predict_" + test_name
    predict(
        gpu=gpu,
        gpu_allow_growth=gpu_allow_growth,
        ckpt_path=ckpt_path,
        mode="test",
        batch_size=1,
        log_dir=log_dir,
        sample_label="all",
        config_path="",
    )
Exemplo n.º 2
0
def test_train():
    """
    Test train by checking it can run.
    """
    gpu = ""
    config_path = "deepreg/config/unpaired_labeled_ddf.yaml"
    gpu_allow_growth = False
    ckpt_path = ""
    log_dir = "test_train"
    train(
        gpu=gpu,
        config_path=config_path,
        gpu_allow_growth=gpu_allow_growth,
        ckpt_path=ckpt_path,
        log_dir=log_dir,
    )
Exemplo n.º 3
0
    dest="test",
    action="store_false",
)
parser.set_defaults(test=True)
args = parser.parse_args()

print("\n\n\n\n\n"
      "=======================================================\n"
      "The training can also be launched using the following command.\n"
      "deepreg_train --gpu '0' "
      f"--config_path demos/{name}/{name}.yaml "
      f"--log_dir demos/{name} "
      "--exp_name logs_train\n"
      "=======================================================\n"
      "\n\n\n\n\n")

log_dir = f"demos/{name}"
exp_name = "logs_train/" + datetime.now().strftime("%Y%m%d-%H%M%S")
config_path = [f"demos/{name}/{name}.yaml"]
if args.test:
    config_path.append("config/test/demo_unpaired_grouped.yaml")

train(
    gpu="0",
    config_path=config_path,
    gpu_allow_growth=True,
    ckpt_path="",
    log_dir=log_dir,
    exp_name=exp_name,
)
Exemplo n.º 4
0
    dest="test",
    action="store_false",
)
parser.set_defaults(test=True)
args = parser.parse_args()

print("\n\n\n\n\n"
      "=======================================================\n"
      "The training can also be launched using the following command.\n"
      "deepreg_train --gpu '0' "
      f"--config_path demos/{name}/{name}.yaml "
      f"--log_root demos/{name} "
      "--log_dir logs_train\n"
      "=======================================================\n"
      "\n\n\n\n\n")

log_root = f"demos/{name}"
log_dir = "logs_train/" + datetime.now().strftime("%Y%m%d-%H%M%S")
config_path = [f"demos/{name}/{name}.yaml"]
if args.test:
    config_path.append("config/test/demo_unpaired_grouped.yaml")

train(
    gpu="0",
    config_path=config_path,
    gpu_allow_growth=True,
    ckpt_path="",
    log_root=log_root,
    log_dir=log_dir,
)
Exemplo n.º 5
0
from deepreg.train import train

######## NOW WE DO THE TRAINING ########

gpu = "0"
gpu_allow_growth = False
ckpt_path = ""
log_dir = "learn2reg_t2_unpaired_train_logs"
config_path = [
    r"demos/unpaired_ct_lung/unpaired_ct_lung_train.yaml",
    r"demos/unpaired_ct_lung/unpaired_ct_lung.yaml",
]
train(
    gpu=gpu,
    config_path=config_path,
    gpu_allow_growth=gpu_allow_growth,
    ckpt_path=ckpt_path,
    log_dir=log_dir,
)
Exemplo n.º 6
0
        )
        self.conv2 = tf.keras.layers.Conv3D(
            filters=out_channels,
            kernel_size=1,
            kernel_initializer=out_kernel_initializer,
            activation=out_activation,
            padding="same",
        )

    def call(self, inputs: tf.Tensor, training=None, mask=None) -> tf.Tensor:
        """
        Builds graph based on built layers.

        :param inputs: shape = (batch, f_dim1, f_dim2, f_dim3, in_channels)
        :param training:
        :param mask:
        :return: shape = (batch, f_dim1, f_dim2, f_dim3, out_channels)
        """
        out = self.conv1(inputs)
        out = self.conv2(out)
        return out


config_path = "examples/config_custom_backbone.yaml"
train(
    gpu="",
    config_path=config_path,
    gpu_allow_growth=True,
    ckpt_path="",
)