Skip to content

Commit

Permalink
train lower test upper, update io for ngsim roadway reading
Browse files Browse the repository at this point in the history
  • Loading branch information
raunakbh92 committed May 7, 2020
1 parent 00bcbd3 commit 84a5784
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 12 deletions.
6 changes: 6 additions & 0 deletions scripts/experiments.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,9 @@ rmse_plots_modelscompare(rmse_pos_list,filename = "media/rmse_pos_upper.svg");

coll_mat_list = [coll_mat_idm,coll_mat_cidm,coll_mat_lmidm,coll_mat_pf];
coll_barchart(coll_mat_list,filename = "media/coll_barchart_upper.svg");

#********************Train upper test lower******************
# We need to show a variability in the generated scenarios
# So we need to combine the particle sets of different vehicles together
# And then for the same set of vehicles in the lower merge i.e. test domain
# We show significantly different driving behavior by sampling from the particle set
35 changes: 35 additions & 0 deletions scripts/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,38 @@ function rmse_plots_modelscompare(rmse_mat_list;filename="media/test_rmse.pdf")
print("function rmse_plots_modelscompare says: saved $(filename)\n")
return nothing
end

"""
function train_one_test_another(;train_filename="media/lower_3.jld",test_filename="media/upper_2.jld",video_filename="media/train_low_test_up.mp4")
- Take final particle (i.e. mean of particles) obtained for one vehicle in train scenario
- Assign cidm model using that particle to all vehicles in test scenario
- Run a simulation, make a video and return collision assessment
# Example
```julia
# Run this from scripts folder
train_one_test_another(train_filename="media/lower_3.jld",
test_filename="media/upper_4.jld",video_filename="media/train_test_3_4.mp4")
```
"""
function train_one_test_another(;train_filename="media/lower_3.jld",
test_filename="media/upper_2.jld",video_filename="media/train_low_test_up.mp4")
# p_dict is a Dict(veh_id=>final_mean_particle)
p_dict,train_id_list = JLD.load(train_filename,"p","veh_id_list")
particle = p_dict[train_id_list[1]] # pick the first veh in train list wlog

f = FilteringEnvironment() # Will need to have lower as mergeenv when testing on lower
test_id_list,test_ts,test_te = JLD.load(test_filename,"veh_id_list","ts","te")
models = Dict{Int64,DriverModel}()
for id in test_id_list
models[id] = cidm_from_particle(f,particle)
end
nticks = test_te-test_ts+1
scene_real = deepcopy(f.traj[test_ts])
if !isempty(test_id_list) keep_vehicle_subset!(scene_real,test_id_list) end
scene_list = simulate(scene_real,f.roadway,models,nticks,f.timestep)

c_array = test_collision(scene_list,test_id_list)
scenelist2video(f,scene_list,filename=video_filename)
return c_array
end
1 change: 1 addition & 0 deletions src/AutomotiveInteraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export
include("Driving/overlays.jl")

export
cidm_from_particle,
hallucinate_a_step,
weight_and_resample,
multistep_update,
Expand Down
4 changes: 2 additions & 2 deletions src/Data_Processing/roadway_building.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ end
"""
function make_roadway_ngsim()
- Read in the ngsim 101 roadway from the provided roadway file `../dataset/ngsim_101.txt`
- Read in the ngsim 101 roadway from the provided roadway file `/dataset/ngsim_101.txt`
# Examples
```julia
roadway_ngsim = make_roadway_ngsim()
```
"""
function make_roadway_ngsim()
roadway_ngsim = open(io->read(io, MIME"text/plain"(), Roadway),joinpath(@__DIR__,"dataset/ngsim_101.txt"), "r")
roadway_ngsim = open(io->read(io, Roadway),joinpath(@__DIR__,"dataset/ngsim_101.txt"), "r")
return roadway_ngsim
end

Expand Down
22 changes: 12 additions & 10 deletions src/Driving/visualization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,27 @@ end
# Examples
```julia
# See run_vehicles function in driving_simulation.jl
scenelist2video(f,scenelist,filename="media/test_scenelist2video.mp4")
```
"""
function scenelist2video(scene_list;id_list=[],roadway,filename)
function scenelist2video(f::FilteringEnvironment,scene_list;filename)
frames = Frames(MIME("image/png"),fps = 10)
mr = MergingRoadway(roadway) # Wrapper for specialized render for merging lanes
mr = MergingRoadway(f.roadway) # Wrapper for specialized render for merging lanes
mp = VecE2(1064.5227, 959.1559)

# Loop over list of scenes and convert to video
for i in 1:length(scene_list)
if !isempty(id_list) keep_vehicle_subset!(scene_list[i],id_list) end
scene_visual = render([mr,scene_list[i],
IDOverlay(scene=scene_list[i]),
TextOverlay(text=["frame=$(i)"],font_size=12)],
camera=StaticCamera(position=mp,zoom=5.)
)
temp_scene = deepcopy(scene_list[i])
renderables = [
mr,
(FancyCar(car=temp_scene[j]) for j in 1:length(temp_scene))...,
IDOverlay(scene=temp_scene),
TextOverlay(text=["frame=$(i)"],font_size=12)
]
scene_visual = render(renderables,camera=StaticCamera(position=mp,zoom=5.))
push!(frames,scene_visual)
end
print("Making video filename: $(filename)\n")
print("scenelist2video says: Making video filename: $(filename)\n")
write(filename,frames)
return nothing
end
Expand Down

0 comments on commit 84a5784

Please sign in to comment.