easy_vision.python.inference¶
easy_vision.python.inference.predictor¶
-
class
easy_vision.python.inference.predictor.
Classifier
(model_path, profiling_file=None, verbose_result=False)[source]¶ Bases:
easy_vision.python.inference.predictor.Predictor
-
__init__
(model_path, profiling_file=None, verbose_result=False)[source]¶ Parameters: - model_path – saved model path or frozenpb path
- profiling_file – profiling result file, default None. if not None, predict function will use Timeline to profiling prediction time, and the result json will be saved to profiling_file
- verbose_result – if True, will output more result info for predictor_eval
-
classmethod
create_class
(name)¶
-
predict
(**kwargs)¶
-
-
class
easy_vision.python.inference.predictor.
Detector
(model_path, profiling_file=None)[source]¶ Bases:
easy_vision.python.inference.predictor.Predictor
-
__init__
(model_path, profiling_file=None)[source]¶ Parameters: model_path – saved model path or frozenpb path
-
classmethod
create_class
(name)¶
-
predict
(**kwargs)¶
-
-
class
easy_vision.python.inference.predictor.
FeatureExtractor
(model_path, output_feature, profiling_file=None)[source]¶ Bases:
easy_vision.python.inference.predictor.Predictor
-
__init__
(model_path, output_feature, profiling_file=None)[source]¶ Parameters: - model_path – saved model path or frozenpb path
- output_feature – output node name
-
classmethod
create_class
(name)¶
-
predict
(**kwargs)¶
-
-
class
easy_vision.python.inference.predictor.
MultiLabelClassifier
(model_path, profiling_file=None, verbose_result=False)[source]¶ Bases:
easy_vision.python.inference.predictor.Predictor
-
__init__
(model_path, profiling_file=None, verbose_result=False)[source]¶ Parameters: - model_path – saved model path or frozenpb path
- profiling_file – profiling result file, default None. if not None, predict function will use Timeline to profiling prediction time, and the result json will be saved to profiling_file
- verbose_result – if True, will output more result info for predictor_eval
-
classmethod
create_class
(name)¶
-
predict
(**kwargs)¶
-
-
class
easy_vision.python.inference.predictor.
Predictor
(model_path, profiling_file=None, decode=True)[source]¶ Bases:
easy_vision.python.inference.predictor.PredictorInterface
-
__init__
(model_path, profiling_file=None, decode=True)[source]¶ Parameters: - model_path – saved_model directory or frozenpb file path
- profiling_file – profiling result file, default None. if not None, predict function will use Timeline to profiling prediction time, and the result json will be saved to profiling_file
-
batch
(images)[source]¶ Pack a list of rgb order images to batch
Parameters: images – a list of numpy array Returns: image for image data true_image_shape for image shapes Return type: a dict of input feed dict, containing keys
-
classmethod
create_class
(name)¶
-
get_input_names
¶ a list, which conaining the name of input nodes available in model
Type: Return
-
get_output_names
()[source]¶ Returns: a list, which conaining the name of outputs nodes available in model
-
predict
(data_list, output_names=None, batch_size=1)[source]¶ Parameters: - data_list – list of numpy array with type uint8
- output_names – if not None, will fetch certain outputs, if set None, will
- batch_size – batch_size used to predict, -1 indicates to use the real batch_size
Returns: a list of dict, each dict contain a key-value pair for output_name, output_value
-
-
class
easy_vision.python.inference.predictor.
PredictorImpl
(model_path, profiling_file=None, decode=True)[source]¶ Bases:
object
-
__init__
(model_path, profiling_file=None, decode=True)[source]¶ Impl class for predictor
Parameters: - model_path – saved_model directory or frozenpb file path
- profiling_file – profiling result file, default None. if not None, predict function will use Timeline to profiling prediction time, and the result json will be saved to profiling_file
-
predict
(input_data_dict, output_names=None)[source]¶ Parameters: - input_data_dict – a dict containing all input data, key is the input name, value is the corresponding value
- output_names – if not None, will fetch certain outputs, if set None, will return all the output info according to the output info in model signature
Returns: a dict of outputs, key is the output name, value is the corresponding value
-
-
class
easy_vision.python.inference.predictor.
PredictorInterface
(model_path, model_config=None)[source]¶ Bases:
object
-
__init__
(model_path, model_config=None)[source]¶ init tensorflow session and load tf model
Parameters: - model_path – init model from this directory
- model_config – config string for model to init, in json format
-
classmethod
create_class
(name)¶
-
get_output_type
()[source]¶ in this function user should return a type dict, which indicates which type of data should the output of predictor be converted to * type json, data will be serialized to json str
- type image, data will be converted to encode image binary and write to oss file, whose name is output_dir/${key}/${input_filename}_${idx}.jpg, where input_filename is extracted from url, key corresponds to the key in the dict of output_type, if the type of data indexed by key is a list, idx is the index of element in list, otherwhile ${idx} will be empty
- type video, data will be converted to encode video binary and write to oss file,
- eg: return {
- ‘image’: ‘image’, ‘feature’: ‘json’
} indicating that the image data in the output dict will be save to image file and feature in output dict will be converted to json
-
predict
(input_data, batch_size)[source]¶ using session run predict a number of samples using batch_size
Parameters: - input_data – a list of numpy array, each array is a sample to be predicted
- batch_size – batch_size passed by the caller, you can also ignore this param and use a fixed number if you do not want to adjust batch_size in runtime
Returns: - a list of dict, each dict is the prediction result of one sample
eg, {“output1”: value1, “output2”: value2}, the value type can be python int str float, and numpy array
Return type: result
-
version
= 1¶
-
-
class
easy_vision.python.inference.predictor.
PredictorInterfaceV2
(model_path, model_config=None)[source]¶ Bases:
easy_vision.python.inference.predictor.PredictorInterface
-
__init__
(model_path, model_config=None)[source]¶ init tensorflow session and load tf model
Parameters: - model_path – init model from this directory
- model_config – config string for model to init, in json format
-
classmethod
create_class
(name)¶
-
get_output_type
()[source]¶ in this function user should return a type dict, which indicates which type of data should the output of predictor be converted to * type json, data will be serialized to json str
- type image, data will be converted to encode image binary and write to oss file, whose name is output_dir/${key}/${input_filename}_${idx}.jpg, where input_filename is the base filename extracted from url, key corresponds to the key in the dict of output_type, if the type of data indexed by key is a list, idx is the index of element in list, otherwhile ${idx} will be empty
- type video, data will be converted to encode video binary and write to oss file,
- eg: return {
- ‘image’: ‘image’, ‘feature’: ‘json’
} indicating that the image data in the output dict will be save to image file and feature in output dict will be converted to json
-
predict
(input_data_dict_list, batch_size)[source]¶ using session run predict a number of samples using batch_size
Parameters: - input_data_dict_list – a list of dict, each dict is a sample data to be predicted
- batch_size – batch_size passed by the caller, you can also ignore this param and use a fixed number if you do not want to adjust batch_size in runtime
Returns: - a list of dict, each dict is the prediction result of one sample
eg, {“output1”: value1, “output2”: value2}, the value type can be python int str float, and numpy array
Return type: result
-
version
= 2¶
-
-
class
easy_vision.python.inference.predictor.
PredictorV2
(model_path, profiling_file=None, decode=True)[source]¶ Bases:
easy_vision.python.inference.predictor.PredictorInterfaceV2
-
__init__
(model_path, profiling_file=None, decode=True)[source]¶ Parameters: - model_path – saved_model directory or frozenpb file path
- profiling_file – profiling result file, default None. if not None, predict function will use Timeline to profiling prediction time, and the result json will be saved to profiling_file
-
batch
(batch_data_dict_list)[source]¶ Pack a list of data to batch, here implements batch for images
Parameters: batch_data_dict_list – a list of a dict of data Returns: input feed dict for tensorflow
-
classmethod
create_class
(name)¶
-
get_input_names
()[source]¶ - Return
- a list: which conaining the name of input nodes available in model
-
get_output_names
()[source]¶ - Return
- a list: which conaining the name of outputs nodes available in model
-
predict
(input_data_dict_list, output_names=None, batch_size=1)[source]¶ Parameters: - input_data_dict_list – list of dict
- output_names – if not None, will fetch certain outputs, if set None, will
- batch_size – batch_size used to predict, -1 indicates to use the real batch_size
Returns: a list of dict, each dict contain a key-value pair for output_name, output_value
-
-
class
easy_vision.python.inference.predictor.
Segmentor
(model_path, profiling_file=None)[source]¶ Bases:
easy_vision.python.inference.predictor.Predictor
-
__init__
(model_path, profiling_file=None)[source]¶ Parameters: - model_path – saved_model directory or frozenpb file path
- profiling_file – profiling result file, default None. if not None, predict function will use Timeline to profiling prediction time, and the result json will be saved to profiling_file
-
classmethod
create_class
(name)¶
-
get_output_type
()[source]¶ in this function user should return a type dict, which indicates which type of data should the output of predictor be converted to * type json, data will be serialized to json str
- type image, data will be converted to encode image binary and write to oss file, whose name is output_dir/${key}/${input_filename}_${idx}.jpg, where input_filename is extracted from url, key corresponds to the key in the dict of output_type, if the type of data indexed by key is a list, idx is the index of element in list, otherwhile ${idx} will be empty
- type video, data will be converted to encode video binary and write to oss file,
- eg: return {
- ‘image’: ‘image’, ‘feature’: ‘json’
} indicating that the image data in the output dict will be save to image file and feature in output dict will be converted to json
-
predict
(**kwargs)¶
-
-
class
easy_vision.python.inference.predictor.
TextDetector
(model_path, profiling_file=None)[source]¶ Bases:
easy_vision.python.inference.predictor.Predictor
-
__init__
(model_path, profiling_file=None)[source]¶ Parameters: - model_path – saved_model directory or frozenpb file path
- profiling_file – profiling result file, default None. if not None, predict function will use Timeline to profiling prediction time, and the result json will be saved to profiling_file
-
classmethod
create_class
(name)¶
-
predict
(**kwargs)¶
-
-
class
easy_vision.python.inference.predictor.
TextRecognizer
(model_path, profiling_file=None)[source]¶ Bases:
easy_vision.python.inference.predictor.Predictor
-
__init__
(model_path, profiling_file=None)[source]¶ Parameters: - model_path – saved_model directory or frozenpb file path
- profiling_file – profiling result file, default None. if not None, predict function will use Timeline to profiling prediction time, and the result json will be saved to profiling_file
-
classmethod
create_class
(name)¶
-
predict
(**kwargs)¶
-
-
class
easy_vision.python.inference.predictor.
TextSpotter
(model_path, profiling_file=None)[source]¶ Bases:
easy_vision.python.inference.predictor.Predictor
-
__init__
(model_path, profiling_file=None)[source]¶ Parameters: - model_path – saved_model directory or frozenpb file path
- profiling_file – profiling result file, default None. if not None, predict function will use Timeline to profiling prediction time, and the result json will be saved to profiling_file
-
classmethod
create_class
(name)¶
-
predict
(**kwargs)¶
-
easy_vision.python.inference.text_pipeline_predictor¶
-
class
easy_vision.python.inference.text_pipeline_predictor.
TextPipelinePredictor
(model_path)[source]¶ Bases:
easy_vision.python.inference.predictor.PredictorInterface
-
__init__
(model_path)[source]¶ init text detector and recognizer
Parameters: model directory which store detection model and recognition model (model_path) –
-
classmethod
create_class
(name)¶
-
crop_roi_image
(img, corners)[source]¶ Parameters: - img – pil image object
- coords – 4x2 numpy array, [:, y,x]
-
predict
(image_list, batch_size=None)[source]¶ Parameters: - image_list – a list of uint8 numpy array
- batch_size – unused, just for interface compatibility
Returns: detection_boxes: numpy float32 array [num_detections, 4] detection_keypoints: numpy float32 array [num_detections, 8] detection_classes: a float32 numpy array with shape [num_detection] detection_class_names: a numpy array of class names detection_scores: numpy float32 array with shape [num_detections] detection_texts: numpy string array with shape [num_detections] detection_texts_scores: numpy float32 array with shape [num_detections]
Return type: a list of dict conataining following key-values
-
easy_vision.python.inference.video_predictor¶
-
class
easy_vision.python.inference.video_predictor.
I3DClassifier
(model_path, resize_height=256, resize_width=340, crop_size=224, input_modal='rgb', profiling_file=None)[source]¶ Bases:
easy_vision.python.inference.video_predictor.VideoPredictor
-
__init__
(model_path, resize_height=256, resize_width=340, crop_size=224, input_modal='rgb', profiling_file=None)[source]¶ Parameters: - model_path – saved model path, model_rgb or model_flow
- input_modal – rgb indicates to use rgb model, flow indicates to use flow model
- profiling_file – profiling result file, default None. if not None, predict function will use Timeline to profiling prediction time, and the result json will be saved to profiling_file
-
classmethod
create_class
(name)¶
-
predict
(**kwargs)¶
-
predict_inner
(data_dict_list, batch_size=4)[source]¶ This class is abstracted to used in two stream classifier
Parameters: - clips – list of numpy uint8 array
- batch_size – batch_size
Returns: a list of a dict containing following rgb_logits/flow_logits: logits float32 class: predict class, int32 probs: a dict contain num_classes items with {class_name: prob} format
-
-
class
easy_vision.python.inference.video_predictor.
I3DTwoStreamClassifier
(model_path, resize_height=256, resize_width=340, crop_size=224, profiling_file=None)[source]¶ Bases:
easy_vision.python.inference.predictor.PredictorInterfaceV2
Two-stream Video classifier inference. average rgb and flow logits for output
-
__init__
(model_path, resize_height=256, resize_width=340, crop_size=224, profiling_file=None)[source]¶ Parameters: - model_path – two saved model path, model_rgb;model_flow
- sample_duration – sample length, default 16
- train_crop – crop method, default, ‘corner’
- input_modal – rgb indicates to use rgb model,
- profiling_file – profiling result file, default None. if not None, predict function will use Timeline to profiling prediction time, and the result json will be saved to profiling_file
-
classmethod
create_class
(name)¶
-
predict
(input_data_dict_list, batch_size=4)[source]¶ using session run predict a number of samples using batch_size
Parameters: - input_data_dict_list – a list of dict, each dict is a sample data to be predicted
- batch_size – batch_size passed by the caller, you can also ignore this param and use a fixed number if you do not want to adjust batch_size in runtime
Returns: - a list of dict, each dict is the prediction result of one sample
eg, {“output1”: value1, “output2”: value2}, the value type can be python int str float, and numpy array
Return type: result
-
-
class
easy_vision.python.inference.video_predictor.
VideoClassifier
(model_path, sample_duration=16, train_crop='corner', sample_size=112, output_feature=None, profiling_file=None)[source]¶ Bases:
easy_vision.python.inference.video_predictor.VideoPredictor
Video classifier inference.
-
__init__
(model_path, sample_duration=16, train_crop='corner', sample_size=112, output_feature=None, profiling_file=None)[source]¶ Parameters: - model_path – saved_model directory or frozenpb file path
- sample_duration – sample length, default 16
- train_crop – crop method, default, ‘corner’
- sample_size – output size of each frame, default 112
- output_feature – extract feature name, default None.
- profiling_file – profiling result file, default None.
- not None, predict function will use Timeline to profiling (if) –
- time, and the result json will be saved to profiling_file (prediction) –
-
classmethod
create_class
(name)¶
-
predict
(**kwargs)¶
-
-
class
easy_vision.python.inference.video_predictor.
VideoMultiLabelClassifier
(model_path, sample_duration=16, train_crop='corner', sample_size=112, profiling_file=None)[source]¶ Bases:
easy_vision.python.inference.video_predictor.VideoPredictor
Video multilabel classifier inference.
-
__init__
(model_path, sample_duration=16, train_crop='corner', sample_size=112, profiling_file=None)[source]¶ Parameters: - model_path – saved_model directory or frozenpb file path
- sample_duration – sample length, default 16
- train_crop – crop method, default, ‘corner’
- sample_size – output size of each frame, default 112
- profiling_file – profiling result file, default None.
- not None, predict function will use Timeline to profiling (if) –
- time, and the result json will be saved to profiling_file (prediction) –
-
classmethod
create_class
(name)¶
-
predict
(**kwargs)¶
-
-
class
easy_vision.python.inference.video_predictor.
VideoPredictor
(model_path, profiling_file=None, input_modal='rgb')[source]¶ Bases:
easy_vision.python.inference.predictor.PredictorV2
Video predictor.
-
__init__
(model_path, profiling_file=None, input_modal='rgb')[source]¶ Parameters: - model_path – saved_model directory or frozenpb file path
- profiling_file – profiling result file, default None. if not None, predict function will use Timeline to profiling
- time, and the result json will be saved to profiling_file (prediction) –
- input_modal –
‘rgb’ indicates to use video_clip, if preprocess graph is not exported, video_clip should be an np array of np.float32 with shape [num_frame, h, w, c], otherwise an np array of np.string with shape [num_frame]
- ’flow’ indicates to use flow_clip, if preprocess graph is not exported,
- flow_clip should be an np array of np.float32 with with shape[num_frame, h, w, c] otherwise an np array of np.string with shape [num_frame]
-
batch
(batch_data_dict_list)[source]¶ Pack a list of data to batch, here implements batch for images
Parameters: batch_data_dict_list – a list of a dict of data Returns: input feed dict for tensorflow
-
batch_clips
(clips)[source]¶ Pack a list of clips to batch :param clips: a list of numpy array
Returns: a float numpy array containing batched data an int32 numpy array containing origin image shape
-
classmethod
create_class
(name)¶
-