-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdata_prepare.py
More file actions
66 lines (46 loc) · 1.26 KB
/
data_prepare.py
File metadata and controls
66 lines (46 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import cv2
import numpy as np
from os.path import isfile, join
from os import rename, listdir, rename, makedirs
import time
from PIL import Image
from imutils import paths
import os
seed = 42
np.random.seed(seed)
# datapath = './cmfd_forge/casia/'
datapath1 = './forge/coco/authentic/'
datapath2 = './forge/coco/tamper/'
datapath3 = './splicing/'
imagePaths1 = list(paths.list_images(datapath1))
imagePaths2 = list(paths.list_images(datapath2))
# print(len(imagePaths1))
# print(len(imagePaths2))
data = []
labels = []
for imagePath in imagePaths1[:5000]:
label = imagePath.split(os.path.sep)[-2]
# print(label)
image = cv2.imread(imagePath)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (224, 224))
data.append(image)
labels.append(label)
print("COCO authentic done ....")
for imagePath in imagePaths2[:5000]:
label = imagePath.split(os.path.sep)[-2]
# print(label)
image = cv2.imread(imagePath)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (224, 224))
data.append(image)
labels.append(label)
print("COCO tampering done ....")
data = np.array(data)
labels = np.array(labels)
# print(labels)
print(data.shape)
print(labels.shape)
np.save('x_new.npy', data)
np.save('y_new.npy', labels)
print("Done.....")