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


    baseline

    代码

    百度飞浆一键运行

    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
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
  • 相关阅读:
    K8S对外服务之Ingress
    Laya中的脚本与外部的Js之间相互调用
    2000亿元贴息贷款,医疗系统上云,解锁医护协同新玩法
    派克液压油泵PVP3336R2M
    qtday3
    杰理之充电仓UI 设置相关的接口 API【篇】
    [CISCN 2019初赛]Love Math
    快鲸物业管理系统:助力物业管理服务双提升
    BUUCTF 不一样的flag
    Vue中常用的指令
  • 原文地址:https://blog.csdn.net/weixin_43557816/article/details/134431520