Spaces:
Sleeping
Sleeping
add
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- combined_data/blendshape_annotation_preprocess.py +114 -0
- combined_data/combination_to_filename.json +80 -0
- combined_data/lapwing/images/000001.png +0 -0
- combined_data/lapwing/images/000002.png +0 -0
- combined_data/lapwing/images/000003.png +0 -0
- combined_data/lapwing/images/000004.png +0 -0
- combined_data/lapwing/images/000005.png +0 -0
- combined_data/lapwing/images/000006.png +0 -0
- combined_data/lapwing/images/000007.png +0 -0
- combined_data/lapwing/images/000008.png +0 -0
- combined_data/lapwing/images/000009.png +0 -0
- combined_data/lapwing/images/000010.png +0 -0
- combined_data/lapwing/images/000011.png +0 -0
- combined_data/lapwing/images/000012.png +0 -0
- combined_data/lapwing/images/000013.png +0 -0
- combined_data/lapwing/images/000014.png +0 -0
- combined_data/lapwing/images/000015.png +0 -0
- combined_data/lapwing/images/000016.png +0 -0
- combined_data/lapwing/images/000017.png +0 -0
- combined_data/lapwing/images/000018.png +0 -0
- combined_data/lapwing/images/000019.png +0 -0
- combined_data/lapwing/images/000020.png +0 -0
- combined_data/lapwing/images/000021.png +0 -0
- combined_data/lapwing/images/000022.png +0 -0
- combined_data/lapwing/images/000023.png +0 -0
- combined_data/lapwing/images/000024.png +0 -0
- combined_data/lapwing/images/000025.png +0 -0
- combined_data/lapwing/images/000026.png +0 -0
- combined_data/lapwing/images/000027.png +0 -0
- combined_data/lapwing/images/000028.png +0 -0
- combined_data/lapwing/images/000029.png +0 -0
- combined_data/lapwing/images/000030.png +0 -0
- combined_data/lapwing/images/000031.png +0 -0
- combined_data/lapwing/images/000032.png +0 -0
- combined_data/lapwing/images/000033.png +0 -0
- combined_data/lapwing/images/000034.png +0 -0
- combined_data/lapwing/images/000035.png +0 -0
- combined_data/lapwing/images/000036.png +0 -0
- combined_data/lapwing/images/000037.png +0 -0
- combined_data/lapwing/images/000038.png +0 -0
- combined_data/lapwing/images/000039.png +0 -0
- combined_data/lapwing/images/000040.png +0 -0
- combined_data/lapwing/images/000041.png +0 -0
- combined_data/lapwing/images/000042.png +0 -0
- combined_data/lapwing/images/000043.png +0 -0
- combined_data/lapwing/images/000044.png +0 -0
- combined_data/lapwing/images/000045.png +0 -0
- combined_data/lapwing/images/000046.png +0 -0
- combined_data/lapwing/images/000047.png +0 -0
- combined_data/lapwing/images/000048.png +0 -0
combined_data/blendshape_annotation_preprocess.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import json
|
| 3 |
+
import torch
|
| 4 |
+
import numpy as np
|
| 5 |
+
from PIL import Image
|
| 6 |
+
from tqdm import tqdm
|
| 7 |
+
from loguru import logger
|
| 8 |
+
from typing import Dict, List, Tuple
|
| 9 |
+
|
| 10 |
+
# ---- あなたの定義済み Dataset, transforms があるなら import ----
|
| 11 |
+
# from your_dataset import BlendShapeDataset, image_transform
|
| 12 |
+
|
| 13 |
+
def unify_index(idx: int, group_size: int) -> int:
|
| 14 |
+
"""
|
| 15 |
+
BlendShape の選択 index が group_size と同じ場合、-1 (none) に変換して返す。
|
| 16 |
+
"""
|
| 17 |
+
if idx == group_size:
|
| 18 |
+
return -1
|
| 19 |
+
return idx
|
| 20 |
+
|
| 21 |
+
def build_combination_to_filename(
|
| 22 |
+
teacher_data_file: str,
|
| 23 |
+
meta_file: str,
|
| 24 |
+
) -> Tuple[Dict[Tuple[int, ...], str], List[int]]:
|
| 25 |
+
"""
|
| 26 |
+
BlendShapeData.json を読み込み、
|
| 27 |
+
例:
|
| 28 |
+
{ (g0_idx, g1_idx, g2_idx): "000001.png", ... }
|
| 29 |
+
のような辞書を作成して返す。
|
| 30 |
+
|
| 31 |
+
さらに各グループのサイズ (blendShapeNames数 + 1) のリスト group_sizes も返す。
|
| 32 |
+
"""
|
| 33 |
+
with open(meta_file, "r", encoding="utf-8") as f:
|
| 34 |
+
meta = json.load(f)
|
| 35 |
+
blend_shape_groups = meta["blendShapeGroupsMeta"]
|
| 36 |
+
# group_sizes[i] = len(そのグループの blendShapeNames) + 1(none枠)
|
| 37 |
+
group_sizes = [len(g["blendShapeNames"]) + 1 for g in blend_shape_groups]
|
| 38 |
+
|
| 39 |
+
# teacher_data_file 読み込み
|
| 40 |
+
with open(teacher_data_file, "r", encoding="utf-8") as f:
|
| 41 |
+
teacher_data = json.load(f)
|
| 42 |
+
data_list = teacher_data["dataList"]
|
| 43 |
+
|
| 44 |
+
combination_to_filename = {}
|
| 45 |
+
for data in data_list:
|
| 46 |
+
photo_filename = data["photoFileName"]
|
| 47 |
+
blendShapeSelections = data["blendShapeSelectionsPerGroup"]
|
| 48 |
+
|
| 49 |
+
# グループ順に selectedBlendShapeIndex を取得しつつ、-1の場合は-1のまま、
|
| 50 |
+
# group_sizeと一致していたら-1へ変換(理想的には -1 しか登場しない想定だが一応対応)
|
| 51 |
+
combo = []
|
| 52 |
+
for group_idx, selection in enumerate(blendShapeSelections):
|
| 53 |
+
sel_idx = selection["selectedBlendShapeIndex"]
|
| 54 |
+
# group_sizes[group_idx] と同じなら none として -1
|
| 55 |
+
sel_idx = unify_index(sel_idx, group_sizes[group_idx])
|
| 56 |
+
combo.append(sel_idx)
|
| 57 |
+
|
| 58 |
+
combo = tuple(combo) # dictのキーにするのでtuple化
|
| 59 |
+
combination_to_filename[combo] = photo_filename
|
| 60 |
+
|
| 61 |
+
return combination_to_filename, group_sizes
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def main_offline_precompute():
|
| 66 |
+
"""
|
| 67 |
+
1. Dataset(JSON)から (組み合わせ -> filename) を作る
|
| 68 |
+
2. CLIP モデルロード
|
| 69 |
+
3. filename -> embedding
|
| 70 |
+
4. ペアワイズ類似度
|
| 71 |
+
5. 保存
|
| 72 |
+
"""
|
| 73 |
+
import argparse
|
| 74 |
+
parser = argparse.ArgumentParser()
|
| 75 |
+
parser.add_argument("--image_dir", type=str, default="lapwing/images")
|
| 76 |
+
parser.add_argument("--meta_file", type=str, default="lapwing/texts/BlendShapeGroupsMeta.json")
|
| 77 |
+
parser.add_argument("--teacher_data_file", type=str, default="lapwing/texts/BlendShapeData.json")
|
| 78 |
+
parser.add_argument("--clip_model_name", type=str, default="ViT-L-14")
|
| 79 |
+
parser.add_argument("--clip_pretrained", type=str, default="openai")
|
| 80 |
+
parser.add_argument("--batch_size", type=int, default=8)
|
| 81 |
+
parser.add_argument("--device", type=str, default="cuda")
|
| 82 |
+
parser.add_argument("--out_comb2fn", type=str, default="combination_to_filename.json")
|
| 83 |
+
parser.add_argument("--out_sims", type=str, default="pairwise_clip_sims.json")
|
| 84 |
+
|
| 85 |
+
args = parser.parse_args()
|
| 86 |
+
|
| 87 |
+
# 1. 組み合わせ->filename辞書の作成
|
| 88 |
+
combination_to_filename, group_sizes = build_combination_to_filename(
|
| 89 |
+
teacher_data_file=args.teacher_data_file,
|
| 90 |
+
meta_file=args.meta_file,
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
# 5. 保存 (JSON形式)
|
| 95 |
+
# 5.1 (combination -> filename)
|
| 96 |
+
# group_sizes も保存しておくと後段のオンライン時に参照しやすい
|
| 97 |
+
# tupleは文字列化する必要あり
|
| 98 |
+
comb2fn_dict = {
|
| 99 |
+
"group_sizes": group_sizes,
|
| 100 |
+
"mapping": {
|
| 101 |
+
",".join(map(str, comb)): fn
|
| 102 |
+
for comb, fn in combination_to_filename.items()
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
with open(args.out_comb2fn, "w", encoding="utf-8") as f:
|
| 106 |
+
json.dump(comb2fn_dict, f, ensure_ascii=False, indent=2)
|
| 107 |
+
|
| 108 |
+
# データ出力
|
| 109 |
+
for combo, filename in combination_to_filename.items():
|
| 110 |
+
logger.info(f"Combination: {combo}, Filename: {filename}")
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
if __name__ == "__main__":
|
| 114 |
+
main_offline_precompute()
|
combined_data/combination_to_filename.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"group_sizes": [
|
| 3 |
+
8,
|
| 4 |
+
9
|
| 5 |
+
],
|
| 6 |
+
"mapping": {
|
| 7 |
+
"-1,-1": "000001.png",
|
| 8 |
+
"-1,0": "000002.png",
|
| 9 |
+
"-1,1": "000003.png",
|
| 10 |
+
"-1,2": "000004.png",
|
| 11 |
+
"-1,3": "000005.png",
|
| 12 |
+
"-1,4": "000006.png",
|
| 13 |
+
"-1,5": "000007.png",
|
| 14 |
+
"-1,6": "000008.png",
|
| 15 |
+
"-1,7": "000009.png",
|
| 16 |
+
"0,-1": "000010.png",
|
| 17 |
+
"0,0": "000011.png",
|
| 18 |
+
"0,1": "000012.png",
|
| 19 |
+
"0,2": "000013.png",
|
| 20 |
+
"0,3": "000014.png",
|
| 21 |
+
"0,4": "000015.png",
|
| 22 |
+
"0,5": "000016.png",
|
| 23 |
+
"0,6": "000017.png",
|
| 24 |
+
"0,7": "000018.png",
|
| 25 |
+
"1,-1": "000019.png",
|
| 26 |
+
"1,0": "000020.png",
|
| 27 |
+
"1,1": "000021.png",
|
| 28 |
+
"1,2": "000022.png",
|
| 29 |
+
"1,3": "000023.png",
|
| 30 |
+
"1,4": "000024.png",
|
| 31 |
+
"1,5": "000025.png",
|
| 32 |
+
"1,6": "000026.png",
|
| 33 |
+
"1,7": "000027.png",
|
| 34 |
+
"2,-1": "000028.png",
|
| 35 |
+
"2,0": "000029.png",
|
| 36 |
+
"2,1": "000030.png",
|
| 37 |
+
"2,2": "000031.png",
|
| 38 |
+
"2,3": "000032.png",
|
| 39 |
+
"2,4": "000033.png",
|
| 40 |
+
"2,5": "000034.png",
|
| 41 |
+
"2,6": "000035.png",
|
| 42 |
+
"2,7": "000036.png",
|
| 43 |
+
"3,-1": "000037.png",
|
| 44 |
+
"3,0": "000038.png",
|
| 45 |
+
"3,1": "000039.png",
|
| 46 |
+
"3,2": "000040.png",
|
| 47 |
+
"3,3": "000041.png",
|
| 48 |
+
"3,4": "000042.png",
|
| 49 |
+
"3,5": "000043.png",
|
| 50 |
+
"3,6": "000044.png",
|
| 51 |
+
"3,7": "000045.png",
|
| 52 |
+
"4,-1": "000046.png",
|
| 53 |
+
"4,0": "000047.png",
|
| 54 |
+
"4,1": "000048.png",
|
| 55 |
+
"4,2": "000049.png",
|
| 56 |
+
"4,3": "000050.png",
|
| 57 |
+
"4,4": "000051.png",
|
| 58 |
+
"4,5": "000052.png",
|
| 59 |
+
"4,6": "000053.png",
|
| 60 |
+
"4,7": "000054.png",
|
| 61 |
+
"5,-1": "000055.png",
|
| 62 |
+
"5,0": "000056.png",
|
| 63 |
+
"5,1": "000057.png",
|
| 64 |
+
"5,2": "000058.png",
|
| 65 |
+
"5,3": "000059.png",
|
| 66 |
+
"5,4": "000060.png",
|
| 67 |
+
"5,5": "000061.png",
|
| 68 |
+
"5,6": "000062.png",
|
| 69 |
+
"5,7": "000063.png",
|
| 70 |
+
"6,-1": "000064.png",
|
| 71 |
+
"6,0": "000065.png",
|
| 72 |
+
"6,1": "000066.png",
|
| 73 |
+
"6,2": "000067.png",
|
| 74 |
+
"6,3": "000068.png",
|
| 75 |
+
"6,4": "000069.png",
|
| 76 |
+
"6,5": "000070.png",
|
| 77 |
+
"6,6": "000071.png",
|
| 78 |
+
"6,7": "000072.png"
|
| 79 |
+
}
|
| 80 |
+
}
|
combined_data/lapwing/images/000001.png
ADDED
|
combined_data/lapwing/images/000002.png
ADDED
|
combined_data/lapwing/images/000003.png
ADDED
|
combined_data/lapwing/images/000004.png
ADDED
|
combined_data/lapwing/images/000005.png
ADDED
|
combined_data/lapwing/images/000006.png
ADDED
|
combined_data/lapwing/images/000007.png
ADDED
|
combined_data/lapwing/images/000008.png
ADDED
|
combined_data/lapwing/images/000009.png
ADDED
|
combined_data/lapwing/images/000010.png
ADDED
|
combined_data/lapwing/images/000011.png
ADDED
|
combined_data/lapwing/images/000012.png
ADDED
|
combined_data/lapwing/images/000013.png
ADDED
|
combined_data/lapwing/images/000014.png
ADDED
|
combined_data/lapwing/images/000015.png
ADDED
|
combined_data/lapwing/images/000016.png
ADDED
|
combined_data/lapwing/images/000017.png
ADDED
|
combined_data/lapwing/images/000018.png
ADDED
|
combined_data/lapwing/images/000019.png
ADDED
|
combined_data/lapwing/images/000020.png
ADDED
|
combined_data/lapwing/images/000021.png
ADDED
|
combined_data/lapwing/images/000022.png
ADDED
|
combined_data/lapwing/images/000023.png
ADDED
|
combined_data/lapwing/images/000024.png
ADDED
|
combined_data/lapwing/images/000025.png
ADDED
|
combined_data/lapwing/images/000026.png
ADDED
|
combined_data/lapwing/images/000027.png
ADDED
|
combined_data/lapwing/images/000028.png
ADDED
|
combined_data/lapwing/images/000029.png
ADDED
|
combined_data/lapwing/images/000030.png
ADDED
|
combined_data/lapwing/images/000031.png
ADDED
|
combined_data/lapwing/images/000032.png
ADDED
|
combined_data/lapwing/images/000033.png
ADDED
|
combined_data/lapwing/images/000034.png
ADDED
|
combined_data/lapwing/images/000035.png
ADDED
|
combined_data/lapwing/images/000036.png
ADDED
|
combined_data/lapwing/images/000037.png
ADDED
|
combined_data/lapwing/images/000038.png
ADDED
|
combined_data/lapwing/images/000039.png
ADDED
|
combined_data/lapwing/images/000040.png
ADDED
|
combined_data/lapwing/images/000041.png
ADDED
|
combined_data/lapwing/images/000042.png
ADDED
|
combined_data/lapwing/images/000043.png
ADDED
|
combined_data/lapwing/images/000044.png
ADDED
|
combined_data/lapwing/images/000045.png
ADDED
|
combined_data/lapwing/images/000046.png
ADDED
|
combined_data/lapwing/images/000047.png
ADDED
|
combined_data/lapwing/images/000048.png
ADDED
|