Comments (3)
I ended up writing it like this @ethanjyx, in case you are still interested. Been a year or so since I last looked at this, but I think this is what you want. Revisiting research code is always difficult 😄
def process_polygon(polygon, polygon_resolution=28, cropped_image_size=224, max_polygon_length=60):
"""
We superimpose a grid of size polygon_resolution*polygon_resolution over the cropped image.
We then one-hot-encode the polygon by creating a polygon_resolution*polygon_resolution array of ints,
where a 0 tells us that there is no vertex present, and a 1 tells us there is a vertex present.
We need the output to be of a fixed size, so we make sure that every output is of size
(max_polygon_length, polygon_resolution**2 + additional_info_if_needed).
"""
assert cropped_image_size % polygon_resolution == 0
grid_size = cropped_image_size // polygon_resolution
# we add two to the length, so we can slice for previous, and previous previous vertices, the first vertex is then
# stored in one_hot_polygon[2].
one_hot_polygon = torch.zeros((max_polygon_length + 2, polygon_resolution ** 2 + 1))
one_hot_ordering = np.zeros((max_polygon_length + 2), dtype=np.int)
# if `polygon` contains more vertices than max_polygon_length, then we subsample the polygon.
if len(polygon) > max_polygon_length:
scale = len(polygon) / max_polygon_length
subsample_selection = (np.arange(0, max_polygon_length) * scale).astype(np.int)
polygon = polygon[subsample_selection]
# Fill in the original polygon vertices.
for i in range(len(polygon)):
vertex = polygon[i]
x, y = vertex[0] // grid_size, vertex[1] // grid_size
vertex_index = np.ravel_multi_index((x, y), dims=(polygon_resolution, polygon_resolution))
one_hot_polygon[i + 2, vertex_index] = 1
one_hot_ordering[i + 2] = vertex_index
# set end-of-polygon bit
one_hot_polygon[i + 2, polygon_resolution ** 2] = 1
one_hot_ordering[i + 2] = polygon_resolution ** 2
# If the polygon is shorter than max_polygon_length, then we pad with the ground truth indices with -1
for i in range(len(polygon), max_polygon_length):
one_hot_ordering[i + 2] = -1
return one_hot_polygon, torch.as_tensor(one_hot_ordering[2:])
from pytorch-polygon-rnn.
- Sorry to reply so late, kind of busy in the last 2 years. The 3 more slots are for two starting vertices and one stop vertices.
- The filling vector process has two types:
a. the actual number of vertices is less than the fixed vector length: the vertices are repeated to avoid lots of zeros.
b. the actual number of vertices is larger than the fixed vector length: the vertices are proportionally selected to satisfy the fixed length.
from pytorch-polygon-rnn.
hi @qTipTip , i'm having the same question as you, hopefully @AlexMa011 can answer here.
Specifically, I have the following questions,
- for
label_array = np.zeros([self.length, 28 * 28 + 3])
, why do we need 28 * 28 + 3? what is the 3 slots for?
what is this kkk
doing in this block? https://github.com/AlexMa011/pytorch-polygon-rnn/blob/master/data.py#L45-L57
thanks in advance!
from pytorch-polygon-rnn.
Related Issues (13)
- Could you please share the datasets? HOT 4
- Visualizing the net-structure when training the net HOT 1
- Training is throwing error. HOT 4
- Images/performance metrics
- LICENSE HOT 2
- Which dataset in CitySpace are you refering to?
- Bad performance on CityScapes dataset. HOT 3
- Differences to Original Polygon RNN Paper HOT 2
- Cityscapes Results HOT 8
- Running Correction code HOT 3
- Training on cityscapes, acc always under 0.1 HOT 4
- Testing on CItyscapes, the channels are wrong HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytorch-polygon-rnn.