ductai199x
commited on
Upload 19 files
Browse files- .gitattributes +9 -0
- demo.ipynb +141 -0
- example_images/splicing-01-gt.png +0 -0
- example_images/splicing-01.png +3 -0
- example_images/splicing-02-gt.png +0 -0
- example_images/splicing-02.png +3 -0
- example_images/splicing-03-gt.png +0 -0
- example_images/splicing-03.png +3 -0
- example_images/splicing-04-gt.png +0 -0
- example_images/splicing-04.png +3 -0
- example_images/splicing-05-gt.png +0 -0
- example_images/splicing-05.png +3 -0
- example_images/splicing-06-gt.png +0 -0
- example_images/splicing-06.png +3 -0
- example_images/splicing-07-gt.png +0 -0
- example_images/splicing-07.png +3 -0
- example_images/splicing-08-gt.png +0 -0
- example_images/splicing-08.png +3 -0
- example_images/splicing-11-gt.png +0 -0
- example_images/splicing-11.png +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,12 @@ saved_model/**/* 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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_images/splicing-01.png filter=lfs diff=lfs merge=lfs -text
|
37 |
+
example_images/splicing-02.png filter=lfs diff=lfs merge=lfs -text
|
38 |
+
example_images/splicing-03.png filter=lfs diff=lfs merge=lfs -text
|
39 |
+
example_images/splicing-04.png filter=lfs diff=lfs merge=lfs -text
|
40 |
+
example_images/splicing-05.png filter=lfs diff=lfs merge=lfs -text
|
41 |
+
example_images/splicing-06.png filter=lfs diff=lfs merge=lfs -text
|
42 |
+
example_images/splicing-07.png filter=lfs diff=lfs merge=lfs -text
|
43 |
+
example_images/splicing-08.png filter=lfs diff=lfs merge=lfs -text
|
44 |
+
example_images/splicing-11.png filter=lfs diff=lfs merge=lfs -text
|
demo.ipynb
ADDED
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"import glob\n",
|
10 |
+
"import torch\n",
|
11 |
+
"import matplotlib.pyplot as plt\n",
|
12 |
+
"from PIL import Image\n",
|
13 |
+
"from transformers import AutoModel\n",
|
14 |
+
"from torchvision.transforms.functional import to_pil_image, pil_to_tensor\n",
|
15 |
+
"from torchmetrics.classification import BinaryF1Score, BinaryAveragePrecision\n",
|
16 |
+
"from tqdm.auto import tqdm"
|
17 |
+
]
|
18 |
+
},
|
19 |
+
{
|
20 |
+
"cell_type": "code",
|
21 |
+
"execution_count": null,
|
22 |
+
"metadata": {},
|
23 |
+
"outputs": [],
|
24 |
+
"source": [
|
25 |
+
"model = AutoModel.from_pretrained(\"ductai199x/forensic-similarity-graph\", trust_remote_code=True)"
|
26 |
+
]
|
27 |
+
},
|
28 |
+
{
|
29 |
+
"cell_type": "code",
|
30 |
+
"execution_count": null,
|
31 |
+
"metadata": {},
|
32 |
+
"outputs": [],
|
33 |
+
"source": [
|
34 |
+
"device = \"cuda\" if torch.cuda.is_available() else \"cpu\""
|
35 |
+
]
|
36 |
+
},
|
37 |
+
{
|
38 |
+
"cell_type": "code",
|
39 |
+
"execution_count": null,
|
40 |
+
"metadata": {},
|
41 |
+
"outputs": [],
|
42 |
+
"source": [
|
43 |
+
"model = model.eval().to(device)"
|
44 |
+
]
|
45 |
+
},
|
46 |
+
{
|
47 |
+
"cell_type": "code",
|
48 |
+
"execution_count": null,
|
49 |
+
"metadata": {},
|
50 |
+
"outputs": [],
|
51 |
+
"source": [
|
52 |
+
"image_paths = sorted(glob.glob(\"example_images/splicing-??.png\"))\n",
|
53 |
+
"gt_paths = sorted(glob.glob(\"example_images/splicing-??-gt.png\"))\n",
|
54 |
+
"image_vs_gt_paths = list(zip(image_paths, gt_paths))"
|
55 |
+
]
|
56 |
+
},
|
57 |
+
{
|
58 |
+
"cell_type": "code",
|
59 |
+
"execution_count": null,
|
60 |
+
"metadata": {},
|
61 |
+
"outputs": [],
|
62 |
+
"source": [
|
63 |
+
"with torch.no_grad():\n",
|
64 |
+
" imgs = []\n",
|
65 |
+
" gts = []\n",
|
66 |
+
" img_preds = []\n",
|
67 |
+
" loc_preds = []\n",
|
68 |
+
" f1, mAP = BinaryF1Score(), BinaryAveragePrecision()\n",
|
69 |
+
" for image_path, gt_path in tqdm(image_vs_gt_paths):\n",
|
70 |
+
" image = pil_to_tensor(Image.open(image_path).convert(\"RGB\")).float() / 255\n",
|
71 |
+
" gt = ((pil_to_tensor(Image.open(gt_path).convert(\"L\")).float() / 255) < 0.9).int()\n",
|
72 |
+
" img_pred, loc_pred = model(image.unsqueeze(0).to(device))\n",
|
73 |
+
" img_pred, loc_pred = img_pred[0].cpu(), loc_pred[0].cpu()\n",
|
74 |
+
" f1.update(loc_pred[None, ...], gt)\n",
|
75 |
+
" mAP.update(loc_pred[None, ...], gt)\n",
|
76 |
+
" img_preds.append(img_pred)\n",
|
77 |
+
" loc_preds.append(loc_pred)\n",
|
78 |
+
" imgs.append(image)\n",
|
79 |
+
" gts.append(gt)"
|
80 |
+
]
|
81 |
+
},
|
82 |
+
{
|
83 |
+
"cell_type": "code",
|
84 |
+
"execution_count": null,
|
85 |
+
"metadata": {},
|
86 |
+
"outputs": [],
|
87 |
+
"source": [
|
88 |
+
"f1.compute().item(), mAP.compute().item()"
|
89 |
+
]
|
90 |
+
},
|
91 |
+
{
|
92 |
+
"cell_type": "code",
|
93 |
+
"execution_count": null,
|
94 |
+
"metadata": {},
|
95 |
+
"outputs": [],
|
96 |
+
"source": [
|
97 |
+
"col = 4 * 2\n",
|
98 |
+
"row = -(-len(image_vs_gt_paths) // 4)\n",
|
99 |
+
"fig, axs = plt.subplots(row, col)\n",
|
100 |
+
"fig.set_size_inches(3 * col, 3 * row)\n",
|
101 |
+
"for i, (img, gt, img_pred, loc_pred) in enumerate(zip(imgs, gts, img_preds, loc_preds)):\n",
|
102 |
+
" ax = axs[i // 4][(i % 4) * 2]\n",
|
103 |
+
" ax.imshow(to_pil_image(img))\n",
|
104 |
+
" ax = axs[i // 4][(i % 4) * 2 + 1]\n",
|
105 |
+
" ax.imshow(to_pil_image(gt.float()))\n",
|
106 |
+
" ax.imshow(loc_pred, alpha=0.5, cmap=\"coolwarm\")\n",
|
107 |
+
"\n",
|
108 |
+
"for ax in axs.flat:\n",
|
109 |
+
" ax.axis(\"off\")"
|
110 |
+
]
|
111 |
+
},
|
112 |
+
{
|
113 |
+
"cell_type": "code",
|
114 |
+
"execution_count": null,
|
115 |
+
"metadata": {},
|
116 |
+
"outputs": [],
|
117 |
+
"source": []
|
118 |
+
}
|
119 |
+
],
|
120 |
+
"metadata": {
|
121 |
+
"kernelspec": {
|
122 |
+
"display_name": "pyt_tf2",
|
123 |
+
"language": "python",
|
124 |
+
"name": "python3"
|
125 |
+
},
|
126 |
+
"language_info": {
|
127 |
+
"codemirror_mode": {
|
128 |
+
"name": "ipython",
|
129 |
+
"version": 3
|
130 |
+
},
|
131 |
+
"file_extension": ".py",
|
132 |
+
"mimetype": "text/x-python",
|
133 |
+
"name": "python",
|
134 |
+
"nbconvert_exporter": "python",
|
135 |
+
"pygments_lexer": "ipython3",
|
136 |
+
"version": "3.9.18"
|
137 |
+
}
|
138 |
+
},
|
139 |
+
"nbformat": 4,
|
140 |
+
"nbformat_minor": 2
|
141 |
+
}
|
example_images/splicing-01-gt.png
ADDED
example_images/splicing-01.png
ADDED
Git LFS Details
|
example_images/splicing-02-gt.png
ADDED
example_images/splicing-02.png
ADDED
Git LFS Details
|
example_images/splicing-03-gt.png
ADDED
example_images/splicing-03.png
ADDED
Git LFS Details
|
example_images/splicing-04-gt.png
ADDED
example_images/splicing-04.png
ADDED
Git LFS Details
|
example_images/splicing-05-gt.png
ADDED
example_images/splicing-05.png
ADDED
Git LFS Details
|
example_images/splicing-06-gt.png
ADDED
example_images/splicing-06.png
ADDED
Git LFS Details
|
example_images/splicing-07-gt.png
ADDED
example_images/splicing-07.png
ADDED
Git LFS Details
|
example_images/splicing-08-gt.png
ADDED
example_images/splicing-08.png
ADDED
Git LFS Details
|
example_images/splicing-11-gt.png
ADDED
example_images/splicing-11.png
ADDED
Git LFS Details
|