Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In dataset.py crop_img function sometimes returning negative vertices #65

Open
Ashish0091 opened this issue Apr 28, 2023 · 0 comments
Open

Comments

@Ashish0091
Copy link

Ashish0091 commented Apr 28, 2023

In the below code, I tried to print the output of crop_img function which does random cropping augmentation on input image. I tried to print the vertices variables and got negative vertices. My question is:

  1. What is the use of negative vertices. How these negative vertices are useful during training
  2. If this function is cropping non text region also does the model learns from background also

`def crop_img(img, vertices, labels, length):
'''crop img patches to obtain batch and augment
Input:
img : PIL Image
vertices : vertices of text regions <numpy.ndarray, (n,8)>
labels : 1->valid, 0->ignore, <numpy.ndarray, (n,)>
length : length of cropped image region
Output:
region : cropped image region
new_vertices: new vertices in cropped region
'''
h, w = img.height, img.width
# confirm the shortest side of image >= length
if h >= w and w < length:
img = img.resize((length, int(h * length / w)), Image.BILINEAR)
elif h < w and h < length:
img = img.resize((int(w * length / h), length), Image.BILINEAR)
ratio_w = img.width / w
ratio_h = img.height / h
assert(ratio_w >= 1 and ratio_h >= 1)

new_vertices = np.zeros(vertices.shape)
if vertices.size > 0:
	new_vertices[:,[0,2,4,6]] = vertices[:,[0,2,4,6]] * ratio_w
	new_vertices[:,[1,3,5,7]] = vertices[:,[1,3,5,7]] * ratio_h

# find random position
remain_h = img.height - length
remain_w = img.width - length
flag = True
cnt = 0
while flag and cnt < 1000:
	cnt += 1
	start_w = int(np.random.rand() * remain_w)
	start_h = int(np.random.rand() * remain_h)
	flag = is_cross_text([start_w, start_h], length, new_vertices[labels==1,:])
box = (start_w, start_h, start_w + length, start_h + length)
region = img.crop(box)
if new_vertices.size == 0:
	return region, new_vertices	

new_vertices[:,[0,2,4,6]] -= start_w
new_vertices[:,[1,3,5,7]] -= start_h
return region, new_vertices

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant