天池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)
相关推荐
云烟成雨TD12 分钟前
Spring AI 1.x 系列【56】用大模型评判大模型:递归顾问实现自动化评估方案
人工智能·spring·自动化
Hello:CodeWorld15 分钟前
C 风格变参 vs C++ 变参模板:核心区别与选型指南
c语言·c++·算法
AI客栈32 分钟前
K8s 自定义控制器中 WorkQueue 队列优化实践:基于 IPVS 转发原理的状态变化处理
人工智能
0xR3lativ1ty37 分钟前
每周AI工具新动态
人工智能
jerryinwuhan39 分钟前
面向产业带与中小企业数字化转型的电商运营人才培养模式
大数据·人工智能
xsc69967541 分钟前
从零搭建大模型与智能体平台 - 完整技术详解
python
Drgfd1 小时前
智造赋能品控:汪进进以精益生产,夯实质量制造底座
人工智能·制造
米小虾1 小时前
"Chat is dead":OpenAI 正在杀死的不是聊天,是整个 AI 交互范式
人工智能·openai
冬奇Lab1 小时前
Agent 系列(18):成本与性能优化——省钱且更快
人工智能·llm·agent
Hefei GlobefishAI1 小时前
合肥合豚AI硬件方案:专为智能售货柜厂商定制的无人零售接口套件
人工智能·零售·自动售货机·无人零售硬件·ai硬件方案·智能售货柜·接口套件