Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
LearningEnvironment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Armin Co
LearningEnvironment
Commits
3494392f
Commit
3494392f
authored
Feb 21, 2021
by
Armin Co
Browse files
Options
Downloads
Patches
Plain Diff
Measure network baselines
parent
e714c48a
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
carla_environment.py
+67
-25
67 additions, 25 deletions
carla_environment.py
run_scripts/baselines.py
+47
-0
47 additions, 0 deletions
run_scripts/baselines.py
with
115 additions
and
25 deletions
.gitignore
+
1
−
0
View file @
3494392f
...
@@ -2,6 +2,7 @@ __pycache__
...
@@ -2,6 +2,7 @@ __pycache__
.vscode
.vscode
saved_agents
saved_agents
benchmarks
benchmarks
baselines
workspace.code-workspace
workspace.code-workspace
tech_demo.py
tech_demo.py
*.png
*.png
This diff is collapsed.
Click to expand it.
carla_environment.py
+
67
−
25
View file @
3494392f
...
@@ -47,7 +47,7 @@ class Camera:
...
@@ -47,7 +47,7 @@ class Camera:
camera_blueprint
.
set_attribute
(
'
image_size_x
'
,
f
'
{
self
.
width
}
'
)
camera_blueprint
.
set_attribute
(
'
image_size_x
'
,
f
'
{
self
.
width
}
'
)
camera_blueprint
.
set_attribute
(
'
image_size_y
'
,
f
'
{
self
.
height
}
'
)
camera_blueprint
.
set_attribute
(
'
image_size_y
'
,
f
'
{
self
.
height
}
'
)
camera_blueprint
.
set_attribute
(
'
fov
'
,
'
95
'
)
camera_blueprint
.
set_attribute
(
'
fov
'
,
'
95
'
)
camera_transform
=
carla
.
Transform
(
carla
.
Location
(
x
=-
3
.0
,
z
=
2.2
))
camera_transform
=
carla
.
Transform
(
carla
.
Location
(
x
=-
7
.0
,
z
=
5.2
),
carla
.
Rotation
(
pitch
=-
20.0
,
yaw
=
0
,
roll
=
0.0
))
self
.
sensor
=
world
.
world
.
spawn_actor
(
camera_blueprint
,
camera_transform
,
attach_to
=
world
.
player
)
self
.
sensor
=
world
.
world
.
spawn_actor
(
camera_blueprint
,
camera_transform
,
attach_to
=
world
.
player
)
self
.
sensor
.
listen
(
lambda
data
:
self
.
process_img
(
data
))
self
.
sensor
.
listen
(
lambda
data
:
self
.
process_img
(
data
))
...
@@ -87,6 +87,35 @@ class CollisionSensor:
...
@@ -87,6 +87,35 @@ class CollisionSensor:
intensity
=
math
.
sqrt
(
impulse
.
x
**
2
+
impulse
.
y
**
2
+
impulse
.
z
**
2
)
intensity
=
math
.
sqrt
(
impulse
.
x
**
2
+
impulse
.
y
**
2
+
impulse
.
z
**
2
)
# print(intensity)
# print(intensity)
class
ObstacleSensor
:
sensor
=
None
parent
=
None
ZONES
=
4
obstacle
=
[]
def
__init__
(
self
,
world
,
parent
):
self
.
parent
=
parent
bp
=
world
.
get_blueprint_library
().
find
(
'
sensor.other.obstacle
'
)
bp
.
set_attribute
(
'
distance
'
,
'
10
'
)
bp
.
set_attribute
(
'
hit_radius
'
,
'
3
'
)
print
(
bp
.
get_attribute
(
'
hit_radius
'
))
self
.
sensor
=
world
.
spawn_actor
(
bp
,
carla
.
Transform
(),
attach_to
=
parent
,
attachment_type
=
carla
.
AttachmentType
.
Rigid
)
weak_self
=
weakref
.
ref
(
self
)
self
.
sensor
.
listen
(
lambda
event
:
ObstacleSensor
.
_on_event
(
weak_self
,
event
))
def
_on_event
(
weak_self
,
event
):
self
=
weak_self
()
if
not
self
:
return
self
.
collision
=
event
if
not
event
.
other_actor
.
type_id
==
'
static.road
'
:
print
(
self
.
parent
.
get_location
())
print
(
self
.
parent
.
get_velocity
())
print
(
event
.
other_actor
.
type_id
)
print
(
event
.
other_actor
.
transform
)
print
(
event
.
distance
)
class
LidarSensor
:
class
LidarSensor
:
sensor
=
None
sensor
=
None
data
=
None
data
=
None
...
@@ -116,6 +145,7 @@ class World:
...
@@ -116,6 +145,7 @@ class World:
"""
Wrapper for the carla environment, incl. player/vehicle
"""
"""
Wrapper for the carla environment, incl. player/vehicle
"""
player
=
None
player
=
None
collision_sensor
=
None
collision_sensor
=
None
obstacle_sensor
=
None
lidar_sensor
=
None
lidar_sensor
=
None
world
=
None
world
=
None
blueprint_library
=
None
blueprint_library
=
None
...
@@ -137,8 +167,7 @@ class World:
...
@@ -137,8 +167,7 @@ class World:
"""
Remove and create new player/vehicle.
"""
"""
Remove and create new player/vehicle.
"""
self
.
destroy
()
self
.
destroy
()
time
.
sleep
(
0.5
)
time
.
sleep
(
0.5
)
self
.
spawn_player
()
self
.
spawn_on_sidewalk
()
self
.
spawn_actors
()
def
observation
(
self
):
def
observation
(
self
):
if
self
.
player
is
not
None
:
if
self
.
player
is
not
None
:
...
@@ -148,26 +177,32 @@ class World:
...
@@ -148,26 +177,32 @@ class World:
else
:
else
:
return
[
0
,
0
,
0
]
return
[
0
,
0
,
0
]
def
spawn_player
(
self
):
def
spawn_player
(
self
,
transform
):
"""
Add a vehicle to the world.
"""
"""
Add a vehicle to the world.
"""
while
self
.
player
is
None
:
while
self
.
player
is
None
:
blueprint
=
random
.
choice
(
self
.
blueprint_library
.
filter
(
'
model3
'
))
blueprint
=
random
.
choice
(
self
.
blueprint_library
.
filter
(
'
model3
'
))
position
=
carla
.
T
ransform
(
carla
.
Location
(
x
=-
13
,
y
=
57.5
,
z
=
0.2
),
carla
.
Rotation
(
pitch
=
0.0
,
yaw
=-
180
,
roll
=
0.0
))
position
=
t
ransform
self
.
player
=
self
.
world
.
try_spawn_actor
(
blueprint
,
position
)
self
.
player
=
self
.
world
.
try_spawn_actor
(
blueprint
,
position
)
start_location
=
self
.
player
.
get_location
()
start_location
=
self
.
player
.
get_location
()
print
(
str
(
start_location
))
print
(
str
(
start_location
))
self
.
collision_sensor
=
CollisionSensor
(
self
.
world
,
self
.
player
)
self
.
collision_sensor
=
CollisionSensor
(
self
.
world
,
self
.
player
)
# self.lidar_sensor = LidarSensor(self.world, self.player)
self
.
obstacle_sensor
=
ObstacleSensor
(
self
.
world
,
self
.
player
)
# start_location.x = 288.0
# start_location.y = 55.0
# self.player.set_location(start_location)
def
spawn_actors
(
self
):
def
spawn_on_sidewalk
(
self
):
blueprint
=
random
.
choice
(
self
.
blueprint_library
.
filter
(
'
etron
'
))
position
=
carla
.
Transform
(
carla
.
Location
(
x
=-
13
,
y
=
57.5
,
z
=
0.2
),
carla
.
Rotation
(
pitch
=
0.0
,
yaw
=-
180
,
roll
=
0.0
))
self
.
spawn_player
(
position
)
self
.
spawn_actors
(
self
.
sidewalk_parking_cars_transforms
())
def
sidewalk_parking_cars_transforms
(
self
):
transforms
=
[]
transforms
=
[]
transforms
.
append
(
carla
.
Transform
(
carla
.
Location
(
x
=-
19.2
,
y
=
54.5
,
z
=
0.2
),
carla
.
Rotation
(
pitch
=
0.0
,
yaw
=-
180
,
roll
=
0.0
)))
transforms
.
append
(
carla
.
Transform
(
carla
.
Location
(
x
=-
19.2
,
y
=
54.5
,
z
=
0.2
),
carla
.
Rotation
(
pitch
=
0.0
,
yaw
=-
180
,
roll
=
0.0
)))
transforms
.
append
(
carla
.
Transform
(
carla
.
Location
(
x
=-
14.3
,
y
=
54.7
,
z
=
0.2
),
carla
.
Rotation
(
pitch
=
0.0
,
yaw
=-
180
,
roll
=
0.0
)))
transforms
.
append
(
carla
.
Transform
(
carla
.
Location
(
x
=-
14.3
,
y
=
54.7
,
z
=
0.2
),
carla
.
Rotation
(
pitch
=
0.0
,
yaw
=-
180
,
roll
=
0.0
)))
transforms
.
append
(
carla
.
Transform
(
carla
.
Location
(
x
=-
37.3
,
y
=
53.7
,
z
=
0.2
),
carla
.
Rotation
(
pitch
=
0.0
,
yaw
=-
180
,
roll
=
0.0
)))
transforms
.
append
(
carla
.
Transform
(
carla
.
Location
(
x
=-
37.3
,
y
=
53.7
,
z
=
0.2
),
carla
.
Rotation
(
pitch
=
0.0
,
yaw
=-
180
,
roll
=
0.0
)))
return
transforms
def
spawn_actors
(
self
,
transforms
):
blueprint
=
random
.
choice
(
self
.
blueprint_library
.
filter
(
'
etron
'
))
mass
=
carla
.
VehiclePhysicsControl
(
mass
=
900000.0
)
mass
=
carla
.
VehiclePhysicsControl
(
mass
=
900000.0
)
for
transform
in
transforms
:
for
transform
in
transforms
:
actor
=
self
.
world
.
try_spawn_actor
(
blueprint
,
transform
)
actor
=
self
.
world
.
try_spawn_actor
(
blueprint
,
transform
)
...
@@ -187,6 +222,9 @@ class World:
...
@@ -187,6 +222,9 @@ class World:
if
self
.
collision_sensor
is
not
None
:
if
self
.
collision_sensor
is
not
None
:
self
.
collision_sensor
.
sensor
.
destroy
()
self
.
collision_sensor
.
sensor
.
destroy
()
self
.
collision_sensor
=
None
self
.
collision_sensor
=
None
if
self
.
obstacle_sensor
is
not
None
:
self
.
obstacle_sensor
.
sensor
.
destroy
()
self
.
obstacle_sensor
=
None
def
step
(
self
,
action
):
def
step
(
self
,
action
):
...
@@ -204,35 +242,38 @@ class World:
...
@@ -204,35 +242,38 @@ class World:
pos
=
self
.
player
.
get_transform
()
pos
=
self
.
player
.
get_transform
()
pos_diff
=
math
.
sqrt
((
target
.
location
.
x
-
pos
.
location
.
x
)
**
2
+
(
target
.
location
.
y
-
pos
.
location
.
y
)
**
2
)
pos_diff
=
math
.
sqrt
((
target
.
location
.
x
-
pos
.
location
.
x
)
**
2
+
(
target
.
location
.
y
-
pos
.
location
.
y
)
**
2
)
rot_diff
=
(
target
.
rotation
.
yaw
-
pos
.
rotation
.
yaw
)
rot_diff
=
(
target
.
rotation
.
yaw
-
pos
.
rotation
.
yaw
)
r
=
(
-
pos_diff
/
10
)
+
1
velocity
=
self
.
player
.
get_velocity
()
v
=
math
.
sqrt
((
velocity
.
x
)
**
2
+
(
velocity
.
y
)
**
2
)
r
=
((
-
pos_diff
/
10
)
+
1
)
/
5
if
v
<
0.01
:
r
-=
0.5
if
v
>
15.0
:
r
-=
10
at_final_position
=
False
at_final_position
=
False
if
pos_diff
<
1.8
:
if
pos_diff
<
1.8
:
if
self
.
was_big_reward
==
False
:
if
self
.
was_big_reward
==
False
:
r
+=
10
0
r
+=
5
0
self
.
was_big_reward
=
True
self
.
was_big_reward
=
True
if
abs
(
rot_diff
)
<
5
:
if
abs
(
rot_diff
)
<
5
and
v
<
0.01
:
r
+=
100
at_final_position
=
True
at_final_position
=
True
else
:
else
:
if
self
.
was_big_reward
==
True
:
if
self
.
was_big_reward
==
True
:
self
.
was_big_reward
=
False
self
.
was_big_reward
=
False
r
-=
50
r
-=
50
velocity
=
self
.
player
.
get_velocity
()
v
=
math
.
sqrt
((
velocity
.
x
)
**
2
+
(
velocity
.
y
)
**
2
)
if
v
<
0.01
:
r
-=
1
if
v
>
15.0
:
r
-=
10
done
=
False
done
=
False
if
at_final_position
and
v
<
0.01
:
if
at_final_position
:
print
(
"
Success
"
)
print
(
"
Success
"
)
r
+=
100
done
=
True
done
=
True
if
self
.
collision_sensor
.
collision
is
not
None
:
if
self
.
collision_sensor
.
collision
is
not
None
:
r
-=
250
r
-=
250
done
=
True
done
=
True
if
action
==
IDLE
:
if
action
==
IDLE
:
r
-=
1
r
-=
0.3
return
self
.
observation
(),
r
,
done
,
None
return
self
.
observation
(),
r
,
done
,
None
class
ActionSpace
:
class
ActionSpace
:
...
@@ -260,6 +301,7 @@ class CarlaEnvironment:
...
@@ -260,6 +301,7 @@ class CarlaEnvironment:
if
render
:
if
render
:
self
.
allow_render
=
True
self
.
allow_render
=
True
self
.
camera
=
Camera
(
self
.
world
,
camera_type
=
'
semantic_segmentation
'
)
self
.
camera
=
Camera
(
self
.
world
,
camera_type
=
'
semantic_segmentation
'
)
# self.camera = Camera(self.world, camera_type='rgb')
def
reset
(
self
):
def
reset
(
self
):
self
.
world
.
reset
()
self
.
world
.
reset
()
...
@@ -288,7 +330,7 @@ if __name__ == "__main__":
...
@@ -288,7 +330,7 @@ if __name__ == "__main__":
ctrl
=
Controller
()
ctrl
=
Controller
()
cumulated_reward
=
0
cumulated_reward
=
0
while
ctrl
.
is_running
():
while
ctrl
.
is_running
():
clock
.
tick
(
20
)
clock
.
tick
(
5
)
ctrl
.
on_update
()
ctrl
.
on_update
()
obs
,
reward
,
done
,
_
=
env
.
step
(
ctrl
.
get_action
(),
render
=
True
)
obs
,
reward
,
done
,
_
=
env
.
step
(
ctrl
.
get_action
(),
render
=
True
)
print
(
str
(
reward
)
+
'
'
+
str
(
done
))
print
(
str
(
reward
)
+
'
'
+
str
(
done
))
...
...
This diff is collapsed.
Click to expand it.
run_scripts/baselines.py
0 → 100644
+
47
−
0
View file @
3494392f
import
main
import
environment_wrapper
as
ew
import
gym
from
agents
import
DQAgent
,
QAgent
import
threading
import
copy
import
time
start
=
time
.
time
()
c_32
=
ew
.
Config
()
c_32
.
name
=
'
FirstLayerBase
'
c_32
.
render
=
False
c_32
.
force_cpu
=
True
c_32
.
env
=
gym
.
make
(
'
CartPole-v0
'
)
c_32
.
env_type
=
'
CartPole
'
c_32
.
net_layout
=
[
32
,
32
]
c_32
.
eps_decay
=
0.9995
c_32
.
learn_rate
=
0.00075
c_32
.
run_episodes
=
350
c_32
.
save_to
=
'
baselines/
'
c_64
=
copy
.
deepcopy
(
c_32
)
c_64
.
net_layout
=
[
64
,
32
]
c_128
=
copy
.
deepcopy
(
c_32
)
c_128
.
net_layout
=
[
128
,
32
]
c_256
=
copy
.
deepcopy
(
c_32
)
c_256
.
net_layout
=
[
256
,
32
]
c_512
=
copy
.
deepcopy
(
c_32
)
c_512
.
net_layout
=
[
512
,
32
]
c_1024
=
copy
.
deepcopy
(
c_32
)
c_1024
.
net_layout
=
[
1024
,
32
]
conf
=
c_32
conf
.
conf_to_name
()
conf
.
agent
=
QAgent
(
conf
)
main
.
run
(
conf
)
print
(
'
Took:
'
+
str
(
time
.
time
()
-
start
))
print
(
'
Done
'
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment