Upload 6 files
Browse files- LICENSE.txt +180 -0
- README.md +15 -0
- app.py +210 -0
- gitattributes +38 -0
- gitignore +78 -0
- requirements.txt +52 -0
LICENSE.txt
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ModelGo Attribution-NonCommercial-ResponsibleAI License
|
| 2 |
+
Version 2.0, May 2025
|
| 3 |
+
|
| 4 |
+
By exercising the rights granted in Section 2.1, You acknowledge and agree that You have
|
| 5 |
+
read, understood, and agree to be bound by the terms and conditions of this License. If You
|
| 6 |
+
do not agree to any terms and/or conditions of this License, then the Licensor grants You no
|
| 7 |
+
rights under this License.
|
| 8 |
+
|
| 9 |
+
1. DEFINITIONS
|
| 10 |
+
|
| 11 |
+
"Complementary Materials" means the source code and scripts used to define, run, load,
|
| 12 |
+
benchmark and/or evaluate the Model, and prepare data for the purpose of training, pretraining,
|
| 13 |
+
fine-tuning and/or evaluation of the Model, and any tutorials, operating manuals, user guides
|
| 14 |
+
and/or documentation that guide users in using, operating, implementing and/or customising
|
| 15 |
+
the Model.
|
| 16 |
+
|
| 17 |
+
"Derivative Materials" means all improvements, modifications or derivative works to the
|
| 18 |
+
Licensed Material or any part thereof, which are created or developed by You (either by
|
| 19 |
+
Yourself or jointly with other third parties), including any derivative model developed by
|
| 20 |
+
transferring patterns of weights, parameters, activations and/or Output from the Model, such as
|
| 21 |
+
through distillation methods or synthetic data generation techniques, in order to replicate,
|
| 22 |
+
approximate, or otherwise achieve functional behavior that is similar to the Model.
|
| 23 |
+
|
| 24 |
+
"Distribution" (or "Distribute") means any transmission, publication, public performance,
|
| 25 |
+
sharing, or other methods of making the Licensed Materials, Derivative Materials and/or Output
|
| 26 |
+
available to a third party, including providing the Licensed Materials or any part thereof as a
|
| 27 |
+
hosted service or remotely accessible service, such as API-based access or web access.
|
| 28 |
+
|
| 29 |
+
"Licensor" means the rights owner that is granting the License.
|
| 30 |
+
|
| 31 |
+
"Licensed Materials" means the Model and Complementary Materials that are Distributed by
|
| 32 |
+
the Licensor under this License. The Licensed Materials do not include any datasets used for
|
| 33 |
+
pretraining, training, adapting, or evaluating the Model, which may or may not be made
|
| 34 |
+
available under a separate license.
|
| 35 |
+
|
| 36 |
+
"Model" means the machine-learning constructs and/or assemblies licensed by the Licensor
|
| 37 |
+
under this License, including any checkpoints, learned weights, parameters (including optimizer
|
| 38 |
+
states) and the model architecture.
|
| 39 |
+
|
| 40 |
+
"NonCommercial" means not primarily intended for or directed towards commercial advantage
|
| 41 |
+
or monetary compensation.
|
| 42 |
+
|
| 43 |
+
"Output" means any information, data, and/or content, including but not limited to images, text,
|
| 44 |
+
text effects, audio files, and/or video files, generated through operation of the Model, or through
|
| 45 |
+
operation of any new model developed by transferring patterns from the Model.
|
| 46 |
+
|
| 47 |
+
"You" (or "Your") means you, or any other person or entity you are entering into this license on
|
| 48 |
+
behalf of, provided you have the legal authority to bind such person or entity.
|
| 49 |
+
|
| 50 |
+
2. LICENSE RIGHTS
|
| 51 |
+
|
| 52 |
+
2.1 Grant of Rights
|
| 53 |
+
|
| 54 |
+
(a) Subject to the conditions in Section 2.2 of this License, the Licensor hereby grants to
|
| 55 |
+
You a non-exclusive, non-sublicensable, revocable, royalty-free, worldwide license under
|
| 56 |
+
the relevant copyrights, patent rights, database rights, and any other intellectual property
|
| 57 |
+
rights to:
|
| 58 |
+
|
| 59 |
+
(i) make, have made, use, reproduce and Distribute the Licensed Materials;
|
| 60 |
+
|
| 61 |
+
(ii) use the Licensed Materials to create Derivative Materials; and
|
| 62 |
+
|
| 63 |
+
(iii) make, have made, use, reproduce and Distribute Derivative Materials;
|
| 64 |
+
|
| 65 |
+
for NonCommercial purposes only.
|
| 66 |
+
|
| 67 |
+
2.2 Conditions
|
| 68 |
+
|
| 69 |
+
(a) If You Distribute any of the Licensed Materials or Derivative Materials, You shall:
|
| 70 |
+
|
| 71 |
+
(i) provide a copy of this License with the Licensed Material or Derivative Materials;
|
| 72 |
+
|
| 73 |
+
(ii) in the case of Distributing Derivative Materials, provide as part of the Distribution,
|
| 74 |
+
prominent notices stating that You have modified the Licensed Materials and the
|
| 75 |
+
relevant date of such modification;
|
| 76 |
+
|
| 77 |
+
(iii) retain as part of the Distribution any existing copyright notice, attribution notice,
|
| 78 |
+
and/or any notice identifying the authors of the Licensed Materials and any
|
| 79 |
+
Derivative Materials.
|
| 80 |
+
|
| 81 |
+
(b) If You Distribute a collection of Output as a dataset generated wholly or partially using
|
| 82 |
+
the Licensed Materials and/or Derivative Materials, You shall provide a prominent notice
|
| 83 |
+
in the Distribution stating that the dataset is generated using the Licensed Materials
|
| 84 |
+
and/or Derivative Materials provided under this License.
|
| 85 |
+
|
| 86 |
+
(c) You agree not to use the Licensed Materials or any Derivative Materials:
|
| 87 |
+
|
| 88 |
+
(i) for any illegal or unlawful purposes, including in any way that violates any
|
| 89 |
+
applicable national, federal, state, local, or international law or regulation;
|
| 90 |
+
|
| 91 |
+
(ii) for the purpose of exploiting, harming, or attempting to exploit or harm minors in
|
| 92 |
+
any way;
|
| 93 |
+
|
| 94 |
+
(iii) for the purpose of generating, transmitting and/or disseminating computer code,
|
| 95 |
+
files, scripts and programs, including any malware and/or software, that is
|
| 96 |
+
intended or known to be harmful, destructive, disabling or which assists in or
|
| 97 |
+
enables theft, alteration, denial of service, unauthorised disclosure or destruction
|
| 98 |
+
or corruption of data, including viruses, worms, spyware, adware, keyloggers,
|
| 99 |
+
trojans, ransomware and any other type of threats;
|
| 100 |
+
(iv) for any fraudulent purpose, such as generating, transmitting and/or disseminating
|
| 101 |
+
verifiably false information and/or content;
|
| 102 |
+
|
| 103 |
+
(v) for the purpose of generating, transmitting and/or disseminating personal data with
|
| 104 |
+
the purpose of harming others;
|
| 105 |
+
|
| 106 |
+
(vi) for the purpose of generating, transmitting and/or disseminating information
|
| 107 |
+
(including, but not limited to, images, code, posts, articles), and placing the
|
| 108 |
+
information in any public context (including, but not limited to, bot generating
|
| 109 |
+
tweets) without expressly and intelligibly disclaiming that the information and/or
|
| 110 |
+
content is machine generated;
|
| 111 |
+
|
| 112 |
+
(vii) for any libelous, defamatory, obscene or threatening purposes;
|
| 113 |
+
|
| 114 |
+
(viii) for the purpose of impersonating or attempting to impersonate human beings for
|
| 115 |
+
the purposes of deception;
|
| 116 |
+
|
| 117 |
+
(ix) for the purpose of enabling and/or facilitating fully automated decision-making that
|
| 118 |
+
adversely impacts an individual’s legal rights or otherwise creates or modifies a
|
| 119 |
+
binding, enforceable obligation without expressly and intelligibly disclaiming that
|
| 120 |
+
the creation or modification of the obligation is machine generated;
|
| 121 |
+
|
| 122 |
+
(x) for the purpose of enabling and/or facilitating discrimination and/or harm against
|
| 123 |
+
individuals or groups based on online or offline social behavior or known or
|
| 124 |
+
predicted personal or personality characteristics;
|
| 125 |
+
|
| 126 |
+
(xi) for the purpose of exploiting any of the vulnerabilities of a specific group of
|
| 127 |
+
persons based on their age, social, physical, or mental characteristics, in order to
|
| 128 |
+
materially distort the behavior of a person pertaining to that group in a manner that
|
| 129 |
+
causes or is likely to cause that person or another person physical or
|
| 130 |
+
psychological harm;
|
| 131 |
+
|
| 132 |
+
(xii) for the purpose of enabling and/or facilitating discrimination against individuals or
|
| 133 |
+
groups based on legally protected characteristics or categories;
|
| 134 |
+
|
| 135 |
+
(xiii) for the purpose of providing medical advice or medical results interpretation that is
|
| 136 |
+
intended to be a substitute for professional medical advice, diagnosis, or treatment;
|
| 137 |
+
and
|
| 138 |
+
|
| 139 |
+
(xiv) for the purpose of enabling and/or facilitating fully automated decision-making in
|
| 140 |
+
the administration of justice, law enforcement, immigration, or asylum processes.
|
| 141 |
+
|
| 142 |
+
2.3 Reservation of Rights
|
| 143 |
+
|
| 144 |
+
You shall not refer to the Licensor or use the Licensor's trademarks, trade names, and service
|
| 145 |
+
marks, for any publicity, advertising or marketing purposes, without the Licensor's prior written
|
| 146 |
+
consent.
|
| 147 |
+
|
| 148 |
+
3. DISCLAIMER
|
| 149 |
+
|
| 150 |
+
To the maximum extent permissible under applicable law, the Licensed Materials are provided
|
| 151 |
+
on an "as is" and "as available" basis without any representation or warranty of any kind
|
| 152 |
+
(whether express, implied, statutory or otherwise), including of merchantability, satisfactory
|
| 153 |
+
quality, fitness for a particular purpose, title, accuracy, correctness, absence of error, reliability,
|
| 154 |
+
timeliness, non-infringement of or compliance with any laws, regulations and/or third-party
|
| 155 |
+
rights, all of which are expressly disclaimed by the Licensor.
|
| 156 |
+
|
| 157 |
+
4. LIMITATION OF LIABILITY
|
| 158 |
+
|
| 159 |
+
To the maximum extent permissible under applicable law, the Licensor shall not be liable for
|
| 160 |
+
any claims, damages, or any other liabilities, in any way arising out of or in connection with the
|
| 161 |
+
Licensed Materials, Derivative Materials, and/or Output, whether on an action or claim in
|
| 162 |
+
contract, tort (including negligence), breach of statutory duty or otherwise, even if the Licensor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
5. TERMINATION
|
| 166 |
+
|
| 167 |
+
This License shall terminate immediately if You breach any material term and/or condition of
|
| 168 |
+
this License, or if You initiate any legal action against the Licensor alleging that the Licensed
|
| 169 |
+
Materials and/or Derivative Materials infringe any patent worldwide. Sections 3, 4 and 6 shall
|
| 170 |
+
survive the termination of this License.
|
| 171 |
+
|
| 172 |
+
6. MODIFICATION OF THIS LICENSE
|
| 173 |
+
|
| 174 |
+
This License is Copyright © 2024 National University of Singapore. Permission is granted to
|
| 175 |
+
copy, distribute, or communicate this License without modification. Nothing in this License
|
| 176 |
+
permits You to modify this License as applied to the Licensed Materials. However, You may
|
| 177 |
+
modify the text of this License and copy, distribute or communicate Your modified version and
|
| 178 |
+
apply it to other original works of authorship, provided that You do not use the name "ModelGo"
|
| 179 |
+
for your version of the license and furnish a readable notice describing Your modifications to
|
| 180 |
+
this License.
|
README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: UniGaze
|
| 3 |
+
emoji: 🐠
|
| 4 |
+
colorFrom: gray
|
| 5 |
+
colorTo: yellow
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 5.43.1
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: other
|
| 11 |
+
short_description: Online Demo of UniGaze
|
| 12 |
+
---
|
| 13 |
+
This is demo of the approach described in the paper ["UniGaze: Towards Universal Gaze Estimation via Large-scale Pre-Training"](https://arxiv.org/abs/2502.02307)
|
| 14 |
+
|
| 15 |
+
Check out the project page at https://ut-vision.github.io/UniGaze
|
app.py
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
import time
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from typing import List, Optional, Tuple
|
| 7 |
+
|
| 8 |
+
import gradio as gr
|
| 9 |
+
import numpy as np
|
| 10 |
+
from huggingface_hub import hf_hub_download, HfApi
|
| 11 |
+
from unigaze.infer_runtime import UniGazeRuntime # in-process runtime (no subprocess)
|
| 12 |
+
|
| 13 |
+
# --------------------------------------------------------------------------------------
|
| 14 |
+
# Defaults
|
| 15 |
+
# --------------------------------------------------------------------------------------
|
| 16 |
+
DEFAULT_HF_REPO = "xucongzhang/UniGaze-models"
|
| 17 |
+
DEFAULT_CKPT_FILE = [
|
| 18 |
+
"unigaze_h14_joint.pth.tar",
|
| 19 |
+
"unigaze_l16_joint.pth.tar",
|
| 20 |
+
"unigaze_b16_joint.pth.tar",
|
| 21 |
+
]
|
| 22 |
+
DEFAULT_REVISION = "main"
|
| 23 |
+
|
| 24 |
+
DEFAULT_CFGS = [
|
| 25 |
+
"unigaze/configs/model/mae_h_14_gaze.yaml",
|
| 26 |
+
"unigaze/configs/model/mae_L_16_gaze.yaml",
|
| 27 |
+
"unigaze/configs/model/mae_b_16_gaze.yaml",
|
| 28 |
+
]
|
| 29 |
+
|
| 30 |
+
TITLE = "UniGaze Demo (Video + Image)"
|
| 31 |
+
DESC = """
|
| 32 |
+
Upload a short video or a single image. The app downloads a checkpoint from the Hub,
|
| 33 |
+
runs UniGaze in-process (no subprocess, no permanent writes), and returns results.
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
# Ensure imports of local packages work
|
| 37 |
+
sys.path.append(os.path.dirname(__file__))
|
| 38 |
+
|
| 39 |
+
# --------------------------------------------------------------------------------------
|
| 40 |
+
# Helpers
|
| 41 |
+
# --------------------------------------------------------------------------------------
|
| 42 |
+
def resolve_cfg_abs(cfg_str: str) -> Path:
|
| 43 |
+
"""Return an absolute path to the YAML config."""
|
| 44 |
+
p = Path(cfg_str)
|
| 45 |
+
if p.is_absolute():
|
| 46 |
+
if p.exists():
|
| 47 |
+
return p
|
| 48 |
+
raise FileNotFoundError(f"Config not found: {p}")
|
| 49 |
+
|
| 50 |
+
p2 = (Path.cwd() / p).resolve()
|
| 51 |
+
if p2.exists():
|
| 52 |
+
return p2
|
| 53 |
+
|
| 54 |
+
if str(p).startswith("configs/"):
|
| 55 |
+
p3 = (Path.cwd() / "unigaze" / p).resolve()
|
| 56 |
+
if p3.exists():
|
| 57 |
+
return p3
|
| 58 |
+
|
| 59 |
+
raise FileNotFoundError(f"Config not found. Tried: {p2}")
|
| 60 |
+
|
| 61 |
+
def list_weight_files(repo_id: str, revision: str = "main") -> List[str]:
|
| 62 |
+
try:
|
| 63 |
+
api = HfApi()
|
| 64 |
+
files = api.list_repo_files(repo_id=repo_id, repo_type="model", revision=revision)
|
| 65 |
+
return [f for f in files if f.lower().endswith((".pth", ".pt", ".safetensors", ".tar", ".pth.tar"))]
|
| 66 |
+
except Exception:
|
| 67 |
+
return []
|
| 68 |
+
|
| 69 |
+
def get_ckpt_path(repo_id: str, filename: str, revision: str = "main") -> str:
|
| 70 |
+
files = list_weight_files(repo_id, revision)
|
| 71 |
+
if files and filename not in files:
|
| 72 |
+
raise FileNotFoundError(
|
| 73 |
+
f"File '{filename}' not found in model repo '{repo_id}' at rev '{revision}'. "
|
| 74 |
+
f"Available weights: {files}"
|
| 75 |
+
)
|
| 76 |
+
return hf_hub_download(
|
| 77 |
+
repo_id=repo_id,
|
| 78 |
+
filename=filename,
|
| 79 |
+
revision=revision,
|
| 80 |
+
repo_type="model",
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
# Cache the runtime so we load model/FA only once
|
| 84 |
+
from functools import lru_cache
|
| 85 |
+
@lru_cache(maxsize=3)
|
| 86 |
+
def get_runtime(cfg_abs_str: str, ckpt_path: str, device: str = "cpu") -> UniGazeRuntime:
|
| 87 |
+
return UniGazeRuntime(cfg_abs_str, ckpt_path, device=device)
|
| 88 |
+
|
| 89 |
+
# --------------------------------------------------------------------------------------
|
| 90 |
+
# Runners (in-process)
|
| 91 |
+
# --------------------------------------------------------------------------------------
|
| 92 |
+
def run_unigaze_on_video(
|
| 93 |
+
video_path: str,
|
| 94 |
+
hf_repo: str,
|
| 95 |
+
ckpt_filename: str,
|
| 96 |
+
cfg_path_user: str,
|
| 97 |
+
extra_args: str = "",
|
| 98 |
+
) -> Tuple[Optional[np.ndarray], Optional[str], Optional[str], str]:
|
| 99 |
+
logs: List[str] = []
|
| 100 |
+
t0 = time.time()
|
| 101 |
+
|
| 102 |
+
try:
|
| 103 |
+
ckpt_path = get_ckpt_path(hf_repo, ckpt_filename, revision=DEFAULT_REVISION)
|
| 104 |
+
logs.append(f"[hub] downloaded: {ckpt_path}")
|
| 105 |
+
except Exception as e:
|
| 106 |
+
return None, None, None, f"[hub] ERROR: {e}"
|
| 107 |
+
|
| 108 |
+
try:
|
| 109 |
+
cfg_abs = resolve_cfg_abs(cfg_path_user)
|
| 110 |
+
except Exception as e:
|
| 111 |
+
return None, None, None, f"[cfg] {e}"
|
| 112 |
+
|
| 113 |
+
rt = get_runtime(str(cfg_abs), ckpt_path, device="cpu")
|
| 114 |
+
mp4_path, last_rgb, run_sec = rt.predict_video(video_path)
|
| 115 |
+
logs.append(f"[time] total runtime: {run_sec:.2f} seconds")
|
| 116 |
+
|
| 117 |
+
return (last_rgb if last_rgb is not None else None), mp4_path, None, "\n".join(logs)
|
| 118 |
+
|
| 119 |
+
def run_unigaze_on_image(
|
| 120 |
+
image_array: np.ndarray,
|
| 121 |
+
hf_repo: str,
|
| 122 |
+
ckpt_filename: str,
|
| 123 |
+
cfg_path_user: str,
|
| 124 |
+
extra_args: str = "",
|
| 125 |
+
) -> Tuple[Optional[np.ndarray], str]:
|
| 126 |
+
logs: List[str] = []
|
| 127 |
+
t0 = time.time()
|
| 128 |
+
|
| 129 |
+
try:
|
| 130 |
+
ckpt_path = get_ckpt_path(hf_repo, ckpt_filename, revision=DEFAULT_REVISION)
|
| 131 |
+
logs.append(f"[hub] downloaded: {ckpt_path}")
|
| 132 |
+
except Exception as e:
|
| 133 |
+
return None, f"[hub] ERROR: {e}"
|
| 134 |
+
|
| 135 |
+
try:
|
| 136 |
+
cfg_abs = resolve_cfg_abs(cfg_path_user)
|
| 137 |
+
except Exception as e:
|
| 138 |
+
return None, f"[cfg] {e}"
|
| 139 |
+
|
| 140 |
+
rt = get_runtime(str(cfg_abs), ckpt_path, device="cpu")
|
| 141 |
+
out_rgb = rt.predict_image(image_array)
|
| 142 |
+
logs.append(f"[time] total runtime: {time.time() - t0:.2f} seconds")
|
| 143 |
+
|
| 144 |
+
return out_rgb, "\n".join(logs)
|
| 145 |
+
|
| 146 |
+
# --------------------------------------------------------------------------------------
|
| 147 |
+
# UI
|
| 148 |
+
# --------------------------------------------------------------------------------------
|
| 149 |
+
with gr.Blocks(title=TITLE) as demo:
|
| 150 |
+
gr.Markdown(f"# {TITLE}\n{DESC}")
|
| 151 |
+
|
| 152 |
+
with gr.Row():
|
| 153 |
+
ckpt_file = gr.Dropdown(choices=DEFAULT_CKPT_FILE, value=DEFAULT_CKPT_FILE[0], label="Checkpoint filename")
|
| 154 |
+
cfg_choice = gr.Dropdown(choices=DEFAULT_CFGS, value=DEFAULT_CFGS[0], label="Model config")
|
| 155 |
+
|
| 156 |
+
# IMAGE TAB
|
| 157 |
+
with gr.Tab("Image"):
|
| 158 |
+
in_img = gr.Image(type="numpy", label="Input image")
|
| 159 |
+
run_img = gr.Button("Run on Image", variant="primary")
|
| 160 |
+
out_img = gr.Image(label="Output image")
|
| 161 |
+
out_logs = gr.Textbox(label="Logs", interactive=False, lines=18)
|
| 162 |
+
|
| 163 |
+
def ui_predict_image(image, ckpt, cfg_use):
|
| 164 |
+
return run_unigaze_on_image(
|
| 165 |
+
image_array=image,
|
| 166 |
+
hf_repo=DEFAULT_HF_REPO,
|
| 167 |
+
ckpt_filename=ckpt,
|
| 168 |
+
cfg_path_user=cfg_use,
|
| 169 |
+
)
|
| 170 |
+
|
| 171 |
+
run_img.click(
|
| 172 |
+
fn=ui_predict_image,
|
| 173 |
+
inputs=[in_img, ckpt_file, cfg_choice],
|
| 174 |
+
outputs=[out_img, out_logs],
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
# Example image
|
| 178 |
+
gr.Examples(
|
| 179 |
+
examples=[["examples/The_Night_Watch_Frans_Banninck_Cocq.png", DEFAULT_CKPT_FILE[0], DEFAULT_CFGS[0]]],
|
| 180 |
+
inputs=[in_img, ckpt_file, cfg_choice],
|
| 181 |
+
outputs=[out_img, out_logs],
|
| 182 |
+
fn=ui_predict_image,
|
| 183 |
+
cache_examples=False,
|
| 184 |
+
)
|
| 185 |
+
|
| 186 |
+
# VIDEO TAB
|
| 187 |
+
with gr.Tab("Video"):
|
| 188 |
+
in_vid = gr.Video(label="Input video", sources=["upload"])
|
| 189 |
+
run_vid = gr.Button("Run on Video", variant="primary")
|
| 190 |
+
out_img_v = gr.Image(label="Annotated image (last frame)")
|
| 191 |
+
out_vid_v = gr.Video(label="Output video")
|
| 192 |
+
out_zip_v = gr.File(label="All artifacts as ZIP") # always None now
|
| 193 |
+
out_logs_v = gr.Textbox(label="Logs", interactive=False, lines=18)
|
| 194 |
+
|
| 195 |
+
def ui_predict_video(video, ckpt, cfg_use):
|
| 196 |
+
return run_unigaze_on_video(
|
| 197 |
+
video_path=video,
|
| 198 |
+
hf_repo=DEFAULT_HF_REPO,
|
| 199 |
+
ckpt_filename=ckpt,
|
| 200 |
+
cfg_path_user=cfg_use,
|
| 201 |
+
)
|
| 202 |
+
|
| 203 |
+
run_vid.click(
|
| 204 |
+
fn=ui_predict_video,
|
| 205 |
+
inputs=[in_vid, ckpt_file, cfg_choice],
|
| 206 |
+
outputs=[out_img_v, out_vid_v, out_zip_v, out_logs_v],
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
if __name__ == "__main__":
|
| 210 |
+
demo.launch()
|
gitattributes
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
example/The_Night_Watch_Frans_Banninck_Cocq.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
examples/The_Night_Watch_Frans_Banninck_Cocq.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
examples/De_Nachtwacht.png filter=lfs diff=lfs merge=lfs -text
|
gitignore
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.DS_Store
|
| 2 |
+
*.h5
|
| 3 |
+
*.json
|
| 4 |
+
.vscode
|
| 5 |
+
*.pth
|
| 6 |
+
result/
|
| 7 |
+
*.npy
|
| 8 |
+
*.pdf
|
| 9 |
+
cache/
|
| 10 |
+
*.txt
|
| 11 |
+
!requirements.txt
|
| 12 |
+
*.drawio
|
| 13 |
+
|
| 14 |
+
*.ipynb
|
| 15 |
+
!load_gaze_model.ipynb
|
| 16 |
+
.ipynb_checkpoints
|
| 17 |
+
*.npy
|
| 18 |
+
*.dat
|
| 19 |
+
*.bz2
|
| 20 |
+
|
| 21 |
+
figures/
|
| 22 |
+
*.csv
|
| 23 |
+
prototype/
|
| 24 |
+
__pycache__/
|
| 25 |
+
results/
|
| 26 |
+
*.xlsx
|
| 27 |
+
run_on_server/
|
| 28 |
+
|
| 29 |
+
memo/
|
| 30 |
+
ckpt/
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
sig.sh
|
| 35 |
+
*.pkl
|
| 36 |
+
|
| 37 |
+
*.pt
|
| 38 |
+
*.pth
|
| 39 |
+
|
| 40 |
+
*.pyc
|
| 41 |
+
|
| 42 |
+
# src/clip
|
| 43 |
+
# src/taming-transformers
|
| 44 |
+
|
| 45 |
+
*.ckpt
|
| 46 |
+
*.pth.tar
|
| 47 |
+
checkpoints/*
|
| 48 |
+
|
| 49 |
+
!checkpoints/pre_trained_ckpt.md
|
| 50 |
+
!checkpoints/*.md
|
| 51 |
+
|
| 52 |
+
logs/*
|
| 53 |
+
|
| 54 |
+
*.jpg
|
| 55 |
+
*.png
|
| 56 |
+
*.JPG
|
| 57 |
+
|
| 58 |
+
*.PNG
|
| 59 |
+
*.gif
|
| 60 |
+
__pycache__/
|
| 61 |
+
|
| 62 |
+
*.log
|
| 63 |
+
*.sh
|
| 64 |
+
|
| 65 |
+
configs/data_path.yaml
|
| 66 |
+
|
| 67 |
+
!assets/*.jpg
|
| 68 |
+
!configs/trainer/figs/*.jpg
|
| 69 |
+
!configs/trainer/figs/*.png
|
| 70 |
+
!assets/figs/*/*
|
| 71 |
+
!data/face_model.txt
|
| 72 |
+
batch_log*/
|
| 73 |
+
|
| 74 |
+
scripts/
|
| 75 |
+
*out
|
| 76 |
+
*_nodeinfo
|
| 77 |
+
|
| 78 |
+
outputs/
|
requirements.txt
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.0.0
|
| 2 |
+
huggingface_hub>=0.23.0
|
| 3 |
+
|
| 4 |
+
rich
|
| 5 |
+
wandb
|
| 6 |
+
glob2
|
| 7 |
+
h5py
|
| 8 |
+
omegaconf
|
| 9 |
+
matplotlib
|
| 10 |
+
imageio
|
| 11 |
+
imageio-ffmpeg
|
| 12 |
+
seaborn
|
| 13 |
+
torch-summary
|
| 14 |
+
torchfile
|
| 15 |
+
torchmetrics
|
| 16 |
+
|
| 17 |
+
transformers
|
| 18 |
+
accelerate
|
| 19 |
+
albumentations
|
| 20 |
+
chumpy
|
| 21 |
+
cmake
|
| 22 |
+
coloredlogs
|
| 23 |
+
colorlog
|
| 24 |
+
cython
|
| 25 |
+
diffusers
|
| 26 |
+
easydict
|
| 27 |
+
einops
|
| 28 |
+
lpips
|
| 29 |
+
|
| 30 |
+
opencv-python
|
| 31 |
+
optuna
|
| 32 |
+
pandas
|
| 33 |
+
protobuf
|
| 34 |
+
pyopengl
|
| 35 |
+
pytorch-fid
|
| 36 |
+
pytorch-lightning
|
| 37 |
+
pytorch-metric-learning
|
| 38 |
+
scikit-image
|
| 39 |
+
scikit-learn
|
| 40 |
+
scipy
|
| 41 |
+
|
| 42 |
+
tensorboard
|
| 43 |
+
tensorboardx
|
| 44 |
+
|
| 45 |
+
face-alignment
|
| 46 |
+
|
| 47 |
+
numpy==1.24.4
|
| 48 |
+
hydra-core
|
| 49 |
+
torch==2.0.1
|
| 50 |
+
timm>=0.6.13
|
| 51 |
+
torchvision==0.15.2
|
| 52 |
+
|