示例#1
0
def test_joints_to_gaussian_heatmap():

    image_size = (256, 320)

    stride = 2
    num_joints = 17

    input_joints = np.array([[1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1],
                             [5, 5, 1], [6, 6, 1], [7, 7, 1], [8, 8, 1],
                             [9, 9, 1], [10, 10, 1], [11, 11, 1], [12, 12, 1],
                             [13, 13, 1], [14, 14, 1], [15, 15, 1],
                             [16, 16, 1], [17, 17, 0]])

    pre_process = JointsToGaussianHeatmap(image_size,
                                          num_joints=num_joints,
                                          stride=stride,
                                          sigma=2)

    heatmap = pre_process(joints=input_joints)["heatmap"]

    # It is hard to test semantic correctness of a gaussian heatmap manually.
    # That part will be tested jointly with GaussianHeatmapToJoints() in test_post_processor.py.
    assert isinstance(heatmap, np.ndarray)
    assert heatmap.shape[0] == image_size[0] // stride
    assert heatmap.shape[1] == image_size[1] // stride
    assert heatmap.shape[2] == 17
    assert np.max(heatmap) == 10
示例#2
0
def test_ytfaces_facial_landmarks_detection():

    batch_size = 1
    image_size = [256, 320]
    stride = 2

    pre_processor = Sequence([
        ResizeWithJoints(image_size=image_size),
        JointsToGaussianHeatmap(image_size=image_size,
                                num_joints=68,
                                stride=stride)
    ])

    dataset = YoutubeFacialLandmarks(subset="train",
                                     batch_size=batch_size,
                                     pre_processor=pre_processor)
    dataset = DatasetIterator(dataset)

    for _ in range(5):
        images, labels = dataset.feed()

        assert isinstance(images, np.ndarray)
        assert images.shape[0] == batch_size
        assert images.shape[1] == image_size[0]
        assert images.shape[2] == image_size[1]
        assert images.shape[3] == 3

        assert isinstance(labels, np.ndarray)
        assert labels.shape[0] == batch_size
        assert labels.shape[1] == image_size[0] // stride
        assert labels.shape[2] == image_size[1] // stride
        assert labels.shape[3] == 68

    dataset = YoutubeFacialLandmarks(subset="validation",
                                     batch_size=batch_size,
                                     pre_processor=pre_processor)
    dataset = DatasetIterator(dataset)

    for _ in range(5):
        images, labels = dataset.feed()

        assert isinstance(images, np.ndarray)
        assert images.shape[0] == batch_size
        assert images.shape[1] == image_size[0]
        assert images.shape[2] == image_size[1]
        assert images.shape[3] == 3

        assert isinstance(labels, np.ndarray)
        assert labels.shape[0] == batch_size
        assert labels.shape[1] == image_size[0] // stride
        assert labels.shape[2] == image_size[1] // stride
        assert labels.shape[3] == 68
示例#3
0
def test_training():
    """Test only no error raised."""

    config = EasyDict()

    config.NETWORK_CLASS = LmSinglePoseV1Quantize
    config.DATASET_CLASS = MscocoSinglePersonKeypoints

    config.IS_DEBUG = False
    config.IMAGE_SIZE = [160, 160]
    config.BATCH_SIZE = 2
    config.TEST_STEPS = 1
    config.MAX_STEPS = 2
    config.SAVE_CHECKPOINT_STEPS = 1
    config.KEEP_CHECKPOINT_MAX = 5
    config.SUMMARISE_STEPS = 1
    config.IS_PRETRAIN = False
    config.IS_DISTRIBUTION = False
    config.TASK = Tasks.KEYPOINT_DETECTION

    # network model config
    config.NETWORK = EasyDict()
    config.NETWORK.OPTIMIZER_CLASS = tf.train.AdamOptimizer
    config.NETWORK.OPTIMIZER_KWARGS = {"learning_rate": 0.001}
    config.NETWORK.IMAGE_SIZE = config.IMAGE_SIZE
    config.NETWORK.BATCH_SIZE = config.BATCH_SIZE
    config.NETWORK.ACTIVATION_QUANTIZER = linear_mid_tread_half_quantizer
    config.NETWORK.ACTIVATION_QUANTIZER_KWARGS = {
        'bit': 2,
        'max_value': 2.0
    }
    config.NETWORK.WEIGHT_QUANTIZER = binary_channel_wise_mean_scaling_quantizer
    config.NETWORK.WEIGHT_QUANTIZER_KWARGS = {}

    # daasegt config
    config.DATASET = EasyDict()
    config.DATASET.PRE_PROCESSOR = Sequence([
        ResizeWithJoints(image_size=config.IMAGE_SIZE),
        JointsToGaussianHeatmap(image_size=config.IMAGE_SIZE, stride=2),
        DivideBy255()])
    config.DATASET.BATCH_SIZE = config.BATCH_SIZE

    environment.init("test_lm_single_pose_v1")
    prepare_dirs(recreate=True)
    start_training(config, profile_step=1)
示例#4
0
def test_gaussian_heatmap_to_joints():

    from blueoil.pre_processor import JointsToGaussianHeatmap

    image_size = (160, 160)

    num_dimensions = 2
    stride = 1
    confidence_threshold = 0.5
    num_joints = 17

    input_joints = np.array([[1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1],
                             [5, 5, 1], [6, 6, 1], [7, 7, 1], [8, 8, 1],
                             [9, 9, 1], [10, 10, 1], [11, 11, 1], [12, 12, 1],
                             [13, 13, 1], [14, 14, 1], [15, 15, 1],
                             [16, 16, 1], [17, 17, 0]])

    pre_process = JointsToGaussianHeatmap(image_size,
                                          num_joints=num_joints,
                                          stride=1,
                                          sigma=3)

    post_process = GaussianHeatmapToJoints(
        num_dimensions=num_dimensions,
        stride=stride,
        confidence_threshold=confidence_threshold)

    heatmap = pre_process(joints=input_joints)["heatmap"]
    heatmap = np.expand_dims(heatmap, axis=0)

    output_joints = post_process(heatmap)["outputs"][0]

    for i in range(num_joints):
        if input_joints[i, 2] == 1:
            assert np.allclose(output_joints[i],
                               input_joints[i],
                               atol=1e-4,
                               rtol=1e-4)
IS_PRETRAIN = False
PRETRAIN_VARS = []
PRETRAIN_DIR = ""
PRETRAIN_FILE = ""

# for debug
# BATCH_SIZE = 2
# SUMMARISE_STEPS = 1
# IS_DEBUG = True

# stride of output heatmap. the smaller, the slower.
STRIDE = 8

PRE_PROCESSOR = Sequence([
    ResizeWithJoints(image_size=IMAGE_SIZE),
    JointsToGaussianHeatmap(image_size=IMAGE_SIZE, stride=STRIDE, sigma=2),
    DivideBy255()
])
POST_PROCESSOR = Sequence([
    GaussianHeatmapToJoints(num_dimensions=2,
                            stride=STRIDE,
                            confidence_threshold=0.1)
])

step_per_epoch = 149813 // BATCH_SIZE

NETWORK = EasyDict()
NETWORK.OPTIMIZER_CLASS = tf.compat.v1.train.AdamOptimizer
NETWORK.OPTIMIZER_KWARGS = {}
NETWORK.LEARNING_RATE_FUNC = tf.compat.v1.train.piecewise_constant
NETWORK.LEARNING_RATE_KWARGS = {