ductai199x commited on
Commit
1fcbc45
·
verified ·
1 Parent(s): 97c540b

Upload 19 files

Browse files
.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

  • SHA256: f3a56a15c47b711b4b72ffd8ab1f92bb4bffa493dfd79b83616632c15957f0ff
  • Pointer size: 132 Bytes
  • Size of remote file: 3 MB
example_images/splicing-02-gt.png ADDED
example_images/splicing-02.png ADDED

Git LFS Details

  • SHA256: 08545d70a8a702959e2d7f720ed2125ed22b813eb1db7e44f77c30b2f732bcfc
  • Pointer size: 132 Bytes
  • Size of remote file: 2.71 MB
example_images/splicing-03-gt.png ADDED
example_images/splicing-03.png ADDED

Git LFS Details

  • SHA256: 873b47cf883ac423405c4bbf20a51687ef706ee294f85af49de029d31318b88b
  • Pointer size: 132 Bytes
  • Size of remote file: 2.48 MB
example_images/splicing-04-gt.png ADDED
example_images/splicing-04.png ADDED

Git LFS Details

  • SHA256: ecf122407617db82b12a73f6b86612e071fb92e0f95b8bbf4ea82d74293db463
  • Pointer size: 132 Bytes
  • Size of remote file: 2.99 MB
example_images/splicing-05-gt.png ADDED
example_images/splicing-05.png ADDED

Git LFS Details

  • SHA256: 4eb7faaff9923af7cf144863099a0d8645812df7197160d8da3fe0bf7952e333
  • Pointer size: 132 Bytes
  • Size of remote file: 4.44 MB
example_images/splicing-06-gt.png ADDED
example_images/splicing-06.png ADDED

Git LFS Details

  • SHA256: c29fdbf784856ec7a6ca11495652bf95737c803834e1a08e26057dfb67368129
  • Pointer size: 132 Bytes
  • Size of remote file: 4.05 MB
example_images/splicing-07-gt.png ADDED
example_images/splicing-07.png ADDED

Git LFS Details

  • SHA256: bb8d5db3e45dde5df0ea1e523653dac39feab7c44c8b784399811e23ed0b415e
  • Pointer size: 132 Bytes
  • Size of remote file: 4.53 MB
example_images/splicing-08-gt.png ADDED
example_images/splicing-08.png ADDED

Git LFS Details

  • SHA256: f878d668c74a5f8724b72f6d766489d821f9379ec582f23c428f24e2db7a1ec0
  • Pointer size: 132 Bytes
  • Size of remote file: 4.79 MB
example_images/splicing-11-gt.png ADDED
example_images/splicing-11.png ADDED

Git LFS Details

  • SHA256: 35ce213e09c55f8ffd99fe3d403538c94f3849fccf065b36279291b020cbed2b
  • Pointer size: 132 Bytes
  • Size of remote file: 2.61 MB