Skip to content

Commit

Permalink
cleaning make-dataset code
Browse files Browse the repository at this point in the history
  • Loading branch information
Anaisha Das authored and Anaisha Das committed Dec 7, 2024
1 parent fa9b966 commit be23f50
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 31 deletions.
54 changes: 23 additions & 31 deletions color_analysis/processed_images/make_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,33 @@
seasonal_images = {}
seasons = ['spring','winter','summer','autumn']

# # extract all img tags with class img
# for s in seasons:
# s_links = []
# for url in seasons_links_dict[s]:
# request = requests.get(base_url+url, headers=headers)
# soup = BeautifulSoup(request.content, 'html.parser')
# images = soup.find_all('img', attrs={'class':'thumb-image'})
# links = [listing['data-src'] for listing in images]
# s_links.extend(links)
# seasonal_images[s] = s_links

# for s in seasonal_images.keys():
# for i in range(len(seasonal_images[s])):
# print(f"Processing image {i+1} / {len(seasonal_images[s])}")
# try:
# # Download image from URL
# r = requests.get(seasonal_images[s][i], stream=True)
# r.raise_for_status() # Raise an exception for HTTP errors

# # Save the image locally
# local_path = filename.format(s, i)
# with open(local_path, "wb") as f:
# f.write(r.content)

# # Update the image path in seasonal_images
# seasonal_images[s][i] = local_path
# except requests.exceptions.RequestException as e:
# print(f"Error downloading {seasonal_images[s][i]}: {e}")
# except Exception as e:
# print(f"An error occurred with image {seasonal_images[s][i]}: {e}")
# extract all img tags with class img, download the images, and save onto dictionary
for s in seasons:
i = 0
s_links = []
for url in seasons_links_dict[s]:
try:
request = requests.get(base_url+url, headers=headers)
soup = BeautifulSoup(request.content, 'html.parser')
images = soup.find_all('img', attrs={'class':'thumb-image'})
links = [listing['data-src'] for listing in images]
for l in links:
local_path = filename.format(s, i)
with open(local_path, "wb") as f:
f.write(l.content)
i += 1
s_links.append(local_path)
except requests.exceptions.RequestException as e:
print(f"Error downloading {seasonal_images[s][i]}: {e}")
except Exception as e:
print(f"An error occurred with image {seasonal_images[s][i]}: {e}")
seasonal_images[s] = s_links

processed_images = {}
script_path = "./preprocess.sh"
# Directory to save processed images


#Run preprocess script on each image
for s in seasons:
input_folder = f"../../combined-demo/pics/{s}"
output_folder = f"../../combined-demo/processed_images/{s}"
Expand Down
Binary file added combined-demo/input-imgs/benedict.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added combined-demo/input-imgs/sabrina.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added combined-demo/input-imgs/selena.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added combined-demo/output-imgs/your-palette.png.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added combined-demo/scripts/classifier_basic.pth
Binary file not shown.
Binary file added combined-demo/scripts/resnet18.pth
Binary file not shown.
Binary file added combined-demo/scripts/season_classifier.pth
Binary file not shown.

0 comments on commit be23f50

Please sign in to comment.