MER_NN.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:EquationRecognition 作者: xyjiang94 项目源码 文件源码
def image_deformation(self,image):
        random_shear_angl = np.random.random() * np.pi/6 - np.pi/12
        random_rot_angl = np.random.random() * np.pi/6 - np.pi/12 - random_shear_angl
        random_x_scale = np.random.random() * .4 + .8
        random_y_scale = np.random.random() * .4 + .8
        random_x_trans = np.random.random() * image.shape[0] / 4 - image.shape[0] / 8
        random_y_trans = np.random.random() * image.shape[1] / 4 - image.shape[1] / 8
        dx = image.shape[0]/2. \
                - random_x_scale * image.shape[0]/2 * np.cos(random_rot_angl)\
                + random_y_scale * image.shape[1]/2 * np.sin(random_rot_angl + random_shear_angl)
        dy = image.shape[1]/2. \
                - random_x_scale * image.shape[0]/2 * np.sin(random_rot_angl)\
                - random_y_scale * image.shape[1]/2 * np.cos(random_rot_angl + random_shear_angl)
        trans_mat = AffineTransform(rotation=random_rot_angl,
                                    translation=(dx + random_x_trans,
                                                 dy + random_y_trans),
                                    shear = random_shear_angl,
                                    scale = (random_x_scale,random_y_scale))
        return warp(image,trans_mat.inverse,output_shape=image.shape)


    # def get_valid(self,size = 1000):
    #   data = self.mnist.train.next_batch(size)
    #   images = np.zeros((size,32,32))
    #   labels = data[1]
    #   for i in range(1000):
    #       images[i,:,:] = misc.imresize(np.reshape(data[0][i],(28,28)),(32,32))
    #   return images,labels
    # def shuffle(self):
    #   pass
    # def next_batch(self,batch_size):
    #   data = self.mnist.train.next_batch(batch_size)
    #   images = np.zeros((batch_size,32,32))
    #   labels = data[1]
    #   for i in range(batch_size):
    #       images[i,:,:] = misc.imresize(np.reshape(data[0][i],(28,28)),(32,32))
    #   return images,labels



    # def get_valid(self,size = 500):
    #   data = self.mnist.train.next_batch(size)
    #   images = np.zeros((size,32,32))
    #   labels = data[1]
    #   for i in range(500):
    #       images[i,:,:] = misc.imresize(np.reshape(data[0][i],(28,28)),(32,32))
    #   return images,labels
    # def shuffle(self):
    #   pass
    # def next_batch(self,batch_size):
    #   data = self.mnist.train.next_batch(batch_size)
    #   images = np.zeros((batch_size,32,32))
    #   labels = data[1]
    #   for i in range(batch_size):
    #       images[i,:,:] = misc.imresize(np.reshape(data[0][i],(28,28)),(32,32))
    #   return images,labels
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号