Exemplo n.º 1
0
 def sample():
     while True:
         p = AbsolutePoint.sample()
         r = 1 if NIPSPRIMITIVES() else sampleRadius()
         c = Circle(p, r)
         if c.inbounds():
             return c
Exemplo n.º 2
0
def randomLineOfCode():
    k = choice(range(5))
    if k == 0: return None
    if k == 1: return Circle.sample()
    if k == 2: return Line.sample()
    if k == 3: return Rectangle.sample()
    if NIPSPRIMITIVES(): return randomLineOfCode()
    if k == 4: return Label.sample()
    assert False
Exemplo n.º 3
0
    def sample():
        while True:
            c = AbsolutePoint.sample()
            r = 1 if NIPSPRIMITIVES() else sampleRadius()
            # r = choice(range(5)) + 1 if SNAPTOGRID else (1 + random()*5)
            ang = 120 * random()

            tri = Triangle(c, r, ang)
            if tri.onplane():
                return tri
Exemplo n.º 4
0
 def mutate(self):
     if self.radius < 3 and random() < 0.15:
         return Rectangle.absolute(self.center.x - self.radius,
                                   self.center.y - self.radius,
                                   self.center.x + self.radius,
                                   self.center.y + self.radius)
     while True:
         if random() < 0.5 or NIPSPRIMITIVES():
             c = Circle(self.center.mutate(), self.radius)
         else:
             if self.radius < 2: r = self.radius + 1
             else: r = self.radius + randomRadiusPerturbation()
             c = Circle(self.center, r)
         if c.inbounds():
             return c
Exemplo n.º 5
0
    def sampler():
        while True:
            n = choice(range(maximumNumberOfObjects)) + 1
            if NIPSPRIMITIVES():
                shapeIdentities = [choice(range(3)) for _ in range(n)]
            else:
                shapeIdentities = [choice(range(4)) for _ in range(n)]
                numberOfLabels = len([i for i in shapeIdentities if i == 3])
                # make it so that there are not too many labels
                if numberOfLabels > n / 2: continue

            return multipleObjects(
                rectangles=len([x for x in shapeIdentities if x == 0]),
                lines=len([x for x in shapeIdentities if x == 1]),
                circles=len([x for x in shapeIdentities if x == 2]),
                labels=len([x for x in shapeIdentities if x == 3]))()
Exemplo n.º 6
0
 def mutate(self):
     dx = self.p2.x - self.p1.x
     dy = self.p2.y - self.p1.y
     if dx == dy and dx < 8 and dx % 2 == 0 and random() < 0.5 and (
             dx == 2 or (not NIPSPRIMITIVES())):
         return Circle(
             AbsolutePoint(self.p1.x + dx / 2, self.p1.y + dy / 2), dx / 2)
     while True:
         p1 = self.p1
         p2 = self.p2
         if random() > 0.5:
             p1 = p1.mutate()
         else:
             p2 = p2.mutate()
         if p1.x < p2.x and p1.y < p2.y:
             return Triangle(p1, p2)
Exemplo n.º 7
0
def sampleRadius():
    if NIPSPRIMITIVES(): return 1
    return choice(range(5)) + 1 if SNAPTOGRID else (1 + random() * 5)
Exemplo n.º 8
0
    (n, startingPoint, k) = arguments
    # IMPORTANT!
    # You *do not* want directories with an enormous number of files in them
    # pack it all up into a directory that we will tar together later

    os.system('mkdir %s/%d' % (outputName, startingPoint))
    makeSyntheticData("%s/%d/%s" % (outputName, startingPoint, n),
                      generators[n],
                      k=k,
                      offset=startingPoint)
    print "Generated %d training sequences into %s/%d" % (k, outputName,
                                                          startingPoint)


if __name__ == '__main__':
    if not NIPSPRIMITIVES():
        loadCharacters()

    if 'continuous' in sys.argv:
        setSnapToGrid(False)
        outputName = 'syntheticContinuousTrainingData'
    else:
        # models imperfect grid alignment
        setCoordinateNoise(0.2)
        setRadiusNoise(0.1)
        outputName = 'syntheticTrainingData'

    if len(sys.argv) > 1:
        totalNumberOfExamples = int(sys.argv[1])
    else:
        totalNumberOfExamples = 100000