天池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)
相关推荐
新智元9 分钟前
数学圈地震!o3 靠直觉刷爆人类顶尖难题,14 位专家集体破防
人工智能·openai
AI大模型学习教程15 分钟前
Transformer:BERT模型和代码解析
人工智能·llm
LLM大模型17 分钟前
LangChain篇- 一文读懂 LCEL工作流编排
人工智能·程序员·llm
工业互联网专业29 分钟前
基于django+vue的健身房管理系统-vue
vue.js·python·django·毕业设计·源码·课程设计·健身房管理系统
aischang1 小时前
统信桌面专业版如何使用python开发平台jupyter
开发语言·python·jupyter·统信uos
红鼻子时代1 小时前
Django RBAC项目后端实战 - 03 DRF权限控制实现
后端·python·django·rabc
试剂界的爱马仕1 小时前
TCA 循环中间体如何改写肝损伤命运【AbMole】
大数据·人工智能·科技·机器学习·ai写作
敲键盘的小夜猫1 小时前
大模型链路调试平台之LangSmith实战指南
python·langchain
研一计算机小白一枚1 小时前
VRFF: Video Registration and FusionFramework 论文详解
人工智能·深度学习·计算机视觉
狐凄1 小时前
Python实例题:Python计算概率论
开发语言·python·概率论