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

Simplify long objects generation process #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions parallelogram/parallelogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,21 @@ def make_object( x1, y1, max_dim=100 ):

def make_square( x1, y1, max_dim=100 ):
if max_dim<2: raise ValueError
lim = min( [max(x1,y1)+max_dim, 99] )
delta = random.randint( max(x1,y1)+1, lim )
lim = min( [max(x1,y1)+max_dim, 99-max(x1,y1)] )
delta = random.randint( 1, lim )
x2 = x1+delta
y2 = y1+delta
return ( x1, y1, x2, y2 )

def make_long( x1, y1, max_dim=100 ):
if max_dim<2: raise ValueError
# x1,y1 at the edge, impossible to fit long
if x1 == 98 and y1 == 98: raise ValueError
lim_x2 = min( [x1+max_dim,99] )
lim_y2 = min( [y1+max_dim,99] )
delta_x = random.randint( x1+1, lim_x2 )
delta_y = random.randint( y1+1, lim_y2 )
lim_x2 = min( [x1+max_dim,99-x1] )
lim_y2 = min( [y1+max_dim,99-y1] )
delta_x = random.randint( 1, lim_x2 )
delta_y = random.randint( 1, lim_y2 )
while delta_x == delta_y:
delta_x = random.randint( x1+1, lim_x2 )
delta_y = random.randint( y1+1, lim_y2 )
delta_x = random.randint( 1, lim_x2 )
delta_y = random.randint( 1, lim_y2 )
x2 = x1+delta_x
y2 = y1+delta_y
return ( x1, y1, x2, y2 )
Expand All @@ -92,17 +90,15 @@ def make_training_dataset( n ):

def make_production_dataset( n ):
data = []
for i in range(0,math.ceil(n/2)):
for i in range(0,math.ceil(n/2)): # half of the production dataset contains longs
x1 = random.randint( 0, 97 )
y1 = random.randint( 0, 97 )
try:
o = make_long( x1, y1, 72 )
except:
# x1,y1 at the edge,
# impossible to fit long
x1 = random.randint( 0, 90 )
y1 = random.randint( 0, 90 )
o = make_long( x1, y1 )
o = make_long( x1, y1, 72 )
data.append( o )
for i in range(0,math.ceil(n/2)):
x1 = random.randint( 0, 98 )
y1 = random.randint( 0, 98 )
o = make_square( x1, y1, 72 )
data.append( o )
for i in range(0,math.ceil(n/2)):
x1 = random.randint( 0, 98 )
Expand Down