from math import ceil
image_size = 720
print("Input size: ", image_size)
layers = [(3, 1, 'same'), (2, 2, 'valid'), (3, 1, 'same'), (2, 2, 'valid'), (10, 1, 'valid'), (1, 1, 'valid')]
trans = []
for k, s, p in layers:
if p == 'valid':
image_out = ceil((image_size - (k - 1))/s)
scale = ((image_size - k + 1)/image_out)
top, bottom = (k-1)//2, k//2
else:
image_out = ceil(image_size/s)
scale = (image_size/image_out)
top = bottom = 0
image_size = image_out
trans.append((scale, top, bottom))
print("Output size:", image_size)
print("Transformations: ", trans)
for s, t, b in reversed(trans):
image_size = image_size*s + t + b
print("Input size recovered", int(image_size))
point = [1, 1]
print("Point on heatmap: ", point)
for s, t, b in reversed(trans):
point[0] = point[0]*s + t
point[1] = point[1]*s + t
point[0] = int(point[0])
point[1] = int(point[1])
print("Point on original image: ", point)
Given an image dimension and the convolutional/pooling layers, the script computes the scales and padding for each convolutional/pooling layer. Then, given a point in the output image, it recovers the corresponding position in the original image.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.