Example #1
0
    def handle(self, video_path: str) -> bool:
        super(KerasHandler, self).handle(video_path)
        video = VideoObject(video_path)
        if self.preload:
            video.load_frames()

        # --- cutter ---
        cutter = VideoCutter()
        res = cutter.cut(video)
        stable, unstable = res.get_range(threshold=0.98, offset=3)

        # --- classify ---
        cl = KerasClassifier()
        if self.model_path:
            logger.info("load existed pre-train model")
            cl.load_model(self.model_path)
        else:
            data_home = res.pick_and_save(stable,
                                          self.frame_count,
                                          to_dir=self.result_path)
            cl.train(data_home)
        self.classifier_result = cl.classify(video, stable)

        # --- draw ---
        r = Reporter()
        r.draw(self.classifier_result, report_path=self.result_report_path)
        return True
def test_keras():
    # set epochs to 1 for quickly training (test only)
    cl = KerasClassifier(epochs=1)
    cl.train(CUTTER_RESULT_DIR)
    cl.save_model("haha.h5")
    # recreate
    cl = KerasClassifier()
    cl.load_model("haha.h5")
    stable, _ = cutter_res.get_range()
    classify_result = cl.classify(VIDEO_PATH, stable, keep_data=True)
    assert classify_result.to_dict()
Example #3
0
from stagesepx.cutter import VideoCutter
from stagesepx.classifier.keras import KerasClassifier
from stagesepx.reporter import Reporter
from stagesepx.video import VideoObject

video_path = "../videos/douyin1.mp4"
video = VideoObject(video_path)
video.load_frames()

# --- cutter ---
cutter = VideoCutter()
res = cutter.cut(video)
stable, unstable = res.get_range()

# --- classifier ---
cl = KerasClassifier(
    # 在使用时需要保证数据集格式统一(与训练集)
    # 因为 train_model.py 用了 600x800,所以这里设定成一样的
    target_size=(600, 800), )
model_file = "./keras_model.h5"
cl.load_model(model_file)

classify_result = cl.classify(video, stable, keep_data=True)
result_dict = classify_result.to_dict()

# --- draw ---
r = Reporter()
r.draw(classify_result)
Example #4
0
video = VideoObject(file_name)

# 新建帧,计算视频总共多少帧,每帧多少ms
video.load_frames()

# 压缩视频
cutter = VideoCutter()

# 计算每一帧视频的每一个block的ssim和psnr
res = cutter.cut(video)

# 判断A帧到B帧之间是否稳定还是不稳定
stable, unstable = res.get_range()

# 把分类好的稳定阶段图片保存本地
res.pick_and_save(stable, 20, to_dir='./forecast_frame', meaningful_name=True)

# 把切分号的稳定区间,进行归类
classify_result = cl.classify(file_name, stable, keep_data=True)
result_dict = classify_result.to_dict()

# 打印结果
print(result_dict)
with open('./result.txt', 'w') as f:
    f.write(str(result_dict))

# 输出HTML报告
r = Reporter()
r.draw(classify_result, './result.html')
# TODO: 时间计算 = 3[0]-0[-1]