Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
53 lines
2.2 KiB
Python
53 lines
2.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
import torch
|
|
import numpy as np
|
|
import argparse
|
|
|
|
from .utils import convert_to_numpy
|
|
|
|
class FlowAnnotator:
|
|
def __init__(self, cfg, device=None):
|
|
try:
|
|
from raft import RAFT
|
|
from raft.utils.utils import InputPadder
|
|
from raft.utils import flow_viz
|
|
except:
|
|
import warnings
|
|
warnings.warn(
|
|
"ignore raft import, please pip install raft package. you can refer to models/VACE-Annotators/flow/raft-1.0.0-py3-none-any.whl")
|
|
|
|
params = {
|
|
"small": False,
|
|
"mixed_precision": False,
|
|
"alternate_corr": False
|
|
}
|
|
params = argparse.Namespace(**params)
|
|
pretrained_model = cfg['PRETRAINED_MODEL']
|
|
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu") if device is None else device
|
|
self.model = RAFT(params)
|
|
self.model.load_state_dict({k.replace('module.', ''): v for k, v in torch.load(pretrained_model, map_location="cpu", weights_only=True).items()})
|
|
self.model = self.model.to(self.device).eval()
|
|
self.InputPadder = InputPadder
|
|
self.flow_viz = flow_viz
|
|
|
|
def forward(self, frames):
|
|
# frames / RGB
|
|
frames = [torch.from_numpy(convert_to_numpy(frame).astype(np.uint8)).permute(2, 0, 1).float()[None].to(self.device) for frame in frames]
|
|
flow_up_list, flow_up_vis_list = [], []
|
|
with torch.no_grad():
|
|
for i, (image1, image2) in enumerate(zip(frames[:-1], frames[1:])):
|
|
padder = self.InputPadder(image1.shape)
|
|
image1, image2 = padder.pad(image1, image2)
|
|
flow_low, flow_up = self.model(image1, image2, iters=20, test_mode=True)
|
|
flow_up = flow_up[0].permute(1, 2, 0).cpu().numpy()
|
|
flow_up_vis = self.flow_viz.flow_to_image(flow_up)
|
|
flow_up_list.append(flow_up)
|
|
flow_up_vis_list.append(flow_up_vis)
|
|
return flow_up_list, flow_up_vis_list # RGB
|
|
|
|
|
|
class FlowVisAnnotator(FlowAnnotator):
|
|
def forward(self, frames):
|
|
flow_up_list, flow_up_vis_list = super().forward(frames)
|
|
return flow_up_vis_list[:1] + flow_up_vis_list |