f"The size({h}, {w}) of CropImage must be greater than size({img_h}, {img_w}) of image. Please check image original size and size of ResizeImage if used."
err=f"There is no model file or params file in this directory: {inference_model_dir}"
raiseInputModelError(err)
return
else:
err=f"Please specify the model name supported by PaddleClas or directory contained model file and params file."
raiseInputModelError(err)
return
defpredict(self,input_data,print_pred=True):
"""Predict label of img with paddleclas.
Args:
input_data(string, NumPy.ndarray): image to be classified, support:
string: local path of image file, internet URL, directory containing series of images;
NumPy.ndarray: preprocessed image data that has 3 channels and accords with [C, H, W], or raw image data that has 3 channels and accords with [H, W, C]
input_data(str, NumPy.ndarray):
image to be classified, support: str(local path of image file, internet URL, directory containing series of images) and NumPy.ndarray(preprocessed image data that has 3 channels and accords with [C, H, W], or raw image data that has 3 channels and accords with [H, W, C]).
Returns:
dict: {image_name: "", class_id: [], scores: [], label_names: []},if label name path == None,label_names will be empty.
"""
ifisinstance(input_data,np.ndarray):
ifnotself.args.is_preprocessed:
input_data=input_data[:,:,::-1]
input_data=preprocess(input_data,self.args)
input_data=np.expand_dims(input_data,axis=0)
batch_outputs=self.predictor.predict(input_data)
result={"filename":"image"}
result.update(self.postprocess(batch_outputs[0]))
returnresult
returnself.cls_predictor.predict(input_data)
elifisinstance(input_data,str):
input_path=input_data
# download internet image
ifinput_path.startswith('http'):
ifnotos.path.exists(BASE_IMAGES_DIR):
os.makedirs(BASE_IMAGES_DIR)
file_path=os.path.join(BASE_IMAGES_DIR,'tmp.jpg')
download_with_progressbar(input_path,file_path)
print("Current using image from Internet:{}, renamed as: {}".