Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions style-transfer/Style_Transfer_Exercise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@
"%matplotlib inline\n",
"\n",
"from PIL import Image\n",
"from io import BytesIO\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import torch\n",
"import torch.optim as optim\n",
"import requests\n",
"from torchvision import transforms, models"
]
},
Expand Down Expand Up @@ -109,8 +111,11 @@
"def load_image(img_path, max_size=400, shape=None):\n",
" ''' Load in and transform an image, making sure the image\n",
" is <= 400 pixels in the x-y dims.'''\n",
" \n",
" image = Image.open(img_path).convert('RGB')\n",
" if \"http\" in img_path:\n",
" response = requests.get(img_path)\n",
" image = Image.open(BytesIO(response.content)).convert('RGB')\n",
" else:\n",
" image = Image.open(img_path).convert('RGB')\n",
" \n",
" # large images will slow down processing\n",
" if max(image.size) > max_size:\n",
Expand Down
9 changes: 7 additions & 2 deletions style-transfer/Style_Transfer_Solution.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@
"%matplotlib inline\n",
"\n",
"from PIL import Image\n",
"from io import BytesIO\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import torch\n",
"import torch.optim as optim\n",
"import requests\n",
"from torchvision import transforms, models"
]
},
Expand Down Expand Up @@ -158,8 +160,11 @@
"def load_image(img_path, max_size=400, shape=None):\n",
" ''' Load in and transform an image, making sure the image\n",
" is <= 400 pixels in the x-y dims.'''\n",
" \n",
" image = Image.open(img_path).convert('RGB')\n",
" if \"http\" in img_path:\n",
" response = requests.get(img_path)\n",
" image = Image.open(BytesIO(response.content)).convert('RGB')\n",
" else:\n",
" image = Image.open(img_path).convert('RGB')\n",
" \n",
" # large images will slow down processing\n",
" if max(image.size) > max_size:\n",
Expand Down