-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fail the build earlier. - Remove "clean" from the build. Makes it faster. - Use better variable names. - Make an internal method. - Add javadoc. - Remove unused variable. - Add `iter()` and `next()` built-ins. - Handle dataset iteration. - Add summary for `tf.keras.preprocessing.image.ImageDataGenerator.flow_from_directory()`.
- Loading branch information
Showing
12 changed files
with
237 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import tensorflow as tf | ||
|
||
|
||
def add(a, b): | ||
return a + b | ||
|
||
|
||
dataset = tf.data.Dataset.from_tensor_slices([1, 2, 3]) | ||
|
||
my_iter = iter(dataset) | ||
length = len(dataset) | ||
|
||
for _ in range(length): | ||
element = next(my_iter) | ||
add(element, element) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import tensorflow as tf | ||
|
||
|
||
def add(a, b): | ||
return a + b | ||
|
||
|
||
def f(a): | ||
return add(a, a) | ||
|
||
|
||
dataset = tf.data.Dataset.from_tensor_slices([1, 2, 3]) | ||
|
||
my_iter = iter(dataset) | ||
length = len(dataset) | ||
|
||
for _ in range(length): | ||
element = next(my_iter) | ||
f(element) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import tensorflow as tf | ||
|
||
|
||
def add(a, b): | ||
return a + b | ||
|
||
|
||
def f(a): | ||
return add(a, a) | ||
|
||
|
||
def g(a): | ||
element = next(a) | ||
return f(element) | ||
|
||
|
||
dataset = tf.data.Dataset.from_tensor_slices([1, 2, 3]) | ||
|
||
my_iter = iter(dataset) | ||
length = len(dataset) | ||
|
||
for _ in range(length): | ||
g(my_iter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# From https://github.com/YunYang1994/TensorFlow2.0-Examples/blob/299fd6689f242d0f647a96b8844e86325e9fcb46/7-Utils/multi_gpu_train.py. | ||
|
||
import tensorflow as tf | ||
from tensorflow.keras.preprocessing.image import ImageDataGenerator | ||
|
||
|
||
@tf.function | ||
def distributed_train_step(dataset_inputs): | ||
pass | ||
|
||
|
||
EPOCHS = 40 | ||
IMG_SIZE = 112 # Input Image Size | ||
BATCH_SIZE = 512 # Total 4 GPU, 128 batch per GPU | ||
|
||
train_datagen = ImageDataGenerator( | ||
rescale=1.0 / 255, shear_range=0.2, zoom_range=0.2, horizontal_flip=False | ||
) | ||
|
||
train_generator = train_datagen.flow_from_directory( | ||
"./mnist/train", | ||
target_size=(IMG_SIZE, IMG_SIZE), | ||
batch_size=BATCH_SIZE, | ||
class_mode="categorical", | ||
) | ||
|
||
for epoch in range(1, EPOCHS + 1): | ||
batchs_per_epoch = len(train_generator) | ||
train_dataset = iter(train_generator) | ||
|
||
for _ in range(batchs_per_epoch): | ||
batch_loss = distributed_train_step(next(train_dataset)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.