Skip to content

Commit

Permalink
Refactored to use data.utils train/val split function
Browse files Browse the repository at this point in the history
  • Loading branch information
DiogenesAnalytics committed Jan 2, 2024
1 parent 080edd3 commit 628ff9c
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions notebooks/demo/tf_flowers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,18 @@
"metadata": {},
"outputs": [],
"source": [
"# get autoencoder image dataset tools\n",
"from autoencoder.data.utils import train_val_split_image_dataset\n",
"\n",
"# use keras util to load raw images into tensorflow.data.Dataset\n",
"x_train, x_val = keras.utils.image_dataset_from_directory(\n",
"x_train, x_val = train_val_split_image_dataset(\n",
" data_dir,\n",
" color_mode=\"rgb\",\n",
" validation_split=(1 / 7),\n",
" subset=\"both\",\n",
" seed=42,\n",
" image_size=(28, 28),\n",
" batch_size=32,\n",
")\n",
"\n",
"# use a keras layer to normalize\n",
"normalization_layer = keras.layers.Rescaling(1./255)\n",
"\n",
"# will apply normalization as well as regrouping each element\n",
"def change_inputs(images, labels):\n",
" x = normalization_layer(images)\n",
" return x, x\n",
"\n",
"# apply change\n",
"x_train, x_val = x_train.map(change_inputs), x_val.map(change_inputs)"
")"
]
},
{
Expand Down Expand Up @@ -217,7 +208,7 @@
"ae_eval = AutoencoderEvaluator(autoencoder, x_val)\n",
"\n",
"# view distribution\n",
"ae_eval.view_error_distribution(\"tf_flowers Autoencoder: Reconstruction Error Distribution\")"
"ae_eval.view_error_distribution(\"tf_flowers Autoencoder: Reconstruction Error Distribution\", bins=100)"
]
}
],
Expand Down

0 comments on commit 628ff9c

Please sign in to comment.