天池2023智能驾驶汽车虚拟仿真视频数据理解--baseline

baseline

代码

百度飞浆一键运行

python 复制代码
import paddle
from PIL import Image
from clip import tokenize, load_model
import glob, json, os
import cv2
from PIL import Image
from tqdm import tqdm_notebook
import numpy as np
from sklearn.preprocessing import normalize
import matplotlib.pyplot as plt

model, transforms = load_model('ViT_B_32', pretrained=True)

en_match_words = {
"scerario" : ["suburbs","city street","expressway","tunnel","parking-lot","gas or charging stations","unknown"],
"weather" : ["clear","cloudy","raining","foggy","snowy","unknown"],
"period" : ["daytime","dawn or dusk","night","unknown"],
"road_structure" : ["normal","crossroads","T-junction","ramp","lane merging","parking lot entrance","round about","unknown"],
"general_obstacle" : ["nothing","speed bumper","traffic cone","water horse","stone","manhole cover","nothing","unknown"],
"abnormal_condition" : ["uneven","oil or water stain","standing water","cracked","nothing","unknown"],
"ego_car_behavior" : ["slow down","go straight","turn right","turn left","stop","U-turn","speed up","lane change","others"],
"closest_participants_type" : ["passenger car","bus","truck","pedestrain","policeman","nothing","others","unknown"],
"closest_participants_behavior" : ["slow down","go straight","turn right","turn left","stop","U-turn","speed up","lane change","others"],
}

submit_json = {
    "author" : "abc" ,
    "time" : "231011",
    "model" : "model_name",
    "test_results" : []
}

paths = glob.glob('./初赛测试视频/*')
paths.sort()

for video_path in paths:
    print(video_path)
    
    clip_id = video_path.split('/')[-1]
    cap = cv2.VideoCapture(video_path)
    img = cap.read()[1]
    image = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    image = Image.fromarray(image)
    image = transforms(image).unsqueeze(0)

    single_video_result = {
        "clip_id": clip_id,
        "scerario" : "cityroad",
        "weather":"unknown",
        "period":"night",
        "road_structure":"ramp",
        "general_obstacle":"nothing",
        "abnormal_condition":"nothing",
        "ego_car_behavior":"turning right",
        "closest_participants_type":"passenger car",
        "closest_participants_behavior":"braking"
    }
    
    for keyword in en_match_words.keys():
        if keyword not in ["weather", "road_structure"]:
            continue
            
        texts = np.array(en_match_words[keyword])

        with paddle.no_grad():
            logits_per_image, logits_per_text = model(image, tokenize(en_match_words[keyword]))
            probs = paddle.nn.functional.softmax(logits_per_image, axis=-1)

        probs = probs.numpy()        
        single_video_result[keyword] = texts[probs[0].argsort()[::-1][0]]
        
    submit_json["test_results"].append(single_video_result)
    
with open('clip_result.json', 'w', encoding='utf-8') as up:
    json.dump(submit_json, up, ensure_ascii=False)
相关推荐
一颗星星辰1 分钟前
Python | 第九章 | 排序和查找
服务器·网络·python
打码人的日常分享1 分钟前
企业人力资源管理,人事档案管理,绩效考核,五险一金,招聘培训,薪酬管理一体化管理系统(源码)
java·数据库·python·需求分析·规格说明书
27669582922 分钟前
京东e卡滑块 分析
java·javascript·python·node.js·go·滑块·京东
unix2linux2 分钟前
Parade Series - SHA256
linux·python·mysql·shell
SEU-WYL6 分钟前
基于深度学习的视频摘要生成
人工智能·深度学习·音视频
人工智能技术咨询.29 分钟前
张雪峰谈人工智能技术应用专业的就业前景!
人工智能·学习·计算机视觉·语言模型
巽星石31 分钟前
【Blender Python】7.一些运算、三角函数以及随机
python·blender·三角函数·随机·环形阵列
CSXB9931 分钟前
一、Python(介绍、环境搭建)
开发语言·python·测试工具·集成测试
Mopes__35 分钟前
Python | Leetcode Python题解之第461题汉明距离
python·leetcode·题解
睡不着还睡不醒1 小时前
【数据结构强化】应用题打卡
算法