Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Examples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
High Performance Computing
Examples
Commits
b2a1a55c
Commit
b2a1a55c
authored
7 months ago
by
Jannis Klinkenberg
Browse files
Options
Downloads
Patches
Plain Diff
implemented resizing
parent
ef4ef582
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tensorflow/cifar10/train_model.py
+24
-15
24 additions, 15 deletions
tensorflow/cifar10/train_model.py
tensorflow/cifar10_distributed/train_model.py
+25
-15
25 additions, 15 deletions
tensorflow/cifar10_distributed/train_model.py
with
49 additions
and
30 deletions
tensorflow/cifar10/train_model.py
+
24
−
15
View file @
b2a1a55c
...
...
@@ -50,13 +50,28 @@ def load_dataset(args):
x_train
-=
x_train_mean
x_test
-=
x_train_mean
print
(
"
x_train shape:
"
,
x_train
.
shape
)
print
(
"
y_train shape:
"
,
y_train
.
shape
)
print
(
x_train
.
shape
[
0
],
"
train samples
"
)
print
(
x_test
.
shape
[
0
],
"
test samples
"
)
sys
.
stdout
.
flush
()
# dimensions
print
(
f
"
original train_shape:
{
x_train
.
shape
}
"
)
print
(
f
"
original test_shape:
{
x_test
.
shape
}
"
)
n_train
,
n_test
=
x_train
.
shape
[
0
],
x_test
.
shape
[
0
]
resize_size
=
224
# use bigger images with ResNet
# Generating input pipelines
ds_train
=
(
tf
.
data
.
Dataset
.
from_tensor_slices
((
x_train
,
y_train
))
.
map
(
lambda
image
,
label
:
(
tf
.
image
.
resize
(
image
,
[
resize_size
,
resize_size
]),
label
))
.
shuffle
(
n_train
).
cache
().
batch
(
args
.
global_batches
).
prefetch
(
tf
.
data
.
AUTOTUNE
)
)
ds_test
=
(
tf
.
data
.
Dataset
.
from_tensor_slices
((
x_test
,
y_test
))
.
map
(
lambda
image
,
label
:
(
tf
.
image
.
resize
(
image
,
[
resize_size
,
resize_size
]),
label
))
.
shuffle
(
n_test
).
cache
().
batch
(
args
.
global_batches
).
prefetch
(
tf
.
data
.
AUTOTUNE
)
)
# get updated shapes
train_shape
,
test_shape
=
ds_train
.
element_spec
[
0
].
shape
,
ds_test
.
element_spec
[
0
].
shape
print
(
f
"
final train_shape:
{
train_shape
}
"
)
print
(
f
"
final test_shape:
{
test_shape
}
"
)
return
(
x_train
,
y
_train
)
,
(
x
_test
,
y_test
)
return
ds
_train
,
ds
_test
,
train_shape
def
setup
(
args
):
if
args
.
num_intraop_threads
:
...
...
@@ -84,19 +99,13 @@ def main():
# run setup (e.g., create distributed environment if desired)
setup
(
args
)
# data set loading
(
x_train
,
y_train
),
(
x_test
,
y_test
)
=
load_dataset
(
args
)
n_train
,
n_test
=
x_train
.
shape
[
0
],
x_test
.
shape
[
0
]
input_shape
=
x_train
.
shape
[
1
:]
# Generating input pipelines
ds_train
=
tf
.
data
.
Dataset
.
from_tensor_slices
((
x_train
,
y_train
)).
shuffle
(
n_train
).
cache
().
batch
(
args
.
batch_size
).
prefetch
(
tf
.
data
.
AUTOTUNE
)
ds_test
=
ds_test
=
tf
.
data
.
Dataset
.
from_tensor_slices
((
x_test
,
y_test
)).
shuffle
(
n_test
).
cache
().
batch
(
args
.
batch_size
).
prefetch
(
tf
.
data
.
AUTOTUNE
)
# loading desired dataset
ds_train
,
ds_test
,
train_shape
=
load_dataset
(
args
)
# callbacks to register
callbacks
=
[]
model
=
applications
.
ResNet50
(
weights
=
None
,
input_shape
=
input
_shape
,
classes
=
args
.
num_classes
)
model
=
applications
.
ResNet50
(
weights
=
None
,
input_shape
=
train
_shape
[
1
:]
,
classes
=
args
.
num_classes
)
# model.summary() # display the model architecture
cur_optimizer
=
Adam
(
0.001
)
model
.
compile
(
loss
=
"
categorical_crossentropy
"
,
optimizer
=
cur_optimizer
,
metrics
=
[
"
accuracy
"
])
...
...
This diff is collapsed.
Click to expand it.
tensorflow/cifar10_distributed/train_model.py
+
25
−
15
View file @
b2a1a55c
...
...
@@ -68,14 +68,30 @@ def load_dataset(args):
x_train
-=
x_train_mean
x_test
-=
x_train_mean
# dimensions
if
args
.
world_rank
==
0
:
print
(
"
x_train shape:
"
,
x_train
.
shape
)
print
(
"
y_train shape:
"
,
y_train
.
shape
)
print
(
x_train
.
shape
[
0
],
"
train samples
"
)
print
(
x_test
.
shape
[
0
],
"
test samples
"
)
sys
.
stdout
.
flush
()
print
(
f
"
original train_shape:
{
x_train
.
shape
}
"
)
print
(
f
"
original test_shape:
{
x_test
.
shape
}
"
)
n_train
,
n_test
=
x_train
.
shape
[
0
],
x_test
.
shape
[
0
]
resize_size
=
224
# use bigger images with ResNet
return
(
x_train
,
y_train
),
(
x_test
,
y_test
)
# Generating input pipelines
ds_train
=
(
tf
.
data
.
Dataset
.
from_tensor_slices
((
x_train
,
y_train
))
.
map
(
lambda
image
,
label
:
(
tf
.
image
.
resize
(
image
,
[
resize_size
,
resize_size
]),
label
))
.
shuffle
(
n_train
).
cache
().
batch
(
args
.
global_batches
).
prefetch
(
tf
.
data
.
AUTOTUNE
)
)
ds_test
=
(
tf
.
data
.
Dataset
.
from_tensor_slices
((
x_test
,
y_test
))
.
map
(
lambda
image
,
label
:
(
tf
.
image
.
resize
(
image
,
[
resize_size
,
resize_size
]),
label
))
.
shuffle
(
n_test
).
cache
().
batch
(
args
.
global_batches
).
prefetch
(
tf
.
data
.
AUTOTUNE
)
)
# get updated shapes
train_shape
,
test_shape
=
ds_train
.
element_spec
[
0
].
shape
,
ds_test
.
element_spec
[
0
].
shape
if
args
.
world_rank
==
0
:
print
(
f
"
final train_shape:
{
train_shape
}
"
)
print
(
f
"
final test_shape:
{
test_shape
}
"
)
return
ds_train
,
ds_test
,
train_shape
def
setup
(
args
):
if
args
.
num_intraop_threads
:
...
...
@@ -115,20 +131,14 @@ def main():
# run setup (e.g., create distributed environment if desired)
strategy
=
setup
(
args
)
# data set loading
(
x_train
,
y_train
),
(
x_test
,
y_test
)
=
load_dataset
(
args
)
n_train
,
n_test
=
x_train
.
shape
[
0
],
x_test
.
shape
[
0
]
input_shape
=
x_train
.
shape
[
1
:]
# Generating input pipelines
ds_train
=
tf
.
data
.
Dataset
.
from_tensor_slices
((
x_train
,
y_train
)).
shuffle
(
n_train
).
cache
().
batch
(
args
.
global_batches
).
prefetch
(
tf
.
data
.
AUTOTUNE
)
ds_test
=
ds_test
=
tf
.
data
.
Dataset
.
from_tensor_slices
((
x_test
,
y_test
)).
shuffle
(
n_test
).
cache
().
batch
(
args
.
global_batches
).
prefetch
(
tf
.
data
.
AUTOTUNE
)
# loading desired dataset
ds_train
,
ds_test
,
train_shape
=
load_dataset
(
args
)
# callbacks to register
callbacks
=
[]
with
strategy
.
scope
():
model
=
applications
.
ResNet50
(
weights
=
None
,
input_shape
=
input
_shape
,
classes
=
args
.
num_classes
)
model
=
applications
.
ResNet50
(
weights
=
None
,
input_shape
=
train
_shape
[
1
:]
,
classes
=
args
.
num_classes
)
# model.summary() # display the model architecture
cur_optimizer
=
Adam
(
0.001
)
model
.
compile
(
loss
=
"
categorical_crossentropy
"
,
optimizer
=
cur_optimizer
,
metrics
=
[
"
accuracy
"
])
...
...
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