Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.learn.tensorflow
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
bob
bob.learn.tensorflow
Merge requests
!47
Many changes
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
Many changes
amir
into
master
Overview
13
Commits
25
Pipelines
11
Changes
13
Merged
Amir MOHAMMADI
requested to merge
amir
into
master
7 years ago
Overview
13
Commits
25
Pipelines
11
Changes
13
Removing legacy code
Port to the new ci
Estimate the size of the tfrecords file that will be created
bug-fixes
Add a new architecture for patch-based CNN
Refactored the scripts to use the new click tools
Changed the compute_statistics script completely
Removed the unused predict_generic script
Removed the unused train script and renamed train_generic to train
Fixes
#50 (closed)
#52 (closed)
#48 (closed)
Edited
7 years ago
by
Amir MOHAMMADI
0
0
Merge request reports
Viewing commit
90b043a5
Prev
Next
Show latest version
13 files
+
581
−
617
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
13
90b043a5
Convert commands to click commands
· 90b043a5
Amir MOHAMMADI
authored
7 years ago
bob/learn/tensorflow/script/compute_statistics.py
+
31
−
27
View file @ 90b043a5
Edit in single-file editor
Open in Web IDE
Show full file
#!/usr/bin/env python
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
"""
Script that computes statistics for image.
# @author: Tiago de Freitas Pereira <tiago.pereira@idiap.ch>
# @date: Wed 11 May 2016 09:39:36 CEST
"""
"""
Script that computes statistics for image
from
__future__
import
absolute_import
from
__future__
import
division
Usage:
from
__future__
import
print_function
compute_statistics.py <base_path> <output_file> --extension=<arg>
# import pkg_resources so that bob imports work properly:
compute_statistics.py -h | --help
import
pkg_resources
Options:
-h --help Show this screen.
--extension=<arg> [default: .hdf5]
"""
from
docopt
import
docopt
import
bob.io.base
import
os
import
os
import
logging
import
click
import
numpy
import
numpy
import
bob.io.image
import
bob.io.image
# to be able to load images
from
bob.io.base
import
save
,
load
from
bob.extension.scripts.click_helper
import
verbosity_option
logger
=
logging
.
getLogger
(
__name__
)
def
process_images
(
base_path
,
extension
,
shape
):
def
process_images
(
base_path
,
extension
,
shape
):
files
=
os
.
listdir
(
base_path
)
files
=
os
.
listdir
(
base_path
)
sum_data
=
numpy
.
zeros
(
shape
=
shape
)
sum_data
=
numpy
.
zeros
(
shape
=
shape
)
print
(
"
Processing {0}
"
.
format
(
base_path
))
logging
.
info
(
"
Processing {0}
"
.
format
(
base_path
))
count
=
0
count
=
0
for
f
in
files
:
for
f
in
files
:
path
=
os
.
path
.
join
(
base_path
,
f
)
path
=
os
.
path
.
join
(
base_path
,
f
)
@@ -34,27 +31,34 @@ def process_images(base_path, extension, shape):
@@ -34,27 +31,34 @@ def process_images(base_path, extension, shape):
sum_data
+=
s
sum_data
+=
s
if
os
.
path
.
splitext
(
path
)[
1
]
==
extension
:
if
os
.
path
.
splitext
(
path
)[
1
]
==
extension
:
data
=
bob
.
io
.
base
.
load
(
path
)
data
=
load
(
path
)
count
+=
1
count
+=
1
sum_data
+=
data
sum_data
+=
data
return
count
,
sum_data
return
count
,
sum_data
def
main
():
@click.command
()
args
=
docopt
(
__doc__
,
version
=
'
Mnist training with TensorFlow
'
)
@click.argument
(
'
base_path
'
)
@click.argument
(
'
output_file
'
)
@click.option
(
'
--extension
'
,
default
=
'
.hdf5
'
,
show_default
=
True
)
@verbosity_option
()
def
compute_statistics
(
base_path
,
output_file
,
extension
,
**
kwargs
):
"""
Script that computes statistics for image.
"""
logger
.
debug
(
'
base_path: %s
'
,
base_path
)
logger
.
debug
(
'
output_file: %s
'
,
output_file
)
logger
.
debug
(
'
extension: %s
'
,
extension
)
logger
.
debug
(
'
kwargs: %s
'
,
kwargs
)
BASE_PATH
=
args
[
'
<base_path>
'
]
# SHAPE = [3, 224, 224]
EXTENSION
=
args
[
'
--extension
'
]
OUTPUT_FILE
=
args
[
'
<output_file>
'
]
#SHAPE = [3, 224, 224]
SHAPE
=
[
1
,
64
,
64
]
SHAPE
=
[
1
,
64
,
64
]
count
,
sum_data
=
process_images
(
BASE_PATH
,
EXTENSION
,
SHAPE
)
count
,
sum_data
=
process_images
(
base_path
,
extension
,
SHAPE
)
means
=
numpy
.
zeros
(
shape
=
SHAPE
)
means
=
numpy
.
zeros
(
shape
=
SHAPE
)
for
s
in
range
(
SHAPE
[
0
]):
for
s
in
range
(
SHAPE
[
0
]):
means
[
s
,
...]
=
sum_data
[
s
,
...]
/
float
(
count
)
means
[
s
,
...]
=
sum_data
[
s
,
...]
/
float
(
count
)
bob
.
io
.
base
.
save
(
means
,
OUTPUT_FILE
)
save
(
means
,
output_file
)
bob
.
io
.
base
.
save
(
means
[
0
,
:,
:].
astype
(
"
uint8
"
),
"
xuxa.png
"
)
save
(
means
[
0
,
:,
:].
astype
(
"
uint8
"
),
"
xuxa.png
"
)
Loading