Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # DEOLDIFY, use a photo from Drive instead of Internet URL
- # notice the line "image_path", uses transformed_image instead of transformed_image_from_url
- # also, the parameter is not "path" instead of "url"
- source_url = '/content/drive/MyDrive/machinelearninginthecloud2022/exercise2b/originals/pic1.jpg' #@param {type:"string"}
- render_factor = 36 #@param {type: "slider", min: 7, max: 40}
- watermarked = False #@param {type:"boolean"}
- if source_url is not None and source_url !='':
- image_path = colorizer.plot_transformed_image(path=source_url, render_factor=render_factor, compare=True, watermarked=watermarked)
- show_image_in_notebook(image_path)
- else:
- print('Provide an image url and try again.')
- # GETTING ALL PHOTOS IN A FOLDER
- # THE LOGIC IS THIS:
- # get the paths of the photos in our Google Drive old photos folder into a list
- # import the os-module
- import os
- # some folder in Google Drive
- image_folder = '/content/drive/MyDrive/machinelearninginthecloud2022/exercise2b/originals'
- # get file names
- image_files = os.listdir(image_folder)
- # initialize a list for the photo paths
- photos = []
- for i in image_files:
- photos.append(image_folder + "/" + i)
- # check out the results
- print(photos)
- for photo in photos:
- print(photo)
- image_path = colorizer.plot_transformed_image(path=photo, render_factor=render_factor, compare=True, watermarked=watermarked)
- show_image_in_notebook(image_path)
- # use a for-loop to go through each photo in the list
- # use DeOldify to colorize each photo at a time
- # save the colorized photo into a folder
- # ANOTHER VERSION
- # THE LOGIC IS THIS:
- # get the paths of the photos in our Google Drive old photos folder into a list
- # import the os-module
- import os
- from PIL import Image
- # some folder in Google Drive
- image_folder = '/content/drive/MyDrive/machinelearninginthecloud2022/exercise2b/originals'
- # get file names
- image_files = os.listdir(image_folder)
- # initialize a list for the photo paths
- photos = []
- for i in image_files:
- photos.append(image_folder + "/" + i)
- # check out the results
- print(photos)
- number = 1
- for photo in photos:
- print(photo)
- image_path = colorizer.plot_transformed_image(path=photo, render_factor=render_factor, compare=True, watermarked=watermarked)
- show_image_in_notebook(image_path)
- img = Image.open(image_path)
- img.save("/content/drive/MyDrive/machinelearninginthecloud2022/exercise2b/colorized/photo" + str(number) + ".jpg")
- number = number + 1
- # use a for-loop to go through each photo in the list
- # use DeOldify to colorize each photo at a time
- # save the colorized photo into a folder
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement