#安装paddlehub
!pip install paddlehub==1.6.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
情感倾向分析(Sentiment Classification,简称Senta)针对带有主观描述的中文文本,可自动判断该文本的情感极性类别并给出相应的置信度,能够帮助企业理解用户消费习惯、分析热点话题和危机舆情监控,为企业提供有利的决策支持。
#安装情感分析模型
!hub install senta_lstm==1.1.0
#!hub run senta_lstm --input_text "这家餐厅很难吃"
!hub run senta_lstm --input_text "人工智能课程很有趣"
结果:
[{'text': '人工智能课程很有趣', 'sentiment_label': 1, 'sentiment_key': 'positive', 'positive_probs': 0.9572, 'negative_probs': 0.0428}]
PyramidBox-Lite是基于2018年百度发表于计算机视觉顶级会议ECCV 2018的论文PyramidBox而研发的轻量级模型,模型基于主干网络FaceBoxes,对于光照、口罩遮挡、表情变化、尺度变化等常见问题具有很强的鲁棒性。该PaddleHub Module基于WIDER FACE数据集和百度自采人脸数据集进行训练,支持预测,可用于检测人脸是否佩戴口罩。
#安装口罩检测模型
!hub install pyramidbox_lite_mobile_mask==1.1.0
!hub run pyramidbox_lite_mobile_mask --input_path "data/data31681/test.jpeg"
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
test_img_path = "data/data31681/test.jpeg"
img = mpimg.imread(test_img_path)
# 展示待预测图片
plt.figure(figsize=(10,10))
plt.imshow(img)
plt.axis('off')
plt.show()
# 预测结果展示
test_img_path = "./detection_result/test.jpeg"
img = mpimg.imread(test_img_path)
# 展示预测结果图片
plt.figure(figsize=(10,10))
plt.imshow(img)
plt.axis('off')
plt.show()
import paddlehub as hub
import cv2
module = hub.Module(name="pyramidbox_lite_mobile_mask")
test_img_path = "data/data31681/test.jpeg"
# set input dict
input_dict = {"data": [cv2.imread(test_img_path)]}
results = module.face_detection(data=input_dict)
print(results)
结果:
[{'data': {'label': 'MASK', 'left': 678.9846324920654, 'right': 893.2966804504395, 'top': 241.9092297554016, 'bottom': 487.231333732605, 'confidence': 0.9711812}, 'id': 1}]
import paddlehub as hub
humanseg = hub.Module(name="deeplabv3p_xception65_humanseg")
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
path = ["data/data31681/test.jpeg"]
results = humanseg.segmentation(data={"image":path})
# 预测结果展示
test_img_path = result["processed"]
img = mpimg.imread(test_img_path)
# 展示预测结果图片
plt.figure(figsize=(10,10))
plt.imshow(img)
plt.axis('off')
plt.show()
import paddlehub as hub
import cv2
stylepro_artistic = hub.Module(name="stylepro_artistic")
results = stylepro_artistic.style_transfer(images=[{
'content': cv2.imread("data/data31681/main.png"),
'styles': [cv2.imread("data/data31681/style1.png")]}],
alpha = 1.0,
visualization = True)
# 原图展示
test_img_path = "data/data31681/main.png"
img = mpimg.imread(test_img_path)
plt.figure(figsize=(10,10))
plt.imshow(img)
plt.axis('off')
plt.show()
# 原图展示
test_img_path = "data/data31681/style1.png"
img = mpimg.imread(test_img_path)
plt.figure(figsize=(10,10))
plt.imshow(img)
plt.axis('off')
plt.show()
# 预测结果展示
test_img_path = "transfer_result/ndarray_1587809892.1425676.jpg"
img = mpimg.imread(test_img_path)
# 展示预测结果图片
plt.figure(figsize=(10,10))
plt.imshow(img)
plt.axis('off')
plt.show()