Question on downloading image from github #524
Unanswered
Duwimpuhwe
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Hi @Duwimpuhwe , I can confirm the following code works: import torch
import torchvision
# Download custom image
import requests
from pathlib import Path
# Setup path to data folder
data_path = Path("data/")
data_path.mkdir(exist_ok=True)
# Setup custom image path
custom_image_path = data_path / "04-pizza-dad.jpeg"
# Download the image if it doesn't already exist
if not custom_image_path.is_file():
with open(custom_image_path, "wb") as f:
# When downloading from GitHub, need to use the "raw" file link
request = requests.get("https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/04-pizza-dad.jpeg")
print(f"Downloading {custom_image_path}...")
f.write(request.content)
else:
print(f"{custom_image_path} already exists, skipping download.")
# Load the image file
custom_image_uint8 = torchvision.io.read_image(str(custom_image_path))
custom_image_uint8 If you're having trouble loading the image, try to delete it and then redownload it. See this Google Colab notebook for an example: https://colab.research.google.com/drive/1eLCCSP38zf6EEgeFI-cdNmrgKwZfSZg8?usp=sharing |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm unable to get the right image from github, below are the codes and error
Error:
Beta Was this translation helpful? Give feedback.
All reactions