Commit 85570d57 authored by yangql's avatar yangql
Browse files

Update Python/Classifier.py

parent 36700b06
...@@ -42,7 +42,7 @@ def Preprocessing(pathOfImage): ...@@ -42,7 +42,7 @@ def Preprocessing(pathOfImage):
norm_img_data = norm_img_data.reshape(1, 3, 224, 224).astype('float32') norm_img_data = norm_img_data.reshape(1, 3, 224, 224).astype('float32')
return norm_img_data return norm_img_data
def postprocess(scores): def postprocess(scores,pathOfImage):
''' '''
Postprocessing with mxnet gluon Postprocessing with mxnet gluon
The function takes scores generated by the network and returns the class IDs in decreasing order The function takes scores generated by the network and returns the class IDs in decreasing order
...@@ -54,6 +54,9 @@ def postprocess(scores): ...@@ -54,6 +54,9 @@ def postprocess(scores):
a = np.argsort(preds)[::-1] a = np.argsort(preds)[::-1]
print('class=%s ; probability=%f' %(labels[a[0]],preds[a[0]])) print('class=%s ; probability=%f' %(labels[a[0]],preds[a[0]]))
text = 'class=%s ' % (labels[a[0]])
saveimage(pathOfImage,text)
def ort_seg_dcu(model_path,image): def ort_seg_dcu(model_path,image):
#创建sess_options #创建sess_options
...@@ -73,6 +76,17 @@ def ort_seg_dcu(model_path,image): ...@@ -73,6 +76,17 @@ def ort_seg_dcu(model_path,image):
return scores return scores
def saveimage(pathOfImage,text):
iimage = cv2.imread(pathOfImage, cv2.IMREAD_COLOR)
font = cv2.FONT_HERSHEY_SIMPLEX
font_scale = 0.5
font_color = (255, 0, 0)
font_thickness = 1
text_position = (5, 10)
cv2.putText(iimage, text, text_position, font, font_scale, font_color, font_thickness)
cv2.imwrite("./output_image.jpg", iimage)
cv2.destroyAllWindows()
if __name__ == '__main__': if __name__ == '__main__':
pathOfImage ="../Resource/Images/ImageNet_01.jpg" pathOfImage ="../Resource/Images/ImageNet_01.jpg"
...@@ -83,4 +97,4 @@ if __name__ == '__main__': ...@@ -83,4 +97,4 @@ if __name__ == '__main__':
result = ort_seg_dcu(model_path,image) result = ort_seg_dcu(model_path,image)
# 解析分类结果 # 解析分类结果
postprocess(result) postprocess(result,pathOfImage)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment