Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
dcuai
dlexamples
Commits
0016b0a7
Commit
0016b0a7
authored
Jan 11, 2023
by
sunxx1
Browse files
Merge branch 'dtk22.04' into 'main'
Dtk22.04 See merge request dcutoolkit/deeplearing/dlexamples_new!49
parents
17bc28d5
7a382d5d
Changes
335
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
762 additions
and
0 deletions
+762
-0
Keras/keras-cv/examples/layers/preprocessing/bounding_box/visualization_demo.py
...s/layers/preprocessing/bounding_box/visualization_demo.py
+26
-0
Keras/keras-cv/examples/layers/preprocessing/classification/aug_mix_demo.py
...mples/layers/preprocessing/classification/aug_mix_demo.py
+35
-0
Keras/keras-cv/examples/layers/preprocessing/classification/channel_shuffle_demo.py
...yers/preprocessing/classification/channel_shuffle_demo.py
+35
-0
Keras/keras-cv/examples/layers/preprocessing/classification/cut_mix_demo.py
...mples/layers/preprocessing/classification/cut_mix_demo.py
+35
-0
Keras/keras-cv/examples/layers/preprocessing/classification/demo_utils.py
...xamples/layers/preprocessing/classification/demo_utils.py
+73
-0
Keras/keras-cv/examples/layers/preprocessing/classification/fourier_mix_demo.py
...s/layers/preprocessing/classification/fourier_mix_demo.py
+34
-0
Keras/keras-cv/examples/layers/preprocessing/classification/grid_mask_demo.py
...les/layers/preprocessing/classification/grid_mask_demo.py
+40
-0
Keras/keras-cv/examples/layers/preprocessing/classification/mix_up_demo.py
...amples/layers/preprocessing/classification/mix_up_demo.py
+34
-0
Keras/keras-cv/examples/layers/preprocessing/classification/mosaic_demo.py
...amples/layers/preprocessing/classification/mosaic_demo.py
+35
-0
Keras/keras-cv/examples/layers/preprocessing/classification/rand_augment_demo.py
.../layers/preprocessing/classification/rand_augment_demo.py
+36
-0
Keras/keras-cv/examples/layers/preprocessing/classification/random_augmentation_pipeline_demo.py
...ssing/classification/random_augmentation_pipeline_demo.py
+45
-0
Keras/keras-cv/examples/layers/preprocessing/classification/random_channel_shift_demo.py
...preprocessing/classification/random_channel_shift_demo.py
+35
-0
Keras/keras-cv/examples/layers/preprocessing/classification/random_color_degeneration_demo.py
...ocessing/classification/random_color_degeneration_demo.py
+34
-0
Keras/keras-cv/examples/layers/preprocessing/classification/random_color_jitter_demo.py
.../preprocessing/classification/random_color_jitter_demo.py
+42
-0
Keras/keras-cv/examples/layers/preprocessing/classification/random_crop_and_zoom.py
...yers/preprocessing/classification/random_crop_and_zoom.py
+46
-0
Keras/keras-cv/examples/layers/preprocessing/classification/random_cutout_demo.py
...layers/preprocessing/classification/random_cutout_demo.py
+38
-0
Keras/keras-cv/examples/layers/preprocessing/classification/random_gaussian_blur_demo.py
...preprocessing/classification/random_gaussian_blur_demo.py
+35
-0
Keras/keras-cv/examples/layers/preprocessing/classification/random_hue_demo.py
...es/layers/preprocessing/classification/random_hue_demo.py
+33
-0
Keras/keras-cv/examples/layers/preprocessing/classification/random_saturation_demo.py
...rs/preprocessing/classification/random_saturation_demo.py
+34
-0
Keras/keras-cv/examples/layers/preprocessing/classification/random_shear_demo.py
.../layers/preprocessing/classification/random_shear_demo.py
+37
-0
No files found.
Keras/keras-cv/examples/layers/preprocessing/bounding_box/visualization_demo.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
visualization_demo.py is used to visualize the dataset with bounding boxes.
"""
import
demo_utils
def
main
():
inputs
=
demo_utils
.
load_voc_dataset
(
bounding_box_format
=
"rel_xyxy"
)
demo_utils
.
visualize_data
(
inputs
,
bounding_box_format
=
"rel_xyxy"
)
if
__name__
==
"__main__"
:
main
()
Keras/keras-cv/examples/layers/preprocessing/classification/aug_mix_demo.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""aug_mix_demo.py shows how to use the AugMix preprocessing layer.
Operates on the oxford_flowers102 dataset. In this script the flowers
are loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import
demo_utils
import
tensorflow
as
tf
from
keras_cv
import
layers
def
main
():
augmix
=
layers
.
AugMix
(
value_range
=
[
0
,
255
])
ds
=
demo_utils
.
load_oxford_dataset
()
ds
=
ds
.
map
(
augmix
,
num_parallel_calls
=
tf
.
data
.
AUTOTUNE
)
demo_utils
.
visualize_dataset
(
ds
)
if
__name__
==
"__main__"
:
main
()
Keras/keras-cv/examples/layers/preprocessing/classification/channel_shuffle_demo.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""channel_shuffle_demo.py shows how to use the ChannelShuffle preprocessing layer.
Operates on the oxford_flowers102 dataset. In this script the flowers
are loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import
demo_utils
import
tensorflow
as
tf
from
keras_cv
import
layers
def
main
():
channel_shuffle
=
layers
.
ChannelShuffle
()
ds
=
demo_utils
.
load_oxford_dataset
()
ds
=
ds
.
map
(
channel_shuffle
,
num_parallel_calls
=
tf
.
data
.
AUTOTUNE
)
demo_utils
.
visualize_dataset
(
ds
)
if
__name__
==
"__main__"
:
main
()
Keras/keras-cv/examples/layers/preprocessing/classification/cut_mix_demo.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""cut_mix_demo.py shows how to use the CutMix preprocessing layer.
Operates on the oxford_flowers102 dataset. In this script the flowers
are loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import
demo_utils
import
tensorflow
as
tf
from
keras_cv
import
layers
def
main
():
cutmix
=
layers
.
CutMix
()
ds
=
demo_utils
.
load_oxford_dataset
()
ds
=
ds
.
map
(
cutmix
,
num_parallel_calls
=
tf
.
data
.
AUTOTUNE
)
demo_utils
.
visualize_dataset
(
ds
)
if
__name__
==
"__main__"
:
main
()
Keras/keras-cv/examples/layers/preprocessing/classification/demo_utils.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utility functions for preprocessing demos."""
import
matplotlib.pyplot
as
plt
import
tensorflow
as
tf
import
tensorflow_datasets
as
tfds
def
resize
(
image
,
label
,
img_size
=
(
224
,
224
),
classes
=
10
):
image
=
tf
.
image
.
resize
(
image
,
img_size
)
label
=
tf
.
one_hot
(
label
,
classes
)
return
{
"images"
:
image
,
"labels"
:
label
}
def
load_oxford_dataset
(
name
=
"oxford_flowers102"
,
batch_size
=
64
,
img_size
=
(
224
,
224
),
as_supervised
=
True
,
):
# Load dataset.
data
,
ds_info
=
tfds
.
load
(
name
,
as_supervised
=
as_supervised
,
with_info
=
True
)
train_ds
=
data
[
"train"
]
classes
=
ds_info
.
features
[
"label"
].
num_classes
# Get tf dataset.
train_ds
=
train_ds
.
map
(
lambda
x
,
y
:
resize
(
x
,
y
,
img_size
=
img_size
,
classes
=
classes
)
).
batch
(
batch_size
)
return
train_ds
def
visualize_dataset
(
ds
):
outputs
=
next
(
iter
(
ds
.
take
(
1
)))
images
=
outputs
[
"images"
]
plt
.
figure
(
figsize
=
(
8
,
8
))
for
i
in
range
(
9
):
plt
.
subplot
(
3
,
3
,
i
+
1
)
plt
.
imshow
(
images
[
i
].
numpy
().
astype
(
"uint8"
))
plt
.
axis
(
"off"
)
plt
.
show
()
def
gallery_show
(
images
):
images
=
images
.
astype
(
int
)
for
i
in
range
(
9
):
image
=
images
[
i
]
plt
.
subplot
(
3
,
3
,
i
+
1
)
plt
.
imshow
(
image
.
astype
(
"uint8"
))
plt
.
axis
(
"off"
)
plt
.
show
()
def
load_elephant_tensor
(
output_size
=
(
300
,
300
)):
elephants
=
tf
.
keras
.
utils
.
get_file
(
"african_elephant.jpg"
,
"https://i.imgur.com/Bvro0YD.png"
)
elephants
=
tf
.
keras
.
utils
.
load_img
(
elephants
,
target_size
=
output_size
)
elephants
=
tf
.
keras
.
utils
.
img_to_array
(
elephants
)
many_elephants
=
tf
.
repeat
(
tf
.
expand_dims
(
elephants
,
axis
=
0
),
9
,
axis
=
0
)
return
many_elephants
Keras/keras-cv/examples/layers/preprocessing/classification/fourier_mix_demo.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""fourier_mix_demo.py shows how to use the FourierMix preprocessing layer.
Uses the oxford_flowers102 dataset. In this script the flowers
are loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import
demo_utils
import
tensorflow
as
tf
from
keras_cv
import
layers
def
main
():
fourier_mix
=
layers
.
FourierMix
(
alpha
=
0.5
)
ds
=
demo_utils
.
load_oxford_dataset
()
ds
=
ds
.
map
(
fourier_mix
,
num_parallel_calls
=
tf
.
data
.
AUTOTUNE
)
demo_utils
.
visualize_dataset
(
ds
)
if
__name__
==
"__main__"
:
main
()
Keras/keras-cv/examples/layers/preprocessing/classification/grid_mask_demo.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""gridmask_demo.py shows how to use the GridMask preprocessing layer.
Operates on the oxford_flowers102 dataset. In this script the flowers
are loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import
demo_utils
import
tensorflow
as
tf
import
keras_cv
from
keras_cv.layers
import
preprocessing
def
main
():
ds
=
demo_utils
.
load_oxford_dataset
()
gridmask
=
preprocessing
.
GridMask
(
ratio_factor
=
keras_cv
.
ConstantFactorSampler
(
0.3
),
rotation_factor
=
0.5
,
fill_mode
=
"gaussian_noise"
,
)
ds
=
ds
.
map
(
gridmask
,
num_parallel_calls
=
tf
.
data
.
AUTOTUNE
)
demo_utils
.
visualize_dataset
(
ds
)
if
__name__
==
"__main__"
:
main
()
Keras/keras-cv/examples/layers/preprocessing/classification/mix_up_demo.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""mix_up_demo.py shows how to use the MixUp preprocessing layer.
Uses the oxford_flowers102 dataset. In this script the flowers
are loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import
demo_utils
import
tensorflow
as
tf
from
keras_cv.layers
import
preprocessing
def
main
():
ds
=
demo_utils
.
load_oxford_dataset
()
mixup
=
preprocessing
.
MixUp
(
alpha
=
0.8
)
ds
=
ds
.
map
(
mixup
,
num_parallel_calls
=
tf
.
data
.
AUTOTUNE
)
demo_utils
.
visualize_dataset
(
ds
)
if
__name__
==
"__main__"
:
main
()
Keras/keras-cv/examples/layers/preprocessing/classification/mosaic_demo.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""mosaic_demo.py shows how to use the Mosaic preprocessing layer.
Operates on the oxford_flowers102 dataset. In this script the flowers
are loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import
demo_utils
import
tensorflow
as
tf
from
keras_cv
import
layers
def
main
():
mosaic
=
layers
.
Mosaic
()
ds
=
demo_utils
.
load_oxford_dataset
()
ds
=
ds
.
map
(
mosaic
,
num_parallel_calls
=
tf
.
data
.
AUTOTUNE
)
demo_utils
.
visualize_dataset
(
ds
)
if
__name__
==
"__main__"
:
main
()
Keras/keras-cv/examples/layers/preprocessing/classification/rand_augment_demo.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""rand_augment_demo.py shows how to use the RandAugment preprocessing layer.
Uses the oxford_flowers102 dataset. In this script the flowers
are loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import
demo_utils
import
tensorflow
as
tf
from
keras_cv.layers
import
preprocessing
def
main
():
ds
=
demo_utils
.
load_oxford_dataset
()
rand_augment
=
preprocessing
.
RandAugment
(
value_range
=
(
0
,
255
),
augmentations_per_image
=
3
,
magnitude
=
0.5
,
rate
=
0.875
)
ds
=
ds
.
map
(
rand_augment
,
num_parallel_calls
=
tf
.
data
.
AUTOTUNE
)
demo_utils
.
visualize_dataset
(
ds
)
if
__name__
==
"__main__"
:
main
()
Keras/keras-cv/examples/layers/preprocessing/classification/random_augmentation_pipeline_demo.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""rand_augment_demo.py shows how to use the RandAugment preprocessing layer.
Uses the oxford_flowers102 dataset. In this script the flowers
are loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import
demo_utils
import
tensorflow
as
tf
from
keras_cv.layers
import
preprocessing
def
create_custom_pipeline
():
layers
=
preprocessing
.
RandAugment
.
get_standard_policy
(
value_range
=
(
0
,
255
),
magnitude
=
0.75
,
magnitude_stddev
=
0.3
)
layers
=
layers
[:
4
]
# slice out some layers you don't want for whatever reason
layers
=
layers
+
[
preprocessing
.
GridMask
()]
return
preprocessing
.
RandomAugmentationPipeline
(
layers
=
layers
,
augmentations_per_image
=
3
)
def
main
():
ds
=
demo_utils
.
load_oxford_dataset
()
custom_pipeline
=
create_custom_pipeline
()
ds
=
ds
.
map
(
custom_pipeline
,
num_parallel_calls
=
tf
.
data
.
AUTOTUNE
)
demo_utils
.
visualize_dataset
(
ds
)
if
__name__
==
"__main__"
:
main
()
Keras/keras-cv/examples/layers/preprocessing/classification/random_channel_shift_demo.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""random_channel_shift_demo.py shows how to use the RandomChannelShift preprocessing
layer. Operates on the oxford_flowers102 dataset. In this script the flowers
are loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import
demo_utils
import
tensorflow
as
tf
from
keras_cv.layers
import
preprocessing
def
main
():
ds
=
demo_utils
.
load_oxford_dataset
()
rgbshift
=
preprocessing
.
RandomChannelShift
(
value_range
=
(
0
,
255
),
factor
=
0.4
)
ds
=
ds
.
map
(
rgbshift
,
num_parallel_calls
=
tf
.
data
.
AUTOTUNE
)
demo_utils
.
visualize_dataset
(
ds
)
main
()
Keras/keras-cv/examples/layers/preprocessing/classification/random_color_degeneration_demo.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""random_color_degeneration_demo.py shows how to use RandomColorDegeneration.
Operates on the oxford_flowers102 dataset. In this script the flowers
are loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import
demo_utils
import
tensorflow
as
tf
from
keras_cv.layers
import
preprocessing
def
main
():
ds
=
demo_utils
.
load_oxford_dataset
()
random_color_degeneration
=
preprocessing
.
RandomColorDegeneration
(
factor
=
(
0
,
1.0
))
ds
=
ds
.
map
(
random_color_degeneration
,
num_parallel_calls
=
tf
.
data
.
AUTOTUNE
)
demo_utils
.
visualize_dataset
(
ds
)
if
__name__
==
"__main__"
:
main
()
Keras/keras-cv/examples/layers/preprocessing/classification/random_color_jitter_demo.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""color_jitter_demo.py shows how to use the ColorJitter preprocessing layer.
Operates on the oxford_flowers102 dataset. In this script the flowers
are loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import
demo_utils
import
tensorflow
as
tf
from
keras_cv.layers
import
preprocessing
def
main
():
ds
=
demo_utils
.
load_oxford_dataset
()
color_jitter
=
preprocessing
.
RandomColorJitter
(
value_range
=
(
0
,
255
),
brightness_factor
=
(
-
0.2
,
0.5
),
contrast_factor
=
(
0.5
,
0.9
),
saturation_factor
=
(
0.5
,
0.9
),
hue_factor
=
(
0.5
,
0.9
),
seed
=
101
,
)
ds
=
ds
.
map
(
color_jitter
,
num_parallel_calls
=
tf
.
data
.
AUTOTUNE
)
demo_utils
.
visualize_dataset
(
ds
)
if
__name__
==
"__main__"
:
main
()
Keras/keras-cv/examples/layers/preprocessing/classification/random_crop_and_zoom.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""random_resized_crop_demo.py.py shows how to use the RandomResizedCrop
preprocessing layer. Operates on an image of elephant. In this script the image
is loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import
demo_utils
from
keras_cv.layers
import
RandomCropAndResize
def
main
():
many_elephants
=
demo_utils
.
load_elephant_tensor
(
output_size
=
(
300
,
300
))
layer
=
RandomCropAndResize
(
target_size
=
(
224
,
224
),
crop_area_factor
=
(
0.8
,
1.0
),
aspect_ratio_factor
=
(
3.0
/
4.0
,
4.0
/
3.0
),
)
augmented
=
layer
(
many_elephants
)
demo_utils
.
gallery_show
(
augmented
.
numpy
())
layer
=
RandomCropAndResize
(
target_size
=
(
224
,
224
),
crop_area_factor
=
(
0.01
,
1.0
),
aspect_ratio_factor
=
(
3.0
/
4.0
,
4.0
/
3.0
),
)
augmented
=
layer
(
many_elephants
)
demo_utils
.
gallery_show
(
augmented
.
numpy
())
if
__name__
==
"__main__"
:
main
()
Keras/keras-cv/examples/layers/preprocessing/classification/random_cutout_demo.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""random_cutout_demo.py shows how to use the RandomCutout preprocessing layer.
Operates on the oxford_flowers102 dataset. In this script the flowers
are loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import
demo_utils
import
tensorflow
as
tf
from
keras_cv.layers
import
preprocessing
def
main
():
ds
=
demo_utils
.
load_oxford_dataset
()
random_cutout
=
preprocessing
.
RandomCutout
(
height_factor
=
(
0.3
,
0.9
),
width_factor
=
(
0.3
,
0.9
),
fill_mode
=
"gaussian_noise"
,
)
ds
=
ds
.
map
(
random_cutout
,
num_parallel_calls
=
tf
.
data
.
AUTOTUNE
)
demo_utils
.
visualize_dataset
(
ds
)
if
__name__
==
"__main__"
:
main
()
Keras/keras-cv/examples/layers/preprocessing/classification/random_gaussian_blur_demo.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""random_gaussian_blur_demo.py shows how to use the RandomHue preprocessing layer.
Operates on the oxford_flowers102 dataset. In this script the flowers
are loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import
demo_utils
import
tensorflow
as
tf
from
keras_cv.layers
import
preprocessing
def
main
():
ds
=
demo_utils
.
load_oxford_dataset
()
random_gaussian_blur
=
preprocessing
.
RandomGaussianBlur
(
kernel_size
=
3
,
factor
=
(
0.0
,
3.0
)
)
ds
=
ds
.
map
(
random_gaussian_blur
,
num_parallel_calls
=
tf
.
data
.
AUTOTUNE
)
demo_utils
.
visualize_dataset
(
ds
)
if
__name__
==
"__main__"
:
main
()
Keras/keras-cv/examples/layers/preprocessing/classification/random_hue_demo.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""random_hue_demo.py shows how to use the RandomHue preprocessing layer.
Operates on the oxford_flowers102 dataset. In this script the flowers
are loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import
demo_utils
import
tensorflow
as
tf
from
keras_cv.layers
import
preprocessing
def
main
():
ds
=
demo_utils
.
load_oxford_dataset
()
random_hue
=
preprocessing
.
RandomHue
(
factor
=
(
0.0
,
1.0
),
value_range
=
(
0
,
255
))
ds
=
ds
.
map
(
random_hue
,
num_parallel_calls
=
tf
.
data
.
AUTOTUNE
)
demo_utils
.
visualize_dataset
(
ds
)
if
__name__
==
"__main__"
:
main
()
Keras/keras-cv/examples/layers/preprocessing/classification/random_saturation_demo.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""random_saturation_demo.py shows how to use the RandomSaturation preprocessing layer.
Operates on the oxford_flowers102 dataset. In this script the flowers
are loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import
demo_utils
import
tensorflow
as
tf
from
keras_cv.layers
import
preprocessing
def
main
():
ds
=
demo_utils
.
load_oxford_dataset
()
random_saturation
=
preprocessing
.
RandomSaturation
(
factor
=
(
0.0
,
1.0
))
ds
=
ds
.
map
(
random_saturation
,
num_parallel_calls
=
tf
.
data
.
AUTOTUNE
)
demo_utils
.
visualize_dataset
(
ds
)
if
__name__
==
"__main__"
:
main
()
Keras/keras-cv/examples/layers/preprocessing/classification/random_shear_demo.py
0 → 100644
View file @
0016b0a7
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""random_shear_demo.py shows how to use the RandomShear preprocessing layer.
Operates on the oxford_flowers102 dataset. In this script the flowers
are loaded, then are passed through the preprocessing layers.
Finally, they are shown using matplotlib.
"""
import
demo_utils
import
tensorflow
as
tf
from
keras_cv.layers
import
preprocessing
def
main
():
ds
=
demo_utils
.
load_oxford_dataset
()
random_cutout
=
preprocessing
.
RandomShear
(
x_factor
=
(
0
,
1
),
y_factor
=
0.5
,
)
ds
=
ds
.
map
(
random_cutout
,
num_parallel_calls
=
tf
.
data
.
AUTOTUNE
)
demo_utils
.
visualize_dataset
(
ds
)
if
__name__
==
"__main__"
:
main
()
Prev
1
2
3
4
5
6
7
…
17
Next
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