예제 #1
0
 def merge(tbl):
     inp = scn.InputBatch(2, spatial_size)
     center = spatial_size.float().view(1, 2) / 2
     p = torch.LongTensor(2)
     v = torch.FloatTensor([1, 0, 0])
     for char in tbl['input']:
         inp.addSample()
         for stroke in char:
             stroke = stroke.float() * (Scale - 0.01) / 255 - 0.5 * (Scale -
                                                                     0.01)
             stroke += center.expand_as(stroke)
             ###############################################################
             # To avoid GIL problems use a helper function:
             scn.dim_fn(2, 'drawCurve')(inp.metadata.ffi, inp.features,
                                        stroke)
             ###############################################################
             # Above is equivalent to :
             # x1,x2,y1,y2,l=0,stroke[0][0],0,stroke[0][1],0
             # for i in range(1,stroke.size(0)):
             #     x1=x2
             #     y1=y2
             #     x2=stroke[i][0]
             #     y2=stroke[i][1]
             #     l=1e-10+((x2-x1)**2+(y2-y1)**2)**0.5
             #     v[1]=(x2-x1)/l
             #     v[2]=(y2-y1)/l
             #     l=max(x2-x1,y2-y1,x1-x2,y1-y2,0.9)
             #     for j in numpy.arange(0,1,1/l):
             #         p[0]=math.floor(x1*j+x2*(1-j))
             #         p[1]=math.floor(y1*j+y2*(1-j))
             #         inp.setLocation(p,v,False)
             ###############################################################
     inp.precomputeMetadata(precomputeStride)
     return {'input': inp, 'target': torch.LongTensor(tbl['target'])}
예제 #2
0
 def merge(tbl):
     inp = scn.InputBatch(2, spatial_size)
     center = spatial_size.float().view(1, 2) / 2
     p = torch.LongTensor(2)
     v = torch.FloatTensor([1, 0, 0])
     for char in tbl['input']:
         inp.addSample()
         m = torch.eye(2)
         r = random.randint(1, 3)
         alpha = random.uniform(-0.2, 0.2)
         if alpha == 1:
             m[0][1] = alpha
         elif alpha == 2:
             m[1][0] = alpha
         else:
             m = torch.mm(m, torch.FloatTensor(
                 [[math.cos(alpha), math.sin(alpha)],
                  [-math.sin(alpha), math.cos(alpha)]]))
         c = center + torch.FloatTensor(1, 2).uniform_(-8, 8)
         for stroke in char:
             stroke = stroke.float() / 255 - 0.5
             stroke = c.expand_as(stroke) + \
                 torch.mm(stroke, m * (Scale - 0.01))
             ###############################################################
             # To avoid GIL problems use a helper function:
             scn.dim_fn(
                 2,
                 'drawCurve')(
                 inp.metadata.ffi,
                 inp.features,
                 stroke)
             ###############################################################
             # Above is equivalent to :
             # x1,x2,y1,y2,l=0,stroke[0][0],0,stroke[0][1],0
             # for i in range(1,stroke.size(0)):
             #     x1=x2
             #     y1=y2
             #     x2=stroke[i][0]
             #     y2=stroke[i][1]
             #     l=1e-10+((x2-x1)**2+(y2-y1)**2)**0.5
             #     v[1]=(x2-x1)/l
             #     v[2]=(y2-y1)/l
             #     l=max(x2-x1,y2-y1,x1-x2,y1-y2,0.9)
             #     for j in numpy.arange(0,1,1/l):
             #         p[0]=math.floor(x1*j+x2*(1-j))
             #         p[1]=math.floor(y1*j+y2*(1-j))
             #         inp.setLocation(p,v,False)
             ###############################################################
     inp.precomputeMetadata(precomputeStride)
     return {'input': inp, 'target': torch.LongTensor(tbl['target']) - 1}
예제 #3
0
파일: data.py 프로젝트: gaobb/SparseConvNet
 def merge(tbl):
     inp = scn.InputBatch(2, spatial_size)
     center = spatial_size.float().view(1, 2) / 2
     p = torch.LongTensor(2)
     v = torch.FloatTensor([1, 0, 0])
     for char in tbl['input']:
         inp.addSample()
         m = torch.eye(2)
         r = random.randint(1, 3)
         alpha = random.uniform(-0.2, 0.2)
         if alpha == 1:
             m[0][1] = alpha
         elif alpha == 2:
             m[1][0] = alpha
         else:
             m = torch.mm(m, torch.FloatTensor(
                 [[math.cos(alpha), math.sin(alpha)],
                  [-math.sin(alpha), math.cos(alpha)]]))
         c = center + torch.FloatTensor(1, 2).uniform_(-8, 8)
         for stroke in char:
             stroke = stroke.float() / 255 - 0.5
             stroke = c.expand_as(stroke) + \
                 torch.mm(stroke, m * (Scale - 0.01))
             ###############################################################
             # To avoid GIL problems use a helper function:
             scn.dim_fn(
                 2,
                 'drawCurve')(
                 inp.metadata.ffi,
                 inp.features,
                 stroke)
             ###############################################################
             # Above is equivalent to :
             # x1,x2,y1,y2,l=0,stroke[0][0],0,stroke[0][1],0
             # for i in range(1,stroke.size(0)):
             #     x1=x2
             #     y1=y2
             #     x2=stroke[i][0]
             #     y2=stroke[i][1]
             #     l=1e-10+((x2-x1)**2+(y2-y1)**2)**0.5
             #     v[1]=(x2-x1)/l
             #     v[2]=(y2-y1)/l
             #     l=max(x2-x1,y2-y1,x1-x2,y1-y2,0.9)
             #     for j in numpy.arange(0,1,1/l):
             #         p[0]=math.floor(x1*j+x2*(1-j))
             #         p[1]=math.floor(y1*j+y2*(1-j))
             #         inp.setLocation(p,v,False)
             ###############################################################
     inp.precomputeMetadata(precomputeStride)
     return {'input': inp, 'target': torch.LongTensor(tbl['target']) - 1}
예제 #4
0
 def merge(tbl):
     inp = scn.InputBatch(2, spatial_size)
     center = spatial_size.float().view(1, 2) / 2
     p = torch.LongTensor(2)
     v = torch.FloatTensor([1, 0, 0])
     for char in tbl['input']:
         inp.addSample()
         for stroke in char:
             stroke = stroke.float() * (Scale - 0.01) / 255 - 0.5 * (Scale -
                                                                     0.01)
             stroke += center.expand_as(stroke)
             scn.dim_fn(2, 'drawCurve')(inp.metadata.ffi, inp.features,
                                        stroke)
     inp.precomputeMetadata(precomputeStride)
     return {'input': inp, 'target': torch.LongTensor(tbl['target'])}
예제 #5
0
파일: data.py 프로젝트: gaobb/SparseConvNet
 def merge(tbl):
     inp = scn.InputBatch(2, spatial_size)
     center = spatial_size.float().view(1, 2) / 2
     p = torch.LongTensor(2)
     v = torch.FloatTensor([1, 0, 0])
     for char in tbl['input']:
         inp.addSample()
         for stroke in char:
             stroke = stroke.float() * (Scale - 0.01) / 255 - 0.5 * (Scale - 0.01)
             stroke += center.expand_as(stroke)
             scn.dim_fn(
                 2,
                 'drawCurve')(
                 inp.metadata.ffi,
                 inp.features,
                 stroke)
     inp.precomputeMetadata(precomputeStride)
     return {'input': inp, 'target': torch.LongTensor(tbl['target']) - 1}