Update wdv3_timm.py
Browse files- wdv3_timm.py +10 -4
wdv3_timm.py
CHANGED
|
@@ -2,6 +2,7 @@ from dataclasses import dataclass
|
|
| 2 |
from pathlib import Path
|
| 3 |
from typing import Optional
|
| 4 |
|
|
|
|
| 5 |
import numpy as np
|
| 6 |
import pandas as pd
|
| 7 |
import timm
|
|
@@ -111,7 +112,8 @@ def get_tags(
|
|
| 111 |
|
| 112 |
@dataclass
|
| 113 |
class ScriptOptions:
|
| 114 |
-
|
|
|
|
| 115 |
model: str = field(default="vit")
|
| 116 |
gen_threshold: float = field(default=0.35)
|
| 117 |
char_threshold: float = field(default=0.75)
|
|
@@ -119,9 +121,13 @@ class ScriptOptions:
|
|
| 119 |
|
| 120 |
def main(opts: ScriptOptions):
|
| 121 |
repo_id = MODEL_REPO_MAP.get(opts.model)
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
print(f"Loading model '{opts.model}' from '{repo_id}'...")
|
| 127 |
model: nn.Module = timm.create_model("hf-hub:" + repo_id).eval()
|
|
|
|
| 2 |
from pathlib import Path
|
| 3 |
from typing import Optional
|
| 4 |
|
| 5 |
+
import os
|
| 6 |
import numpy as np
|
| 7 |
import pandas as pd
|
| 8 |
import timm
|
|
|
|
| 112 |
|
| 113 |
@dataclass
|
| 114 |
class ScriptOptions:
|
| 115 |
+
image_dir: Path = field(positional=True)
|
| 116 |
+
text_dir: Path = field(positional=True)
|
| 117 |
model: str = field(default="vit")
|
| 118 |
gen_threshold: float = field(default=0.35)
|
| 119 |
char_threshold: float = field(default=0.75)
|
|
|
|
| 121 |
|
| 122 |
def main(opts: ScriptOptions):
|
| 123 |
repo_id = MODEL_REPO_MAP.get(opts.model)
|
| 124 |
+
|
| 125 |
+
image_dir = Path(opts.image_dir).resolve()
|
| 126 |
+
for image_path in os.findall(image_dir):
|
| 127 |
+
for suffix in ['.jpeg','.jpg','.JPEG','.webp','.WEBP','.png','.PNG']:
|
| 128 |
+
if not image_path.find(suffix)>-1: continue
|
| 129 |
+
if not image_path.is_file(): raise FileNotFoundError(f"Image file not found: {image_path}")
|
| 130 |
+
|
| 131 |
|
| 132 |
print(f"Loading model '{opts.model}' from '{repo_id}'...")
|
| 133 |
model: nn.Module = timm.create_model("hf-hub:" + repo_id).eval()
|