<commit_before>from preprocess import MSRII
from preprocess.c3d import C3DFeatureNet
from preprocess.video import Video
from network.model import FC4Net


def main():
    dataset = MSRII.Dataset('/data-disk/MSRII/')
    c3dnet = C3DFeatureNet(feature_file='data/features/MSRII-c3d-features.h5')

    c3dnet.load()
    c3dnet.start(dataset)


def test():
    video = Video('/data-disk/MSRII/videos/1.avi')

    c3dnet = C3DFeatureNet(feature_file=None)
    c3dnet.load()
    y = c3dnet.extract_feature(video)

    fc4net = FC4Net()
    fc4net.load_weights('data/weights/FC4Net_weights.h5')
    pred = fc4net.predict(y, batch_size=32)

    print(pred.shape)

if __name__ == '__main__':
    test()<commit_msg>make test phase complete output proposals<commit_after>import numpy as np

from preprocess import MSRII
from preprocess.c3d import C3DFeatureNet
from preprocess.video import Video
from network.model import FC4Net


def main():
    dataset = MSRII.Dataset('/data-disk/MSRII/')
    c3dnet = C3DFeatureNet(feature_file='data/features/MSRII-c3d-features.h5')

    c3dnet.load()
    c3dnet.start(dataset)


def test(num_video=5):
    dataset = MSRII.Dataset('/data-disk/MSRII/')

    c3dnet = C3DFeatureNet(feature_file=None)
    c3dnet.load()

    fc4net = FC4Net()
    fc4net.load_weights('data/weights/FC4Net_weights.h5')

    for i in range(num_video):
        video_meta = dataset.video_metas[i]
        video = Video('/data-disk/MSRII/videos/' + video_meta.name)
        y = c3dnet.extract_feature(video)
        pred = fc4net.predict(y, batch_size=32)

        predict = nms(pred, tol=16)

        seg_metas = dataset.video_metas[0].seg_metas
        target = []
        for seg_meta in seg_metas:
            s = seg_meta['start']
            t = seg_meta['duration']
            target.append((s, s + t))

        print('Target', target)
        print('Predict', predict)


def nms(pred, tol=16, prob_ths=.5):
    p = pred.reshape(len(pred))
    candidate = np.where(p > prob_ths)

    start = np.multiply(candidate, 16).tolist()[0]
    end = (np.multiply(candidate, 16) + 16).tolist()[0]

    predict = []
    skip = [0 for _ in range(len(start))]
    for i, p in enumerate(zip(start, end)):
        s, e = p
        if skip[i]:
            continue
        next_idx = i + 1 if i + 1 < len(start) else -1
        for j, next_s in enumerate(start[next_idx:]):
            if e + tol >= next_s:
                e = end[next_idx + j]
                skip[next_idx + j] = 1
        predict.append((s, e))

    return predict


if __name__ == '__main__':
    test(num_video=5)
{'fraction_non_alphanumeric': 0.12780790085205268, 'fraction_numerical': 0.024786986831913247, 'mean_word_length': 2.8153618906942395, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5273422', 'n_tokens_mistral': 979, 'n_tokens_neox': 935, 'n_words': 187}