Skip to content

Instantly share code, notes, and snippets.

@neelriyer
Created July 5, 2020 10:09
Show Gist options
  • Save neelriyer/ca2f0682ebf9c5d6f70643f62fe7cb4a to your computer and use it in GitHub Desktop.
Save neelriyer/ca2f0682ebf9c5d6f70643f62fe7cb4a to your computer and use it in GitHub Desktop.
Run inference on images using trained model
mport PIL
import glob
import os
from tqdm.notebook import tqdm
render_factor = 40
if os.path.exists('imagepaths.txt'):
os.remove('imagepaths.txt')
!rm -Rf seinfeld_inference/high_res/
!mkdir seinfeld_inference/high_res/
def write_to_txt(dest):
file = open("imagepaths.txt", "a")
write = "file '" + dest.strip() + "'" + "\n"
file.write(write)
file.close()
files = sorted(glob.glob('seinfeld_inference/images/*.*g'), key = lambda x: int(os.path.basename(x).split('.')[0]))
files = files[300:]
for i in tqdm(range(1000)):
# file = random.choice(files)
file = files[i]
dest = 'seinfeld_inference/high_res/'+os.path.basename(file)
# scale to square
new_path = scale_to_square(PIL.Image.open(file), render_factor*16, dest = dest.split('.')[0]+'_square.jpg')
# run inference
run_inference_images(new_path, dest)
# unsquare
dest = unsquare(PIL.Image.open(dest), PIL.Image.open(file), dest = dest.split('.')[0]+'_unsquared.jpg')
# write to txt
write_to_txt(dest)
# increase brightness
adjust_brightness(PIL.Image.open(dest),factor = 1.75, dest=dest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment