Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Fidle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Talks
Fidle
Commits
f08fcc4c
Commit
f08fcc4c
authored
5 years ago
by
Jean-Luc Parouty Jean-Luc.Parouty@simap.grenoble-inp.fr
Browse files
Options
Downloads
Patches
Plain Diff
Update GTSRB
parent
72704d4b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
GTSRB/01-Preparation-of-data.ipynb
+8
-5
8 additions, 5 deletions
GTSRB/01-Preparation-of-data.ipynb
GTSRB/02-First-convolutions.ipynb
+327
-77
327 additions, 77 deletions
GTSRB/02-First-convolutions.ipynb
GTSRB/README.ipynb
+5
-2
5 additions, 2 deletions
GTSRB/README.ipynb
with
340 additions
and
84 deletions
GTSRB/01-Preparation-of-data.ipynb
+
8
−
5
View file @
f08fcc4c
...
@@ -7,13 +7,14 @@
...
@@ -7,13 +7,14 @@
"German Traffic Sign Recognition Benchmark (GTSRB)\n",
"German Traffic Sign Recognition Benchmark (GTSRB)\n",
"=================================================\n",
"=================================================\n",
"---\n",
"---\n",
"Introduction au Deep Learning (IDLE) - S. Arias, E. Maldonado, JL. Parouty - CNRS/SARI/DEVLOG - 2020\n",
"Introduction au Deep Learning (IDLE) - S. Arias, E. Maldonado, JL. Parouty - CNRS/SARI/DEVLOG - 2020 \n",
"Version: 1.12\n",
"\n",
"\n",
"## Episode 1 : Preparation of data\n",
"## Episode 1 : Preparation of data\n",
"\n",
"\n",
" - Understanding the dataset\n",
" - Understanding the dataset\n",
" - Preparing and formatting enhanced data\n",
" - Preparing and formatting enhanced data\n",
" - Save enhanced datasets\n"
" - Save enhanced datasets
in h5 file format
\n"
]
]
},
},
{
{
...
@@ -43,7 +44,7 @@
...
@@ -43,7 +44,7 @@
"\n",
"\n",
"import idle.pwk as ooo\n",
"import idle.pwk as ooo\n",
"from importlib import reload\n",
"from importlib import reload\n",
"
reload(ooo)
\n",
"\n",
"ooo.init()"
"ooo.init()"
]
]
},
},
...
@@ -109,7 +110,8 @@
...
@@ -109,7 +110,8 @@
" - **x_test, y_test** : Validation or test data\n",
" - **x_test, y_test** : Validation or test data\n",
" - x_meta, y_meta : Illustration data\n",
" - x_meta, y_meta : Illustration data\n",
" \n",
" \n",
"The learning data will be randomly mixted and the illustration data sorted."
"The learning data will be randomly mixted and the illustration data sorted. \n",
"Will take about 2-3'"
]
]
},
},
{
{
...
@@ -440,7 +442,8 @@
...
@@ -440,7 +442,8 @@
"cell_type": "markdown",
"cell_type": "markdown",
"metadata": {},
"metadata": {},
"source": [
"source": [
"Create enhanced datasets, and save them..."
"Create enhanced datasets, and save them... \n",
"Will take about 7-8'"
]
]
},
},
{
{
...
...
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
German Traffic Sign Recognition Benchmark (GTSRB)
German Traffic Sign Recognition Benchmark (GTSRB)
=================================================
=================================================
---
---
Introduction au Deep Learning (IDLE) - S. Arias, E. Maldonado, JL. Parouty - CNRS/SARI/DEVLOG - 2020
Introduction au Deep Learning (IDLE) - S. Arias, E. Maldonado, JL. Parouty - CNRS/SARI/DEVLOG - 2020
Version: 1.12
## Episode 1 : Preparation of data
## Episode 1 : Preparation of data
-
Understanding the dataset
-
Understanding the dataset
-
Preparing and formatting enhanced data
-
Preparing and formatting enhanced data
-
Save enhanced datasets
-
Save enhanced datasets
in h5 file format
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## 1/ Import and init
## 1/ Import and init
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
import
os
,
time
,
sys
import
os
,
time
,
sys
import
csv
import
csv
import
math
,
random
import
math
,
random
import
numpy
as
np
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
import
h5py
import
h5py
from
skimage.morphology
import
disk
from
skimage.morphology
import
disk
from
skimage.filters
import
rank
from
skimage.filters
import
rank
from
skimage
import
io
,
color
,
exposure
,
transform
from
skimage
import
io
,
color
,
exposure
,
transform
import
idle.pwk
as
ooo
import
idle.pwk
as
ooo
from
importlib
import
reload
from
importlib
import
reload
reload
(
ooo
)
ooo
.
init
()
ooo
.
init
()
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## 2/ Read the dataset
## 2/ Read the dataset
Description is available there : http://benchmark.ini.rub.de/?section=gtsrb&subsection=dataset
Description is available there : http://benchmark.ini.rub.de/?section=gtsrb&subsection=dataset
-
Each directory contains one CSV file with annotations ("GT-
<ClassID>
.csv") and the training images
-
Each directory contains one CSV file with annotations ("GT-
<ClassID>
.csv") and the training images
-
First line is fieldnames: Filename;Width;Height;Roi.X1;Roi.Y1;Roi.X2;Roi.Y2;ClassId
-
First line is fieldnames: Filename;Width;Height;Roi.X1;Roi.Y1;Roi.X2;Roi.Y2;ClassId
### 2.1/ Usefull functions
### 2.1/ Usefull functions
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
def
read_dataset_dir
(
csv_filename
):
def
read_dataset_dir
(
csv_filename
):
'''
Reads traffic sign data from German Traffic Sign Recognition Benchmark dataset.
'''
Reads traffic sign data from German Traffic Sign Recognition Benchmark dataset.
Arguments: csv filename
Arguments: csv filename
Example /data/GTSRB/Train.csv
Example /data/GTSRB/Train.csv
Returns: np array of images, np array of corresponding labels
'''
Returns: np array of images, np array of corresponding labels
'''
# ---- csv filename and path
# ---- csv filename and path
#
#
name
=
os
.
path
.
basename
(
csv_filename
)
name
=
os
.
path
.
basename
(
csv_filename
)
path
=
os
.
path
.
dirname
(
csv_filename
)
path
=
os
.
path
.
dirname
(
csv_filename
)
# ---- Read csv file
# ---- Read csv file
#
#
f
,
x
,
y
=
[],[],[]
f
,
x
,
y
=
[],[],[]
with
open
(
csv_filename
)
as
csv_file
:
with
open
(
csv_filename
)
as
csv_file
:
reader
=
csv
.
DictReader
(
csv_file
,
delimiter
=
'
,
'
)
reader
=
csv
.
DictReader
(
csv_file
,
delimiter
=
'
,
'
)
for
row
in
reader
:
for
row
in
reader
:
f
.
append
(
path
+
'
/
'
+
row
[
'
Path
'
]
)
f
.
append
(
path
+
'
/
'
+
row
[
'
Path
'
]
)
y
.
append
(
int
(
row
[
'
ClassId
'
])
)
y
.
append
(
int
(
row
[
'
ClassId
'
])
)
csv_file
.
close
()
csv_file
.
close
()
nb_images
=
len
(
f
)
nb_images
=
len
(
f
)
# ---- Read images
# ---- Read images
#
#
for
filename
in
f
:
for
filename
in
f
:
image
=
io
.
imread
(
filename
)
image
=
io
.
imread
(
filename
)
x
.
append
(
image
)
x
.
append
(
image
)
ooo
.
update_progress
(
name
,
len
(
x
),
nb_images
)
ooo
.
update_progress
(
name
,
len
(
x
),
nb_images
)
# ---- Return
# ---- Return
#
#
return
np
.
array
(
x
),
np
.
array
(
y
)
return
np
.
array
(
x
),
np
.
array
(
y
)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### 2.2/ Read the data
### 2.2/ Read the data
We will read the following datasets:
We will read the following datasets:
-
**x_train, y_train**
: Learning data
-
**x_train, y_train**
: Learning data
-
**x_test, y_test**
: Validation or test data
-
**x_test, y_test**
: Validation or test data
-
x_meta, y_meta : Illustration data
-
x_meta, y_meta : Illustration data
The learning data will be randomly mixted and the illustration data sorted.
The learning data will be randomly mixted and the illustration data sorted.
Will take about 2-3'
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
%%
time
%%
time
# ---- Read datasets
# ---- Read datasets
(
x_train
,
y_train
)
=
read_dataset_dir
(
'
./data/origine/Train.csv
'
)
(
x_train
,
y_train
)
=
read_dataset_dir
(
'
./data/origine/Train.csv
'
)
(
x_test
,
y_test
)
=
read_dataset_dir
(
'
./data/origine/Test.csv
'
)
(
x_test
,
y_test
)
=
read_dataset_dir
(
'
./data/origine/Test.csv
'
)
(
x_meta
,
y_meta
)
=
read_dataset_dir
(
'
./data/origine/Meta.csv
'
)
(
x_meta
,
y_meta
)
=
read_dataset_dir
(
'
./data/origine/Meta.csv
'
)
# ---- Shuffle train set
# ---- Shuffle train set
combined
=
list
(
zip
(
x_train
,
y_train
))
combined
=
list
(
zip
(
x_train
,
y_train
))
random
.
shuffle
(
combined
)
random
.
shuffle
(
combined
)
x_train
,
y_train
=
zip
(
*
combined
)
x_train
,
y_train
=
zip
(
*
combined
)
# ---- Sort Meta
# ---- Sort Meta
combined
=
list
(
zip
(
x_meta
,
y_meta
))
combined
=
list
(
zip
(
x_meta
,
y_meta
))
combined
.
sort
(
key
=
lambda
x
:
x
[
1
])
combined
.
sort
(
key
=
lambda
x
:
x
[
1
])
x_meta
,
y_meta
=
zip
(
*
combined
)
x_meta
,
y_meta
=
zip
(
*
combined
)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## 3/ Few statistics about train dataset
## 3/ Few statistics about train dataset
We want to know if our images are homogeneous in terms of size, ratio, width or height.
We want to know if our images are homogeneous in terms of size, ratio, width or height.
### 3.1/ Do statistics
### 3.1/ Do statistics
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
train_size
=
[]
train_size
=
[]
train_ratio
=
[]
train_ratio
=
[]
train_lx
=
[]
train_lx
=
[]
train_ly
=
[]
train_ly
=
[]
test_size
=
[]
test_size
=
[]
test_ratio
=
[]
test_ratio
=
[]
test_lx
=
[]
test_lx
=
[]
test_ly
=
[]
test_ly
=
[]
for
image
in
x_train
:
for
image
in
x_train
:
(
lx
,
ly
,
lz
)
=
image
.
shape
(
lx
,
ly
,
lz
)
=
image
.
shape
train_size
.
append
(
lx
*
ly
/
1024
)
train_size
.
append
(
lx
*
ly
/
1024
)
train_ratio
.
append
(
lx
/
ly
)
train_ratio
.
append
(
lx
/
ly
)
train_lx
.
append
(
lx
)
train_lx
.
append
(
lx
)
train_ly
.
append
(
ly
)
train_ly
.
append
(
ly
)
for
image
in
x_test
:
for
image
in
x_test
:
(
lx
,
ly
,
lz
)
=
image
.
shape
(
lx
,
ly
,
lz
)
=
image
.
shape
test_size
.
append
(
lx
*
ly
/
1024
)
test_size
.
append
(
lx
*
ly
/
1024
)
test_ratio
.
append
(
lx
/
ly
)
test_ratio
.
append
(
lx
/
ly
)
test_lx
.
append
(
lx
)
test_lx
.
append
(
lx
)
test_ly
.
append
(
ly
)
test_ly
.
append
(
ly
)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### 3.2/ Show statistics
### 3.2/ Show statistics
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# ------ Global stuff
# ------ Global stuff
print
(
"
x_train size :
"
,
len
(
x_train
))
print
(
"
x_train size :
"
,
len
(
x_train
))
print
(
"
y_train size :
"
,
len
(
y_train
))
print
(
"
y_train size :
"
,
len
(
y_train
))
print
(
"
x_test size :
"
,
len
(
x_test
))
print
(
"
x_test size :
"
,
len
(
x_test
))
print
(
"
y_test size :
"
,
len
(
y_test
))
print
(
"
y_test size :
"
,
len
(
y_test
))
# ------ Statistics / sizes
# ------ Statistics / sizes
plt
.
figure
(
figsize
=
(
16
,
6
))
plt
.
figure
(
figsize
=
(
16
,
6
))
plt
.
hist
([
train_size
,
test_size
],
bins
=
100
)
plt
.
hist
([
train_size
,
test_size
],
bins
=
100
)
plt
.
gca
().
set
(
title
=
'
Sizes in Kpixels - Train=[{:5.2f}, {:5.2f}]
'
.
format
(
min
(
train_size
),
max
(
train_size
)),
plt
.
gca
().
set
(
title
=
'
Sizes in Kpixels - Train=[{:5.2f}, {:5.2f}]
'
.
format
(
min
(
train_size
),
max
(
train_size
)),
ylabel
=
'
Population
'
,
ylabel
=
'
Population
'
,
xlim
=
[
0
,
30
])
xlim
=
[
0
,
30
])
plt
.
legend
([
'
Train
'
,
'
Test
'
])
plt
.
legend
([
'
Train
'
,
'
Test
'
])
plt
.
show
()
plt
.
show
()
# ------ Statistics / ratio lx/ly
# ------ Statistics / ratio lx/ly
plt
.
figure
(
figsize
=
(
16
,
6
))
plt
.
figure
(
figsize
=
(
16
,
6
))
plt
.
hist
([
train_ratio
,
test_ratio
],
bins
=
100
)
plt
.
hist
([
train_ratio
,
test_ratio
],
bins
=
100
)
plt
.
gca
().
set
(
title
=
'
Ratio lx/ly - Train=[{:5.2f}, {:5.2f}]
'
.
format
(
min
(
train_ratio
),
max
(
train_ratio
)),
plt
.
gca
().
set
(
title
=
'
Ratio lx/ly - Train=[{:5.2f}, {:5.2f}]
'
.
format
(
min
(
train_ratio
),
max
(
train_ratio
)),
ylabel
=
'
Population
'
,
ylabel
=
'
Population
'
,
xlim
=
[
0.8
,
1.2
])
xlim
=
[
0.8
,
1.2
])
plt
.
legend
([
'
Train
'
,
'
Test
'
])
plt
.
legend
([
'
Train
'
,
'
Test
'
])
plt
.
show
()
plt
.
show
()
# ------ Statistics / lx
# ------ Statistics / lx
plt
.
figure
(
figsize
=
(
16
,
6
))
plt
.
figure
(
figsize
=
(
16
,
6
))
plt
.
hist
([
train_lx
,
test_lx
],
bins
=
100
)
plt
.
hist
([
train_lx
,
test_lx
],
bins
=
100
)
plt
.
gca
().
set
(
title
=
'
Images lx - Train=[{:5.2f}, {:5.2f}]
'
.
format
(
min
(
train_lx
),
max
(
train_lx
)),
plt
.
gca
().
set
(
title
=
'
Images lx - Train=[{:5.2f}, {:5.2f}]
'
.
format
(
min
(
train_lx
),
max
(
train_lx
)),
ylabel
=
'
Population
'
,
ylabel
=
'
Population
'
,
xlim
=
[
20
,
150
])
xlim
=
[
20
,
150
])
plt
.
legend
([
'
Train
'
,
'
Test
'
])
plt
.
legend
([
'
Train
'
,
'
Test
'
])
plt
.
show
()
plt
.
show
()
# ------ Statistics / ly
# ------ Statistics / ly
plt
.
figure
(
figsize
=
(
16
,
6
))
plt
.
figure
(
figsize
=
(
16
,
6
))
plt
.
hist
([
train_ly
,
test_ly
],
bins
=
100
)
plt
.
hist
([
train_ly
,
test_ly
],
bins
=
100
)
plt
.
gca
().
set
(
title
=
'
Images ly - Train=[{:5.2f}, {:5.2f}]
'
.
format
(
min
(
train_ly
),
max
(
train_ly
)),
plt
.
gca
().
set
(
title
=
'
Images ly - Train=[{:5.2f}, {:5.2f}]
'
.
format
(
min
(
train_ly
),
max
(
train_ly
)),
ylabel
=
'
Population
'
,
ylabel
=
'
Population
'
,
xlim
=
[
20
,
150
])
xlim
=
[
20
,
150
])
plt
.
legend
([
'
Train
'
,
'
Test
'
])
plt
.
legend
([
'
Train
'
,
'
Test
'
])
plt
.
show
()
plt
.
show
()
# ------ Statistics / classId
# ------ Statistics / classId
plt
.
figure
(
figsize
=
(
16
,
6
))
plt
.
figure
(
figsize
=
(
16
,
6
))
plt
.
hist
([
y_train
,
y_test
],
bins
=
43
)
plt
.
hist
([
y_train
,
y_test
],
bins
=
43
)
plt
.
gca
().
set
(
title
=
'
ClassesId
'
,
plt
.
gca
().
set
(
title
=
'
ClassesId
'
,
ylabel
=
'
Population
'
,
ylabel
=
'
Population
'
,
xlim
=
[
0
,
43
])
xlim
=
[
0
,
43
])
plt
.
legend
([
'
Train
'
,
'
Test
'
])
plt
.
legend
([
'
Train
'
,
'
Test
'
])
plt
.
show
()
plt
.
show
()
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## 4/ List of classes
## 4/ List of classes
What are the 43 classes of our images...
What are the 43 classes of our images...
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
ooo
.
plot_images
(
x_meta
,
y_meta
,
range
(
43
),
columns
=
8
,
x_size
=
2
,
y_size
=
2
,
ooo
.
plot_images
(
x_meta
,
y_meta
,
range
(
43
),
columns
=
8
,
x_size
=
2
,
y_size
=
2
,
colorbar
=
False
,
y_pred
=
None
,
cm
=
'
binary
'
)
colorbar
=
False
,
y_pred
=
None
,
cm
=
'
binary
'
)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## 5/ What does it really look like
## 5/ What does it really look like
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# ---- Get and show few images
# ---- Get and show few images
samples
=
[
random
.
randint
(
0
,
len
(
x_train
)
-
1
)
for
i
in
range
(
32
)]
samples
=
[
random
.
randint
(
0
,
len
(
x_train
)
-
1
)
for
i
in
range
(
32
)]
ooo
.
plot_images
(
x_train
,
y_train
,
samples
,
columns
=
8
,
x_size
=
2
,
y_size
=
2
,
colorbar
=
False
,
y_pred
=
None
,
cm
=
'
binary
'
)
ooo
.
plot_images
(
x_train
,
y_train
,
samples
,
columns
=
8
,
x_size
=
2
,
y_size
=
2
,
colorbar
=
False
,
y_pred
=
None
,
cm
=
'
binary
'
)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## 6/ dataset cooking...
## 6/ dataset cooking...
Images must have the
**same size**
to match the size of the network.
Images must have the
**same size**
to match the size of the network.
It is possible to work on
**rgb**
or
**monochrome**
images and
**equalize**
the histograms.
It is possible to work on
**rgb**
or
**monochrome**
images and
**equalize**
the histograms.
The data must be
**normalized**
.
The data must be
**normalized**
.
See :
[
Exposure with scikit-image
](
https://scikit-image.org/docs/dev/api/skimage.exposure.html
)
See :
[
Exposure with scikit-image
](
https://scikit-image.org/docs/dev/api/skimage.exposure.html
)
See :
[
Local histogram equalization
](
https://scikit-image.org/docs/dev/api/skimage.filters.rank.html#skimage.filters.rank.equalize
)
See :
[
Local histogram equalization
](
https://scikit-image.org/docs/dev/api/skimage.filters.rank.html#skimage.filters.rank.equalize
)
See :
[
Histogram equalization
](
https://scikit-image.org/docs/dev/api/skimage.exposure.html#skimage.exposure.equalize_hist
)
See :
[
Histogram equalization
](
https://scikit-image.org/docs/dev/api/skimage.exposure.html#skimage.exposure.equalize_hist
)
### 6.1/ Enhancement cook
### 6.1/ Enhancement cook
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
def
images_enhancement
(
images
,
width
=
25
,
height
=
25
,
mode
=
'
RGB
'
):
def
images_enhancement
(
images
,
width
=
25
,
height
=
25
,
mode
=
'
RGB
'
):
'''
'''
Resize and convert images - doesn
'
t change originals.
Resize and convert images - doesn
'
t change originals.
input images must be RGBA or RGB.
input images must be RGBA or RGB.
args:
args:
images : images list
images : images list
width,height : new images size (25,25)
width,height : new images size (25,25)
mode : RGB | RGB-HE | L | L-HE | L-LHE | L-CLAHE
mode : RGB | RGB-HE | L | L-HE | L-LHE | L-CLAHE
return:
return:
numpy array of enhanced images
numpy array of enhanced images
'''
'''
modes
=
{
'
RGB
'
:
3
,
'
RGB-HE
'
:
3
,
'
L
'
:
1
,
'
L-HE
'
:
1
,
'
L-LHE
'
:
1
,
'
L-CLAHE
'
:
1
}
modes
=
{
'
RGB
'
:
3
,
'
RGB-HE
'
:
3
,
'
L
'
:
1
,
'
L-HE
'
:
1
,
'
L-LHE
'
:
1
,
'
L-CLAHE
'
:
1
}
lz
=
modes
[
mode
]
lz
=
modes
[
mode
]
out
=
[]
out
=
[]
for
img
in
images
:
for
img
in
images
:
# ---- if RGBA, convert to RGB
# ---- if RGBA, convert to RGB
if
img
.
shape
[
2
]
==
4
:
if
img
.
shape
[
2
]
==
4
:
img
=
color
.
rgba2rgb
(
img
)
img
=
color
.
rgba2rgb
(
img
)
# ---- Resize
# ---- Resize
img
=
transform
.
resize
(
img
,
(
width
,
height
))
img
=
transform
.
resize
(
img
,
(
width
,
height
))
# ---- RGB / Histogram Equalization
# ---- RGB / Histogram Equalization
if
mode
==
'
RGB-HE
'
:
if
mode
==
'
RGB-HE
'
:
hsv
=
color
.
rgb2hsv
(
img
.
reshape
(
width
,
height
,
3
))
hsv
=
color
.
rgb2hsv
(
img
.
reshape
(
width
,
height
,
3
))
hsv
[:,
:,
2
]
=
exposure
.
equalize_hist
(
hsv
[:,
:,
2
])
hsv
[:,
:,
2
]
=
exposure
.
equalize_hist
(
hsv
[:,
:,
2
])
img
=
color
.
hsv2rgb
(
hsv
)
img
=
color
.
hsv2rgb
(
hsv
)
# ---- Grayscale
# ---- Grayscale
if
mode
==
'
L
'
:
if
mode
==
'
L
'
:
img
=
color
.
rgb2gray
(
img
)
img
=
color
.
rgb2gray
(
img
)
# ---- Grayscale / Histogram Equalization
# ---- Grayscale / Histogram Equalization
if
mode
==
'
L-HE
'
:
if
mode
==
'
L-HE
'
:
img
=
color
.
rgb2gray
(
img
)
img
=
color
.
rgb2gray
(
img
)
img
=
exposure
.
equalize_hist
(
img
)
img
=
exposure
.
equalize_hist
(
img
)
# ---- Grayscale / Local Histogram Equalization
# ---- Grayscale / Local Histogram Equalization
if
mode
==
'
L-LHE
'
:
if
mode
==
'
L-LHE
'
:
img
=
color
.
rgb2gray
(
img
)
img
=
color
.
rgb2gray
(
img
)
img
=
rank
.
equalize
(
img
,
disk
(
10
))
/
255.
img
=
rank
.
equalize
(
img
,
disk
(
10
))
/
255.
# ---- Grayscale / Contrast Limited Adaptive Histogram Equalization (CLAHE)
# ---- Grayscale / Contrast Limited Adaptive Histogram Equalization (CLAHE)
if
mode
==
'
L-CLAHE
'
:
if
mode
==
'
L-CLAHE
'
:
img
=
color
.
rgb2gray
(
img
)
img
=
color
.
rgb2gray
(
img
)
img
=
exposure
.
equalize_adapthist
(
img
)
img
=
exposure
.
equalize_adapthist
(
img
)
# ---- Add image in list of list
# ---- Add image in list of list
out
.
append
(
img
)
out
.
append
(
img
)
ooo
.
update_progress
(
'
Enhancement:
'
,
len
(
out
),
len
(
images
))
ooo
.
update_progress
(
'
Enhancement:
'
,
len
(
out
),
len
(
images
))
# ---- Reshape images
# ---- Reshape images
# (-1, width,height,1) for L
# (-1, width,height,1) for L
# (-1, width,height,3) for RGB
# (-1, width,height,3) for RGB
#
#
out
=
np
.
array
(
out
,
dtype
=
'
float64
'
)
out
=
np
.
array
(
out
,
dtype
=
'
float64
'
)
out
=
out
.
reshape
(
-
1
,
width
,
height
,
lz
)
out
=
out
.
reshape
(
-
1
,
width
,
height
,
lz
)
return
out
return
out
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### 6.2/ To get an idea of the different recipes
### 6.2/ To get an idea of the different recipes
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
i
=
random
.
randint
(
0
,
len
(
x_train
)
-
16
)
i
=
random
.
randint
(
0
,
len
(
x_train
)
-
16
)
x_samples
=
x_train
[
i
:
i
+
16
]
x_samples
=
x_train
[
i
:
i
+
16
]
y_samples
=
y_train
[
i
:
i
+
16
]
y_samples
=
y_train
[
i
:
i
+
16
]
datasets
=
{}
datasets
=
{}
datasets
[
'
RGB
'
]
=
images_enhancement
(
x_samples
,
width
=
25
,
height
=
25
,
mode
=
'
RGB
'
)
datasets
[
'
RGB
'
]
=
images_enhancement
(
x_samples
,
width
=
25
,
height
=
25
,
mode
=
'
RGB
'
)
datasets
[
'
RGB-HE
'
]
=
images_enhancement
(
x_samples
,
width
=
25
,
height
=
25
,
mode
=
'
RGB-HE
'
)
datasets
[
'
RGB-HE
'
]
=
images_enhancement
(
x_samples
,
width
=
25
,
height
=
25
,
mode
=
'
RGB-HE
'
)
datasets
[
'
L
'
]
=
images_enhancement
(
x_samples
,
width
=
25
,
height
=
25
,
mode
=
'
L
'
)
datasets
[
'
L
'
]
=
images_enhancement
(
x_samples
,
width
=
25
,
height
=
25
,
mode
=
'
L
'
)
datasets
[
'
L-HE
'
]
=
images_enhancement
(
x_samples
,
width
=
25
,
height
=
25
,
mode
=
'
L-HE
'
)
datasets
[
'
L-HE
'
]
=
images_enhancement
(
x_samples
,
width
=
25
,
height
=
25
,
mode
=
'
L-HE
'
)
datasets
[
'
L-LHE
'
]
=
images_enhancement
(
x_samples
,
width
=
25
,
height
=
25
,
mode
=
'
L-LHE
'
)
datasets
[
'
L-LHE
'
]
=
images_enhancement
(
x_samples
,
width
=
25
,
height
=
25
,
mode
=
'
L-LHE
'
)
datasets
[
'
L-CLAHE
'
]
=
images_enhancement
(
x_samples
,
width
=
25
,
height
=
25
,
mode
=
'
L-CLAHE
'
)
datasets
[
'
L-CLAHE
'
]
=
images_enhancement
(
x_samples
,
width
=
25
,
height
=
25
,
mode
=
'
L-CLAHE
'
)
print
(
'
\n
EXPECTED (Meta) :
\n
'
)
print
(
'
\n
EXPECTED (Meta) :
\n
'
)
x_expected
=
[
x_meta
[
i
]
for
i
in
y_samples
]
x_expected
=
[
x_meta
[
i
]
for
i
in
y_samples
]
ooo
.
plot_images
(
x_expected
,
y_samples
,
range
(
16
),
columns
=
16
,
x_size
=
1
,
y_size
=
1
,
colorbar
=
False
,
y_pred
=
None
,
cm
=
'
binary
'
)
ooo
.
plot_images
(
x_expected
,
y_samples
,
range
(
16
),
columns
=
16
,
x_size
=
1
,
y_size
=
1
,
colorbar
=
False
,
y_pred
=
None
,
cm
=
'
binary
'
)
print
(
'
\n
ORIGINAL IMAGES :
\n
'
)
print
(
'
\n
ORIGINAL IMAGES :
\n
'
)
ooo
.
plot_images
(
x_samples
,
y_samples
,
range
(
16
),
columns
=
16
,
x_size
=
1
,
y_size
=
1
,
colorbar
=
False
,
y_pred
=
None
,
cm
=
'
binary
'
)
ooo
.
plot_images
(
x_samples
,
y_samples
,
range
(
16
),
columns
=
16
,
x_size
=
1
,
y_size
=
1
,
colorbar
=
False
,
y_pred
=
None
,
cm
=
'
binary
'
)
print
(
'
\n
ENHANCED :
\n
'
)
print
(
'
\n
ENHANCED :
\n
'
)
for
k
,
d
in
datasets
.
items
():
for
k
,
d
in
datasets
.
items
():
print
(
"
dataset : {} min,max=[{:.3f},{:.3f}] shape={}
"
.
format
(
k
,
d
.
min
(),
d
.
max
(),
d
.
shape
))
print
(
"
dataset : {} min,max=[{:.3f},{:.3f}] shape={}
"
.
format
(
k
,
d
.
min
(),
d
.
max
(),
d
.
shape
))
ooo
.
plot_images
(
d
,
y_samples
,
range
(
16
),
columns
=
16
,
x_size
=
1
,
y_size
=
1
,
colorbar
=
False
,
y_pred
=
None
,
cm
=
'
binary
'
)
ooo
.
plot_images
(
d
,
y_samples
,
range
(
16
),
columns
=
16
,
x_size
=
1
,
y_size
=
1
,
colorbar
=
False
,
y_pred
=
None
,
cm
=
'
binary
'
)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### 6.3/ Cook and save
### 6.3/ Cook and save
A function to save a dataset
A function to save a dataset
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
def
save_h5_dataset
(
x_train
,
y_train
,
x_test
,
y_test
,
x_meta
,
y_meta
,
h5name
):
def
save_h5_dataset
(
x_train
,
y_train
,
x_test
,
y_test
,
x_meta
,
y_meta
,
h5name
):
# ---- Filename
# ---- Filename
filename
=
'
./data/
'
+
h5name
filename
=
'
./data/
'
+
h5name
# ---- Create h5 file
# ---- Create h5 file
with
h5py
.
File
(
filename
,
"
w
"
)
as
f
:
with
h5py
.
File
(
filename
,
"
w
"
)
as
f
:
f
.
create_dataset
(
"
x_train
"
,
data
=
x_train
)
f
.
create_dataset
(
"
x_train
"
,
data
=
x_train
)
f
.
create_dataset
(
"
y_train
"
,
data
=
y_train
)
f
.
create_dataset
(
"
y_train
"
,
data
=
y_train
)
f
.
create_dataset
(
"
x_test
"
,
data
=
x_test
)
f
.
create_dataset
(
"
x_test
"
,
data
=
x_test
)
f
.
create_dataset
(
"
y_test
"
,
data
=
y_test
)
f
.
create_dataset
(
"
y_test
"
,
data
=
y_test
)
f
.
create_dataset
(
"
x_meta
"
,
data
=
x_meta
)
f
.
create_dataset
(
"
x_meta
"
,
data
=
x_meta
)
f
.
create_dataset
(
"
y_meta
"
,
data
=
y_meta
)
f
.
create_dataset
(
"
y_meta
"
,
data
=
y_meta
)
# ---- done
# ---- done
size
=
os
.
path
.
getsize
(
filename
)
/
(
1024
*
1024
)
size
=
os
.
path
.
getsize
(
filename
)
/
(
1024
*
1024
)
print
(
'
Dataset : {:24s} shape : {:22s} size : {:6.1f} Mo (saved)
\n
'
.
format
(
filename
,
str
(
x_train
.
shape
),
size
))
print
(
'
Dataset : {:24s} shape : {:22s} size : {:6.1f} Mo (saved)
\n
'
.
format
(
filename
,
str
(
x_train
.
shape
),
size
))
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Create enhanced datasets, and save them...
Create enhanced datasets, and save them...
Will take about 7-8'
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
%%
time
%%
time
for
s
in
[
24
,
48
]:
for
s
in
[
24
,
48
]:
for
m
in
[
'
RGB
'
,
'
RGB-HE
'
,
'
L
'
,
'
L-LHE
'
]:
for
m
in
[
'
RGB
'
,
'
RGB-HE
'
,
'
L
'
,
'
L-LHE
'
]:
# ---- A nice dataset name
# ---- A nice dataset name
name
=
'
set-{}x{}-{}.h5
'
.
format
(
s
,
s
,
m
)
name
=
'
set-{}x{}-{}.h5
'
.
format
(
s
,
s
,
m
)
print
(
"
\n
Dataset :
"
,
name
)
print
(
"
\n
Dataset :
"
,
name
)
# ---- Enhancement
# ---- Enhancement
x_train_new
=
images_enhancement
(
x_train
,
width
=
s
,
height
=
s
,
mode
=
m
)
x_train_new
=
images_enhancement
(
x_train
,
width
=
s
,
height
=
s
,
mode
=
m
)
x_test_new
=
images_enhancement
(
x_test
,
width
=
s
,
height
=
s
,
mode
=
m
)
x_test_new
=
images_enhancement
(
x_test
,
width
=
s
,
height
=
s
,
mode
=
m
)
x_meta_new
=
images_enhancement
(
x_meta
,
width
=
s
,
height
=
s
,
mode
=
'
RGB
'
)
x_meta_new
=
images_enhancement
(
x_meta
,
width
=
s
,
height
=
s
,
mode
=
'
RGB
'
)
# ---- Save
# ---- Save
save_h5_dataset
(
x_train_new
,
y_train
,
x_test_new
,
y_test
,
x_meta_new
,
y_meta
,
name
)
save_h5_dataset
(
x_train_new
,
y_train
,
x_test_new
,
y_test
,
x_meta_new
,
y_meta
,
name
)
x_train_new
,
x_test_new
=
0
,
0
x_train_new
,
x_test_new
=
0
,
0
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## 7/ Reload data to be sure ;-)
## 7/ Reload data to be sure ;-)
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
%%
time
%%
time
dataset
=
'
set-48x48-L
'
dataset
=
'
set-48x48-L
'
samples
=
range
(
24
)
samples
=
range
(
24
)
with
h5py
.
File
(
'
./data/
'
+
dataset
+
'
.h5
'
)
as
f
:
with
h5py
.
File
(
'
./data/
'
+
dataset
+
'
.h5
'
)
as
f
:
x_tmp
=
f
[
'
x_train
'
][:]
x_tmp
=
f
[
'
x_train
'
][:]
y_tmp
=
f
[
'
y_train
'
][:]
y_tmp
=
f
[
'
y_train
'
][:]
print
(
"
dataset loaded from h5 file.
"
)
print
(
"
dataset loaded from h5 file.
"
)
ooo
.
plot_images
(
x_tmp
,
y_tmp
,
samples
,
columns
=
8
,
x_size
=
2
,
y_size
=
2
,
colorbar
=
False
,
y_pred
=
None
,
cm
=
'
binary
'
)
ooo
.
plot_images
(
x_tmp
,
y_tmp
,
samples
,
columns
=
8
,
x_size
=
2
,
y_size
=
2
,
colorbar
=
False
,
y_pred
=
None
,
cm
=
'
binary
'
)
x_tmp
,
y_tmp
=
0
,
0
x_tmp
,
y_tmp
=
0
,
0
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
----
----
That's all folks !
That's all folks !
...
...
This diff is collapsed.
Click to expand it.
GTSRB/02-First-convolutions.ipynb
+
327
−
77
View file @
f08fcc4c
source diff could not be displayed: it is too large. Options to address this:
view the blob
.
This diff is collapsed.
Click to expand it.
GTSRB/README.ipynb
+
5
−
2
View file @
f08fcc4c
...
@@ -24,14 +24,17 @@
...
@@ -24,14 +24,17 @@
"Environment, with the following packages :\n",
"Environment, with the following packages :\n",
" - Python 3.6\n",
" - Python 3.6\n",
" - numpy\n",
" - numpy\n",
" - Matplotlib\n",
" - Tensorflow 2.0\n",
" - Tensorflow 2.0\n",
" - scikit-image\n",
" - scikit-image\n",
" - scikit-learn\n",
" - Matplotlib\n",
" - seaborn\n",
" \n",
" \n",
"You can create it from the `environment.yml` file :\n",
"You can create it from the `environment.yml` file :\n",
"```\n",
"```\n",
"# conda env create -f environment.yml\n",
"# conda env create -f environment.yml\n",
"```\n",
"```\n",
"To manage conda environment see [there](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#) \n",
"\n",
"\n",
"About the dataset\n",
"About the dataset\n",
"-----------------\n",
"-----------------\n",
...
@@ -88,7 +91,7 @@
...
@@ -88,7 +91,7 @@
"name": "python",
"name": "python",
"nbconvert_exporter": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"pygments_lexer": "ipython3",
"version": "3.
6.9
"
"version": "3.
7.5
"
}
}
},
},
"nbformat": 4,
"nbformat": 4,
...
...
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
German Traffic Sign Recognition Benchmark (GTSRB)
German Traffic Sign Recognition Benchmark (GTSRB)
=================================================
=================================================
---
---
Introduction au Deep Learning (IDLE)
Introduction au Deep Learning (IDLE)
S. Aria, E. Maldonado, JL. Parouty
S. Aria, E. Maldonado, JL. Parouty
CNRS/SARI/DEVLOG - 2020
CNRS/SARI/DEVLOG - 2020
Objectives of this practical work
Objectives of this practical work
---------------------------------
---------------------------------
Traffic sign classification with
**CNN**
, using Tensorflow and
**Keras**
Traffic sign classification with
**CNN**
, using Tensorflow and
**Keras**
Prerequisite
Prerequisite
------------
------------
Environment, with the following packages :
Environment, with the following packages :
-
Python 3.6
-
Python 3.6
-
numpy
-
numpy
-
Matplotlib
-
Tensorflow 2.0
-
Tensorflow 2.0
-
scikit-image
-
scikit-image
-
scikit-learn
-
Matplotlib
-
seaborn
You can create it from the
`environment.yml`
file :
You can create it from the
`environment.yml`
file :
```
```
# conda env create -f environment.yml
# conda env create -f environment.yml
```
```
To manage conda environment see
[
there
](
https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#
)
About the dataset
About the dataset
-----------------
-----------------
Name :
[
German Traffic Sign Recognition Benchmark (GTSRB)
](
http://benchmark.ini.rub.de/?section=gtsrb
)
Name :
[
German Traffic Sign Recognition Benchmark (GTSRB)
](
http://benchmark.ini.rub.de/?section=gtsrb
)
Available
[
here
](
https://sid.erda.dk/public/archives/daaeac0d7ce1152aea9b61d9f1e19370/published-archive.html
)
Available
[
here
](
https://sid.erda.dk/public/archives/daaeac0d7ce1152aea9b61d9f1e19370/published-archive.html
)
or on
**[kaggle](https://www.kaggle.com/meowmeowmeowmeowmeow/gtsrb-german-traffic-sign)**
or on
**[kaggle](https://www.kaggle.com/meowmeowmeowmeowmeow/gtsrb-german-traffic-sign)**
A nice example from :
[
Alex Staravoitau
](
https://navoshta.com/traffic-signs-classification/
)
A nice example from :
[
Alex Staravoitau
](
https://navoshta.com/traffic-signs-classification/
)
In few words :
In few words :
-
Images : Variable dimensions, rgb
-
Images : Variable dimensions, rgb
-
Train set : 39209 images
-
Train set : 39209 images
-
Test set : 12630 images
-
Test set : 12630 images
-
Classes : 0 to 42
-
Classes : 0 to 42
Episodes
Episodes
--------
--------
**[01 - Preparation of data](01-Preparation-of-data.ipynb)**
**[01 - Preparation of data](01-Preparation-of-data.ipynb)**
-
Understanding the dataset
-
Understanding the dataset
-
Preparing and formatting data
-
Preparing and formatting data
-
Organize and backup data
-
Organize and backup data
**[02 - First convolutions](02-First-convolutions.ipynb)**
**[02 - First convolutions](02-First-convolutions.ipynb)**
-
Read dataset
-
Read dataset
-
Build a model
-
Build a model
-
Train the model
-
Train the model
-
Model evaluation
-
Model evaluation
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
```
```
...
...
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