{ "cells": [ { "cell_type": "markdown", "id": "498b754e", "metadata": {}, "source": [ "# Gather images and upload them for labs\n", "----\n", "\n", "This notebook creates an S3 bucket and loads the bucket with synthetically generated images of faces. The bucket and the images will be used in the subsequent modules. \n", "\n", "1. Create a S3 bucket, you'll need to provide a name.\n", "2. Upload contents of media directory to the S3 bucket. \n", "\n", "#### Install python dependencies if necessary" ] }, { "cell_type": "code", "execution_count": null, "id": "02a0b095", "metadata": {}, "outputs": [], "source": [ "!pip install boto3 matplotlib opencv-python openpyxl pandas sklearn scikit-image" ] }, { "cell_type": "markdown", "id": "cb30d25b", "metadata": {}, "source": [ "#### Import Libraries & Specify a S3 bucket name\n", "\n", "Update the name of the bucket you want created on your behalf. This bucket will be used in subsequent modules and will be loaded with the synthetically generated images. \n", "\n", "
About Images used in Labs \n", " \n", "Images provided in lab modules were generated using a stylized generative adversarial network (GAN) using an adaptive discriminator and age dithered via latent encoding which “ages” the faces in the images. While the faces in the images may appear remarkable, they are synthetically generated and **are not images of real people**. \n", "\n", "
" ] }, { "cell_type": "code", "execution_count": null, "id": "95ebfa80", "metadata": {}, "outputs": [], "source": [ "import os\n", "import glob \n", "import boto3\n", "\n", "mySession = boto3.session.Session()\n", "aws_region = mySession.region_name\n", "print(\"AWS Region: {}\".format(aws_region))\n", "\n", "# --- sklearn libraries for Labeled Faces in the Wild --- \n", "from sklearn.datasets import fetch_lfw_people, get_data_home\n", "\n", "# --- provide a bucket name ---\n", "bucket_name = \"\"\n", "# -------------------------------------------\n", "\n", "print(\"AWS Bucket: {}\".format(bucket_name))\n", "%store bucket_name" ] }, { "cell_type": "markdown", "id": "d6e9e6a0", "metadata": {}, "source": [ "## Step 1. Create an S3 Bucket \n", "----\n", "The following will create a new S3 bucket which will store images and other objects that are used in subsequent modules. \n" ] }, { "cell_type": "code", "execution_count": null, "id": "6d5fec48", "metadata": {}, "outputs": [], "source": [ "s3 = boto3.client('s3')\n", "try:\n", " s3.create_bucket(Bucket=bucket_name)\n", "except Exception as err:\n", " print(\"ERROR: {}\".format(err))" ] }, { "cell_type": "markdown", "id": "7e0bd094", "metadata": {}, "source": [ "## Step 2. Upload Images to S3 bucket\n", "----\n", "This step reads all of the files in the media folder and uploads them to the S3 bucket. \n", "\n", "**NOTE: this may take a minute or two to upload to S3** " ] }, { "cell_type": "code", "execution_count": null, "id": "09a5ac33", "metadata": { "scrolled": false }, "outputs": [], "source": [ "# S3 content of media directory and upload it\n", "media_path = \"media/*\"\n", "for img in glob.glob(media_path):\n", " file_name = os.path.basename(img)\n", " s3.upload_file(img, bucket_name, file_name)\n", "print(\"-- upload complete --\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.7" }, "vscode": { "interpreter": { "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" } } }, "nbformat": 4, "nbformat_minor": 5 }