Exemple #1
0
def train_and_calculate_metric(params):
    logging.info("params = " + str(params))

    s = Model.Settings()
    s.batch_size = FLAGS.batch_size
    s.loss = params["loss"]
    s.num_classes = len(params["class_weights"])
    s.class_weights = params["class_weights"]
    s.image_depth = FLAGS.image_depth
    s.image_height = FLAGS.image_width
    s.image_width = FLAGS.image_height
    s.keep_prob = params["keep_prob"]
    s.l2_reg = params["l2_reg"]
    s.learning_rate = params["learning_rate"]
    s.num_conv_blocks = 5
    s.num_conv_channels = 40
    s.num_dense_layers = 1
    s.use_batch_norm = False

    try:
        trainer = Trainer(s)
        trainer.train(FLAGS.num_steps)
    except tf.errors.ResourceExhaustedError as e:
        logging.info("Resource exhausted: %s", e.message)
        trainer.clear()
        return {'status': hyperopt.STATUS_FAIL}
    finally:
        trainer.clear()

    logging.info(
        "iou = " + str(trainer.val_iou_history[-1]) + ", params = " + str(params))

    return {'loss': -trainer.val_iou_history[-1], 'status': hyperopt.STATUS_OK}
Exemple #2
0
def make_best_settings():
    s = Model.Settings()

    s.loss = "softmax"
    s.batch_size = FLAGS.batch_size
    s.image_depth = FLAGS.image_depth
    s.image_height = FLAGS.image_width
    s.image_width = FLAGS.image_height
    s.keep_prob = 0.5
    s.learning_rate = 0.05
    s.num_conv_blocks = 4
    s.num_conv_channels = 64
    s.l2_reg = 0.0
    s.use_batch_norm = False
    s.num_dense_layers = 0

    if FLAGS.settings == "Abdomen":
        s.num_classes = 13
        s.class_weights = [1.0] + [5.0]*12
    elif FLAGS.settings == "Cardiac":
        s.num_classes = 2
        s.class_weights = [1.0, 5.0]
    elif FLAGS.settings == "LiTS":
        s.num_classes = 3
        s.class_weights = [1.0, 5.0, 5.0]
        s.l2_reg = 1.0e-6
    elif FLAGS.settings == "LCTSC":
        s.learning_rate = 0.0005
        s.num_conv_channels = 128
        s.num_classes = 6
        s.class_weights = [1.0] + [5.0]*5
        s.keep_prob = 0.5
        s.l2_reg = 1.0e-4
    elif FLAGS.settings == "Tissue":
        s.learning_rate = 0.0005
        s.num_conv_channels = 128
        s.num_classes = 6
        s.class_weights = [1.0, 5.0, 1.0, 5.0, 5.0, 1.0]
        s.keep_prob = 0.5
    else:
        raise ValueError("Unknown dataset")

    return s