mlModule/Predictor.py
def parse_features(self,stoke_data):
            """Parse provided stroke data and ink (as np array) and classname."""
            inkarray = json.loads(stoke_data)
            stroke_lengths = [len(stroke[0]) for stroke in inkarray]
            total_points = sum(stroke_lengths)
            np_ink = np.zeros((total_points, 3), dtype=np.float32)
            current_t = 0
            for stroke in inkarray:
                if len(stroke[0]) != len(stroke[1]):
                    print("Inconsistent number of x and y coordinates.")
                    return None
                for i in [0, 1]:
                    np_ink[current_t:(current_t + len(stroke[0])), i] = stroke[i]
                current_t += len(stroke[0])
                np_ink[current_t - 1, 2] = 1  # stroke_end
        # Preprocessing.
        # 1. Size normalization.
            lower = np.min(np_ink[:, 0:2], axis=0)
            upper = np.max(np_ink[:, 0:2], axis=0)
            scale = upper - lower
            scale[scale == 0] = 1
            np_ink[:, 0:2] = (np_ink[:, 0:2] - lower) / scale
            
            np_ink[1:, 0:2] -= np_ink[0:-1, 0:2]
#            print(np_ink)
            np_ink = np_ink[1:, :]
#            return ([np_ink.flatten().tolist(),np_ink.flatten().tolist()],[np_ink.shape[0],np_ink.shape[0]])
            np_ink_flatten = np_ink.flatten()
            
#            self.shapeConstant = tf.constant([list(np_ink.shape),list(np_ink.shape)])
            return ([list(np_ink.shape),list(np_ink.shape)],[np_ink_flatten.tolist(),np_ink_flatten.tolist()])
Parse provided stroke data and ink (as np array) and classname.
Parse provided stroke data and ink (as np array) and classname.
Parse provided stroke data and ink ( as np array ) and classname .
def parse_features(self,stoke_data):
            inkarray = json.loads(stoke_data)
            stroke_lengths = [len(stroke[0]) for stroke in inkarray]
            total_points = sum(stroke_lengths)
            np_ink = np.zeros((total_points, 3), dtype=np.float32)
            current_t = 0
            for stroke in inkarray:
                if len(stroke[0]) != len(stroke[1]):
                    print("Inconsistent number of x and y coordinates.")
                    return None
                for i in [0, 1]:
                    np_ink[current_t:(current_t + len(stroke[0])), i] = stroke[i]
                current_t += len(stroke[0])
                np_ink[current_t - 1, 2] = 1  
            lower = np.min(np_ink[:, 0:2], axis=0)
            upper = np.max(np_ink[:, 0:2], axis=0)
            scale = upper - lower
            scale[scale == 0] = 1
            np_ink[:, 0:2] = (np_ink[:, 0:2] - lower) / scale
            np_ink[1:, 0:2] -= np_ink[0:-1, 0:2]
            np_ink = np_ink[1:, :]
            np_ink_flatten = np_ink.flatten()
            return ([list(np_ink.shape),list(np_ink.shape)],[np_ink_flatten.tolist(),np_ink_flatten.tolist()])
def parse_features ( self , stoke_data ) : inkarray = json . loads ( stoke_data ) stroke_lengths = [ len ( stroke [ 0 ] ) for stroke in inkarray ] total_points = sum ( stroke_lengths ) np_ink = np . zeros ( ( total_points , 3 ) , dtype = np . float32 ) current_t = 0 for stroke in inkarray : if len ( stroke [ 0 ] ) != len ( stroke [ 1 ] ) : print ( "Inconsistent number of x and y coordinates." ) return None for i in [ 0 , 1 ] : np_ink [ current_t : ( current_t + len ( stroke [ 0 ] ) ) , i ] = stroke [ i ] current_t += len ( stroke [ 0 ] ) np_ink [ current_t - 1 , 2 ] = 1 lower = np . min ( np_ink [ : , 0 : 2 ] , axis = 0 ) upper = np . max ( np_ink [ : , 0 : 2 ] , axis = 0 ) scale = upper - lower scale [ scale == 0 ] = 1 np_ink [ : , 0 : 2 ] = ( np_ink [ : , 0 : 2 ] - lower ) / scale np_ink [ 1 : , 0 : 2 ] -= np_ink [ 0 : - 1 , 0 : 2 ] np_ink = np_ink [ 1 : , : ] np_ink_flatten = np_ink . flatten ( ) return ( [ list ( np_ink . shape ) , list ( np_ink . shape ) ] , [ np_ink_flatten . tolist ( ) , np_ink_flatten . tolist ( ) ] )
Parse provided stroke data and ink (as np array) and classname.
Parse provided stroke data and ink ( as np array ) and classname .
"""Parse provided stroke data and ink (as np array) and classname.""" # stroke_end # Preprocessing. # 1. Size normalization. #            print(np_ink) #            return ([np_ink.flatten().tolist(),np_ink.flatten().tolist()],[np_ink.shape[0],np_ink.shape[0]]) #            self.shapeConstant = tf.constant([list(np_ink.shape),list(np_ink.shape)])
self
stoke_data