-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcount_addr_crop.py
More file actions
executable file
·49 lines (43 loc) · 1.69 KB
/
count_addr_crop.py
File metadata and controls
executable file
·49 lines (43 loc) · 1.69 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
from cv2 import imread
import numpy as np
from os.path import join
from os import listdir
from sys import argv
annotation_dir = "../FCN_OCR_address_dataset/annotations"
files = listdir(annotation_dir)
validation_image = files[int(len(files) * 0.8):]
training_image = files[:int(len(files) * 0.8)]
num_training_crops = 0
num_validation_crops = 0
CROP_SIZE = 32
STRIDE = int(argv[1])
for img_name in validation_image:
img = imread(join('../FCN_OCR_address_dataset/annotations', img_name))
print("Processing", img_name)
# num_validation_crops += (img.shape[0] - CROP_SIZE + 1) * (img.shape[1] - CROP_SIZE + 1)
i = 0
while i + (CROP_SIZE - 1) <= img.shape[0] - 1:
j = 0
while j + (CROP_SIZE - 1) <= img.shape[1] - 1:
num_validation_crops += 1
j += STRIDE
i += STRIDE
for img_name in training_image:
img = imread(join('../FCN_OCR_address_dataset/annotations', img_name))
print("Processing", img_name)
# num_training_crops += (img.shape[0] - CROP_SIZE + 1) * (img.shape[1] - CROP_SIZE + 1)
i = 0
while i + (CROP_SIZE - 1) <= img.shape[0] - 1:
j = 0
while j + (CROP_SIZE - 1) <= img.shape[1] - 1:
num_training_crops += 1
j += STRIDE
i += STRIDE
print("No. of training images:", num_training_crops)
print("Training size:", num_training_crops * 2497.0 / 1024.0 / 1024.0 / 1024.0)
print()
print("No. of validation images:", num_validation_crops)
print("Validation size:", num_validation_crops * 2497.0 / 1024.0 / 1024.0 / 1024.0)
print()
print("Total:", num_training_crops + num_validation_crops)
print("Total size:", (num_training_crops + num_validation_crops) * 2497.0 / 1024.0 / 1024.0 / 1024.0)