Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
bob.learn.tensorflow
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
11
Issues
11
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bob
bob.learn.tensorflow
Commits
2a101a7e
Commit
2a101a7e
authored
Oct 17, 2016
by
Tiago de Freitas Pereira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Developing triplet selection
parent
f4b7c953
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
39 deletions
+66
-39
bob/learn/tensorflow/datashuffler/Base.py
bob/learn/tensorflow/datashuffler/Base.py
+7
-2
bob/learn/tensorflow/datashuffler/__init__.py
bob/learn/tensorflow/datashuffler/__init__.py
+2
-5
bob/learn/tensorflow/network/SequenceNetwork.py
bob/learn/tensorflow/network/SequenceNetwork.py
+4
-1
bob/learn/tensorflow/script/train_mnist_triplet.py
bob/learn/tensorflow/script/train_mnist_triplet.py
+29
-13
bob/learn/tensorflow/script/train_mobio.py
bob/learn/tensorflow/script/train_mobio.py
+18
-17
bob/learn/tensorflow/trainers/Trainer.py
bob/learn/tensorflow/trainers/Trainer.py
+6
-1
No files found.
bob/learn/tensorflow/datashuffler/Base.py
View file @
2a101a7e
...
...
@@ -112,8 +112,6 @@ class Base(object):
return
bob_image
def
rescale
(
self
,
data
):
"""
Reescale a single sample with input_shape
...
...
@@ -146,3 +144,10 @@ class Base(object):
return
dst
else
:
return
data
def
reshape_for_deploy
(
self
,
data
):
shape
=
tuple
([
1
]
+
list
(
data
.
shape
))
return
numpy
.
reshape
(
data
,
shape
)
bob/learn/tensorflow/datashuffler/__init__.py
View file @
2a101a7e
...
...
@@ -9,14 +9,11 @@ from .Disk import Disk
from
.SiameseMemory
import
SiameseMemory
from
.TripletMemory
import
TripletMemory
from
.TripletWithSelectionMemory
import
TripletWithSelectionMemory
from
.SiameseDisk
import
SiameseDisk
from
.TripletDisk
import
TripletDisk
# Data Augmentation
from
.DataAugmentation
import
DataAugmentation
from
.ImageAugmentation
import
ImageAugmentation
from
.TripletWithSelectionDisk
import
TripletWithSelectionDisk
# gets sphinx autodoc done right - don't remove it
__all__
=
[
_
for
_
in
dir
()
if
not
_
.
startswith
(
'_'
)]
bob/learn/tensorflow/network/SequenceNetwork.py
View file @
2a101a7e
...
...
@@ -102,7 +102,10 @@ class SequenceNetwork(six.with_metaclass(abc.ABCMeta, object)):
if
feature_layer
is
None
:
feature_layer
=
self
.
default_feature_layer
return
session
.
run
([
self
.
compute_graph
(
feature_placeholder
,
feature_layer
,
training
=
False
)],
feed_dict
=
feed_dict
)[
0
]
feature
=
session
.
run
([
self
.
compute_graph
(
feature_placeholder
,
feature_layer
,
training
=
False
)],
feed_dict
=
feed_dict
)[
0
]
del
feature_placeholder
return
feature
def
dump_variables
(
self
):
"""Return all the tensorflow `variables <https://www.tensorflow.org/versions/r0.11/api_docs/python/state_ops.html#Variable>`_ used in the graph
...
...
bob/learn/tensorflow/script/train_mnist_triplet.py
View file @
2a101a7e
...
...
@@ -22,7 +22,7 @@ from docopt import docopt
import
tensorflow
as
tf
from
..
import
util
SEED
=
10
from
bob.learn.tensorflow.data
import
MemoryDataShuffler
,
TextDataShuffler
from
bob.learn.tensorflow.data
shuffler
import
TripletMemory
,
TripletWithSelectionMemory
from
bob.learn.tensorflow.network
import
Lenet
,
MLP
,
LenetDropout
,
VGG
,
Chopra
,
Dummy
from
bob.learn.tensorflow.trainers
import
TripletTrainer
from
bob.learn.tensorflow.loss
import
TripletLoss
...
...
@@ -44,22 +44,37 @@ def main():
train_data
=
numpy
.
reshape
(
train_data
,
(
train_data
.
shape
[
0
],
28
,
28
,
1
))
validation_data
=
numpy
.
reshape
(
validation_data
,
(
validation_data
.
shape
[
0
],
28
,
28
,
1
))
train_data_shuffler
=
MemoryDataShuffler
(
train_data
,
train_labels
,
#train_data_shuffler = MemoryDataShuffler(train_data, train_labels,
# input_shape=[28, 28, 1],
# scale=True,
# batch_size=BATCH_SIZE)
#validation_data_shuffler = MemoryDataShuffler(validation_data, validation_labels,
# input_shape=[28, 28, 1],
# scale=True,
# batch_size=VALIDATION_BATCH_SIZE)
validation_data_shuffler
=
TripletMemory
(
train_data
,
train_labels
,
input_shape
=
[
28
,
28
,
1
],
scale
=
True
,
batch_size
=
BATCH_SIZE
)
batch_size
=
VALIDATION_
BATCH_SIZE
)
validation_data_shuffler
=
MemoryDataShuffler
(
validation_data
,
validatio
n_labels
,
train_data_shuffler
=
TripletWithSelectionMemory
(
train_data
,
trai
n_labels
,
input_shape
=
[
28
,
28
,
1
],
scale
=
True
,
batch_size
=
VALIDATION_BATCH_SIZE
)
batch_size
=
BATCH_SIZE
)
#train_data_shuffler = TripletMemory(train_data, train_labels,
# input_shape=[28, 28, 1],
# scale=True,
# batch_size=BATCH_SIZE)
# Preparing the architecture
n_classes
=
len
(
train_data_shuffler
.
possible_labels
)
#n_classes = 200
cnn
=
True
if
cnn
:
architecture
=
Chopra
(
seed
=
SEED
,
fc1_output
=
n_classes
)
architecture
=
Chopra
(
seed
=
SEED
,
fc1_output
=
n_classes
,
use_gpu
=
USE_GPU
)
#architecture = Lenet(default_feature_layer="fc2", n_classes=n_classes, conv1_output=8, conv2_output=16,use_gpu=USE_GPU)
#architecture = VGG(n_classes=n_classes, use_gpu=USE_GPU)
#architecture = Dummy(seed=SEED)
...
...
@@ -71,8 +86,8 @@ def main():
loss
=
loss
,
iterations
=
ITERATIONS
,
snapshot
=
VALIDATION_TEST
,
temp_dir
=
"
cnn-triplet
"
,
prefetch
=
Tru
e
,
temp_dir
=
"
triplet/cnn-triplet-SELECTION
"
,
prefetch
=
Fals
e
,
optimizer
=
optimizer
)
trainer
.
train
(
train_data_shuffler
,
validation_data_shuffler
)
...
...
@@ -86,5 +101,6 @@ def main():
temp_dir
=
"dnn-triplet"
,
iterations
=
ITERATIONS
,
snapshot
=
VALIDATION_TEST
)
trainer
.
train
(
train_data_shuffler
,
validation_data_shuffler
)
#trainer.train(train_data_shuffler, validation_data_shuffler)
trainer
.
train
(
train_data_shuffler
)
bob/learn/tensorflow/script/train_mobio.py
View file @
2a101a7e
...
...
@@ -22,7 +22,7 @@ from docopt import docopt
import
tensorflow
as
tf
from
..
import
util
SEED
=
10
from
bob.learn.tensorflow.data
import
MemoryDataShuffler
,
TextDataShuffler
from
bob.learn.tensorflow.data
shuffler
import
TripletWithSelectionDisk
,
TripletDisk
from
bob.learn.tensorflow.network
import
Lenet
,
MLP
,
LenetDropout
,
VGG
,
Chopra
,
Dummy
from
bob.learn.tensorflow.trainers
import
SiameseTrainer
,
Trainer
,
TripletTrainer
from
bob.learn.tensorflow.loss
import
ContrastiveLoss
,
BaseLoss
,
TripletLoss
...
...
@@ -53,7 +53,7 @@ def main():
directory
=
directory
,
extension
=
".hdf5"
)
for
o
in
train_objects
]
train_data_shuffler
=
T
extDataShuffler
(
train_file_names
,
train_labels
,
train_data_shuffler
=
T
ripletWithSelectionDisk
(
train_file_names
,
train_labels
,
input_shape
=
[
125
,
125
,
3
],
batch_size
=
BATCH_SIZE
)
...
...
@@ -66,12 +66,12 @@ def main():
directory
=
directory
,
extension
=
".hdf5"
)
for
o
in
validation_objects
]
validation_data_shuffler
=
T
extDataShuffler
(
validation_file_names
,
validation_labels
,
validation_data_shuffler
=
T
ripletDisk
(
validation_file_names
,
validation_labels
,
input_shape
=
[
125
,
125
,
3
],
batch_size
=
VALIDATION_BATCH_SIZE
)
# Preparing the architecture
#architecture = Chopra(seed=SEED, fc1_output=n_classes)
architecture
=
Chopra
(
seed
=
SEED
)
architecture
=
Chopra
(
seed
=
SEED
,
fc1_output
=
n_classes
)
optimizer
=
tf
.
train
.
GradientDescentOptimizer
(
0.00000001
)
...
...
@@ -82,18 +82,19 @@ def main():
# optimizer=optimizer,
# temp_dir="./LOGS/cnn")
loss
=
ContrastiveLoss
(
contrastive_margin
=
4.
)
trainer
=
SiameseTrainer
(
architecture
=
architecture
,
loss
=
loss
,
#loss = ContrastiveLoss(contrastive_margin=4.)
#trainer = SiameseTrainer(architecture=architecture, loss=loss,
# iterations=ITERATIONS,
# prefetch=False,
# optimizer=optimizer,
# temp_dir="./LOGS_MOBIO/siamese-cnn-prefetch")
loss
=
TripletLoss
(
margin
=
4.
)
trainer
=
TripletTrainer
(
architecture
=
architecture
,
loss
=
loss
,
iterations
=
ITERATIONS
,
prefetch
=
False
,
optimizer
=
optimizer
,
temp_dir
=
"./LOGS_MOBIO/siamese-cnn-prefetch"
)
#loss = TripletLoss(margin=4.)
#trainer = TripletTrainer(architecture=architecture, loss=loss,
# iterations=ITERATIONS,
# prefetch=True,
# optimizer=optimizer,
# temp_dir="./LOGS_MOBIO/triplet-cnn-prefetch")
temp_dir
=
"./LOGS_MOBIO/triplet-cnn"
)
trainer
.
train
(
train_data_shuffler
,
validation_data_shuffler
)
#trainer.train(train_data_shuffler, validation_data_shuffler)
trainer
.
train
(
train_data_shuffler
)
bob/learn/tensorflow/trainers/Trainer.py
View file @
2a101a7e
...
...
@@ -12,6 +12,8 @@ import bob.core
from
..analyzers
import
SoftmaxAnalizer
from
tensorflow.core.framework
import
summary_pb2
import
time
from
bob.learn.tensorflow.datashuffler.OnlineSampling
import
OnLineSampling
logger
=
bob
.
core
.
log
.
setup
(
"bob.learn.tensorflow"
)
...
...
@@ -277,6 +279,9 @@ class Trainer(object):
tf
.
initialize_all_variables
().
run
()
if
isinstance
(
train_data_shuffler
,
OnLineSampling
):
train_data_shuffler
.
set_feature_extractor
(
self
.
architecture
,
session
=
session
)
# Start a thread to enqueue data asynchronously, and hide I/O latency.
if
self
.
prefetch
:
self
.
thread_pool
=
tf
.
train
.
Coordinator
()
...
...
@@ -314,4 +319,4 @@ class Trainer(object):
self
.
thread_pool
.
request_stop
()
self
.
thread_pool
.
join
(
threads
)
session
.
close
()
# For some reason the session is not closed after the context manager finishes
session
.
close
()
# For some reason the session is not closed after the context manager finishes
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment