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
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
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
Slim Karkar
Fidle
Commits
e41ca86b
Commit
e41ca86b
authored
5 years ago
by
Jean-Luc Parouty Jean-Luc.Parouty@simap.grenoble-inp.fr
Browse files
Options
Downloads
Patches
Plain Diff
Minor change
parent
7fb667b1
No related branches found
No related tags found
No related merge requests found
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GTSRB/02.1-First-convolutions.ipynb
+25
-35
25 additions, 35 deletions
GTSRB/02.1-First-convolutions.ipynb
GTSRB/03-Tracking-and-visualizing.ipynb
+348
-0
348 additions, 0 deletions
GTSRB/03-Tracking-and-visualizing.ipynb
with
373 additions
and
35 deletions
GTSRB/02.1-First-convolutions.ipynb
+
25
−
35
View file @
e41ca86b
...
...
@@ -34,7 +34,7 @@
"text": [
"IDLE 2020 - Practical Work Module\n",
" Version : 0.1.1\n",
" Run time :
Su
nday
5
January 2020,
20:14:03
\n",
" Run time :
Mo
nday
6
January 2020,
14:35:14
\n",
" Matplotlib style : idle/talk.mplstyle\n",
" TensorFlow version : 2.0.0\n",
" Keras version : 2.2.4-tf\n"
...
...
@@ -68,7 +68,7 @@
},
{
"cell_type": "code",
"execution_count":
16
,
"execution_count":
2
,
"metadata": {},
"outputs": [
{
...
...
@@ -77,8 +77,8 @@
"text": [
"Dataset loaded, size=742.0 Mo\n",
"\n",
"CPU times: user 0 ns, sys:
824
ms, total:
824
ms\n",
"Wall time:
3.38
s\n"
"CPU times: user 0 ns, sys:
708
ms, total:
708
ms\n",
"Wall time:
6.07
s\n"
]
}
],
...
...
@@ -116,7 +116,7 @@
},
{
"cell_type": "code",
"execution_count":
17
,
"execution_count":
3
,
"metadata": {},
"outputs": [
{
...
...
@@ -173,18 +173,18 @@
},
{
"cell_type": "code",
"execution_count": 5
6
,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"batch_size = 128\n",
"num_classes = 43\n",
"epochs =
10
"
"epochs =
5
"
]
},
{
"cell_type": "code",
"execution_count":
57
,
"execution_count":
6
,
"metadata": {},
"outputs": [
{
...
...
@@ -245,7 +245,7 @@
},
{
"cell_type": "code",
"execution_count":
58
,
"execution_count":
7
,
"metadata": {},
"outputs": [
{
...
...
@@ -253,28 +253,18 @@
"output_type": "stream",
"text": [
"Train on 39209 samples, validate on 12630 samples\n",
"Epoch 1/10\n",
"39209/39209 [==============================] - 4s 92us/sample - loss: 0.9183 - accuracy: 0.7400 - val_loss: 0.3855 - val_accuracy: 0.9032\n",
"Epoch 2/10\n",
"39209/39209 [==============================] - 3s 77us/sample - loss: 0.0895 - accuracy: 0.9770 - val_loss: 0.3091 - val_accuracy: 0.9251\n",
"Epoch 3/10\n",
"39209/39209 [==============================] - 3s 78us/sample - loss: 0.0400 - accuracy: 0.9895 - val_loss: 0.2527 - val_accuracy: 0.9367\n",
"Epoch 4/10\n",
"39209/39209 [==============================] - 3s 78us/sample - loss: 0.0278 - accuracy: 0.9922 - val_loss: 0.2833 - val_accuracy: 0.9399\n",
"Epoch 5/10\n",
"39209/39209 [==============================] - 3s 77us/sample - loss: 0.0182 - accuracy: 0.9952 - val_loss: 0.2724 - val_accuracy: 0.9473\n",
"Epoch 6/10\n",
"39209/39209 [==============================] - 3s 75us/sample - loss: 0.0132 - accuracy: 0.9963 - val_loss: 0.2321 - val_accuracy: 0.9469\n",
"Epoch 7/10\n",
"39209/39209 [==============================] - 3s 77us/sample - loss: 0.0198 - accuracy: 0.9944 - val_loss: 0.2921 - val_accuracy: 0.9390\n",
"Epoch 8/10\n",
"39209/39209 [==============================] - 3s 78us/sample - loss: 0.0169 - accuracy: 0.9958 - val_loss: 0.2827 - val_accuracy: 0.9444\n",
"Epoch 9/10\n",
"39209/39209 [==============================] - 3s 78us/sample - loss: 0.0217 - accuracy: 0.9939 - val_loss: 0.2007 - val_accuracy: 0.9565\n",
"Epoch 10/10\n",
"39209/39209 [==============================] - 3s 78us/sample - loss: 0.0119 - accuracy: 0.9968 - val_loss: 0.1834 - val_accuracy: 0.9628\n",
"CPU times: user 43.7 s, sys: 4.45 s, total: 48.2 s\n",
"Wall time: 30.9 s\n"
"Epoch 1/5\n",
"39209/39209 [==============================] - 18s 468us/sample - loss: 0.9595 - accuracy: 0.7357 - val_loss: 0.4068 - val_accuracy: 0.9015\n",
"Epoch 2/5\n",
"39209/39209 [==============================] - 16s 417us/sample - loss: 0.0876 - accuracy: 0.9770 - val_loss: 0.3472 - val_accuracy: 0.9190\n",
"Epoch 3/5\n",
"39209/39209 [==============================] - 16s 409us/sample - loss: 0.0375 - accuracy: 0.9900 - val_loss: 0.2917 - val_accuracy: 0.9363\n",
"Epoch 4/5\n",
"39209/39209 [==============================] - 17s 421us/sample - loss: 0.0263 - accuracy: 0.9928 - val_loss: 0.3384 - val_accuracy: 0.9284\n",
"Epoch 5/5\n",
"39209/39209 [==============================] - 17s 421us/sample - loss: 0.0237 - accuracy: 0.9929 - val_loss: 0.3022 - val_accuracy: 0.9433\n",
"CPU times: user 16min 31s, sys: 1min 27s, total: 17min 59s\n",
"Wall time: 1min 23s\n"
]
}
],
...
...
@@ -297,15 +287,15 @@
},
{
"cell_type": "code",
"execution_count":
59
,
"execution_count":
8
,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Test loss : 0.
1834
\n",
"Test accuracy : 0.9
628
\n"
"Test loss : 0.
3022
\n",
"Test accuracy : 0.9
433
\n"
]
}
],
...
...
@@ -324,7 +314,7 @@
"### Results : \n",
"```\n",
"L25 : size=250 Mo 93.15% \n",
"RGB25 : size=740 Mo 9
5.42
%\n",
"RGB25 : size=740 Mo 9
4.33
%\n",
"...\n",
"```"
]
...
...
%% Cell type:markdown id: tags:
German Traffic Sign Recognition Benchmark (GTSRB)
=================================================
---
Introduction au Deep Learning (IDLE) - S. Aria, E. Maldonado, JL. Parouty - CNRS/SARI/DEVLOG -
2020
## Episode 2 : First Convolutions
Our main steps
:
-
Read dataset
-
Build a model
-
Train the model
-
Model evaluation
## 1/ Import and init
%% Cell type:code id: tags
:
```
python
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.callbacks import TensorBoard
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import time
import idle.pwk as ooo
ooo.init()
```
%%
Output
IDLE 2020 - Practical Work Module
Version
:
0.1.1
Run time
:
Su
nday
5
January 2020,
20:14:03
Run time
:
Mo
nday
6
January 2020,
14:35:14
Matplotlib style
:
idle/talk.mplstyle
TensorFlow version
:
2.0.0
Keras version
:
2.2.4-tf
%% Cell type:markdown id: tags
:
## 2/ Reload dataset (RGB25)
Dataset is one of the saved dataset
:
RGB25, RGB35, L25, L35, etc.
First of all, we're going to use the dataset
:
*
*L25
**
(with a GPU, it only takes 35'' compared to more than 5' with a CPU !)
%% Cell type:code id: tags
:
```
python
%%
time
dataset ='RGB25'
img_lx =
25
img_ly =
25
img_lz =
3
# ---- Read dataset
x_train = np.load('./data/{}/x_train.npy'.format(dataset))
y_train = np.load('./data/{}/y_train.npy'.format(dataset))
x_test = np.load('./data/{}/x_test.npy'.format(dataset))
y_test = np.load('./data/{}/y_test.npy'.format(dataset))
# ---- Reshape data
x_train = x_train.reshape( x_train.shape[0], img_lx, img_ly, img_lz)
x_test = x_test.reshape( x_test.shape[0], img_lx, img_ly, img_lz)
input_shape = (img_lx, img_ly, img_lz)
print("Dataset loaded, size={:.1f} Mo\n".format(ooo.get_directory_size('./data/'+dataset)))
```
%%
Output
Dataset loaded, size=742.0 Mo
CPU times
:
user 0 ns, sys
:
824
ms, total
:
824
ms
Wall time
:
3.38
s
CPU times
:
user 0 ns, sys
:
708
ms, total
:
708
ms
Wall time
:
6.07
s
%% Cell type:markdown id: tags
:
## 3/ Have a look to the dataset
Note
:
Data must be reshape for matplotlib
%% Cell type:code id: tags
:
```
python
print("x_train
:
"
,
x_train.shape)
print("
y_train
:
"
,
y_train.shape)
print("
x_test
:
"
,
x_test.shape)
print("
y_test
:
"
,
y_test.shape)
if
img_lz>1:
ooo.plot_images(x_train.reshape(-1,img_lx,img_ly,img_lz),
y_train,
range(6),
columns=3,
x_size=4,
y_size=3)
ooo.plot_images(x_train.reshape(-1,img_lx,img_ly,img_lz),
y_train,
range(36),
columns=12,
x_size=1,
y_size=1)
else:
ooo.plot_images(x_train.reshape(-1,img_lx,img_ly),
y_train,
range(6),
columns=6,
x_size=2,
y_size=2)
ooo.plot_images(x_train.reshape(-1,img_lx,img_ly),
y_train,
range(36),
columns=12,
x_size=1,
y_size=1)
```
%%
Output
x_train
:
(39209,
25,
25,
3)
y_train
:
(39209,)
x_test
:
(12630,
25,
25,
3)
y_test
:
(12630,)
%%
Cell
type:markdown
id:
tags:
##
4/
Create
model
%%
Cell
type:code
id:
tags:
```
python
batch_size
=
128
num_classes
=
43
epochs
=
10
epochs
=
5
```
%%
Cell
type:code
id:
tags:
```
python
keras.backend.clear_session()
model
=
keras.models.Sequential()
model.add(
keras.layers.Conv2D(96,
(3,3),
activation='relu',
input_shape=(img_lx,
img_ly,
img_lz)))
model.add(
keras.layers.MaxPooling2D((2,
2)))
model.add(
keras.layers.Conv2D(192,
(3,
3),
activation='relu'))
model.add(
keras.layers.MaxPooling2D((2,
2)))
model.add(
keras.layers.Flatten())
model.add(
keras.layers.Dense(3072,
activation='relu'))
model.add(
keras.layers.Dense(500,
activation='relu'))
model.add(
keras.layers.Dense(43,
activation='softmax'))
model.summary()
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
```
%%
Output
Model:
"sequential"
_________________________________________________________________
Layer (type) Output Shape Param
#
=================================================================
conv2d (Conv2D) (None, 23, 23, 96)
2688
_________________________________________________________________
max_pooling2d (MaxPooling2D) (None, 11, 11, 96)
0
_________________________________________________________________
conv2d_1 (Conv2D) (None, 9, 9, 192)
166080
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 4, 4, 192)
0
_________________________________________________________________
flatten (Flatten) (None, 3072)
0
_________________________________________________________________
dense (Dense) (None, 3072)
9440256
_________________________________________________________________
dense_1 (Dense) (None, 500)
1536500
_________________________________________________________________
dense_2 (Dense) (None, 43)
21543
=================================================================
Total params
:
11,167,067
Trainable params
:
11,167,067
Non-trainable params
:
0
_________________________________________________________________
%% Cell type:markdown id: tags
:
## 5/ Run model
%% Cell type:code id: tags
:
```
python
%%
time
history = model.fit( x_train, y_train,
batch_size=batch_size,
epochs=epochs,
verbose=1,
validation_data=(x_test, y_test))
```
%%
Output
Train on 39209 samples, validate on 12630 samples
Epoch 1/10
39209/39209 [==============================] - 4s 92us/sample - loss
: 0.9183 - accuracy: 0.7400 - val_loss: 0.3855 - val_accuracy
:
0.9032
Epoch 2/10
39209/39209 [==============================] - 3s 77us/sample - loss
: 0.0895 - accuracy: 0.9770 - val_loss: 0.3091 - val_accuracy
:
0.9251
Epoch 3/10
39209/39209 [==============================] - 3s 78us/sample - loss
: 0.0400 - accuracy: 0.9895 - val_loss: 0.2527 - val_accuracy
:
0.9367
Epoch 4/10
39209/39209 [==============================] - 3s 78us/sample - loss
: 0.0278 - accuracy: 0.9922 - val_loss: 0.2833 - val_accuracy
:
0.9399
Epoch 5/10
39209/39209 [==============================] - 3s 77us/sample - loss
: 0.0182 - accuracy: 0.9952 - val_loss: 0.2724 - val_accuracy
:
0.9473
Epoch 6/10
39209/39209 [==============================] - 3s 75us/sample - loss
: 0.0132 - accuracy: 0.9963 - val_loss: 0.2321 - val_accuracy
:
0.9469
Epoch 7/10
39209/39209 [==============================] - 3s 77us/sample - loss
: 0.0198 - accuracy: 0.9944 - val_loss: 0.2921 - val_accuracy
:
0.9390
Epoch 8/10
39209/39209 [==============================] - 3s 78us/sample - loss
: 0.0169 - accuracy: 0.9958 - val_loss: 0.2827 - val_accuracy
:
0.9444
Epoch 9/10
39209/39209 [==============================] - 3s 78us/sample - loss
: 0.0217 - accuracy: 0.9939 - val_loss: 0.2007 - val_accuracy
:
0.9565
Epoch 10/10
39209/39209 [==============================] - 3s 78us/sample - loss
: 0.0119 - accuracy: 0.9968 - val_loss: 0.1834 - val_accuracy
:
0.9628
CPU times
:
user 43.7 s, sys
:
4.45 s, total
:
48.2 s
Wall time
:
30.9 s
Epoch 1/5
39209/39209 [==============================] - 18s 468us/sample - loss
: 0.9595 - accuracy: 0.7357 - val_loss: 0.4068 - val_accuracy
:
0.9015
Epoch 2/5
39209/39209 [==============================] - 16s 417us/sample - loss
: 0.0876 - accuracy: 0.9770 - val_loss: 0.3472 - val_accuracy
:
0.9190
Epoch 3/5
39209/39209 [==============================] - 16s 409us/sample - loss
: 0.0375 - accuracy: 0.9900 - val_loss: 0.2917 - val_accuracy
:
0.9363
Epoch 4/5
39209/39209 [==============================] - 17s 421us/sample - loss
: 0.0263 - accuracy: 0.9928 - val_loss: 0.3384 - val_accuracy
:
0.9284
Epoch 5/5
39209/39209 [==============================] - 17s 421us/sample - loss
: 0.0237 - accuracy: 0.9929 - val_loss: 0.3022 - val_accuracy
:
0.9433
CPU times
:
user 16min 31s, sys
:
1min 27s, total
:
17min 59s
Wall time
:
1min 23s
%% Cell type:markdown id: tags
:
## 6/ Evaluation
%% Cell type:code id: tags
:
```
python
score = model.evaluate(x_test, y_test, verbose=0)
print('Test loss
:
{:
5.4f
}
'
.format(score[0]))
print('
Test accuracy
:
{:
5.4f
}
'
.format(score[1]))
```
%%
Output
Test
loss
:
0.
1834
Test
accuracy
:
0.9
628
Test
loss
:
0.
3022
Test
accuracy
:
0.9
433
%%
Cell
type:markdown
id:
tags:
---
### Results :
```
L25 : size=250 Mo 93.15%
RGB25 : size=740 Mo 9
5.42
%
RGB25 : size=740 Mo 9
4.33
%
...
```
%% Cell type:code id: tags:
```
python
```
...
...
This diff is collapsed.
Click to expand it.
GTSRB/03-Tracking-and-visualizing.ipynb
0 → 100644
+
348
−
0
View file @
e41ca86b
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