def main(): #If there's no argument, run basic demonstration if (len(sys.argv) == 1): style_transfer("./images/all/man_with_sunglasses.jpg", "./images/all/stained_glass_1.jpg", "./output/stained_glasses_man.jpg", max_size=150 * 150) #If there's three arguments, run a basic iteration with only path names. elif (len(sys.argv) == 4): style_transfer(sys.argv[1], sys.argv[2], sys.argv[3], max_size=150 * 150) else: print( "Please enter no arguments for a basic demonstration, or three arguments with the content, style and output images file path." ) print( "For more parameters please open this script and run it from an interpreter." )
def webcam_input(model): st.header("Webcam Live Feed") run = st.checkbox("Run") FRAME_WINDOW = st.image([], channels='BGR') SIDE_WINDOW = st.sidebar.image([], width=100, channels='BGR') camera = cv2.VideoCapture(0) WIDTH = st.sidebar.select_slider('QUALITY (May reduce the speed)', list(range(150, 501, 50))) while run: _, frame = camera.read() frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR) # orig = frame.copy() orig = imutils.resize(frame, width=300) frame = imutils.resize(frame, width=WIDTH) target = style_transfer(frame, model) FRAME_WINDOW.image(target) SIDE_WINDOW.image(orig) else: st.warning("NOTE: Streamlit currently doesn't support webcam. So to use this, clone this repo and run it on local server.") st.warning('Stopped')
def image_input(model): if st.sidebar.checkbox('Upload'): content_file = st.sidebar.file_uploader("Choose a Content Image", type=["png", "jpg", "jpeg"]) else: content_name = st.sidebar.selectbox("Choose the content images:", content_images_name) content_file = content_images_dict[content_name] if content_file is not None: content = Image.open(content_file) content = np.array(content) #pil to cv content = cv2.cvtColor(content, cv2.COLOR_RGB2BGR) else: st.warning("Upload an Image OR Untick the Upload Button)") st.stop() WIDTH = st.sidebar.select_slider('QUALITY (May reduce the speed)', list(range(150, 501, 50)), value=200) content = imutils.resize(content, width=WIDTH) generated = style_transfer(content, model) st.sidebar.image(content, width=300, channels='BGR') st.image(generated, channels='BGR', clamp=True)
content_images_name) content_file = content_images_dict[content_name] if content_file is not None: content = Image.open(content_file) content = np.array(content) # pil to cv content = cv2.cvtColor(content, cv2.COLOR_RGB2BGR) else: st.warning("Upload an Image OR Untick the Upload Button)") st.stop() # ## Exercise 3 : Render your final results ## # # 3.1. Create a slider on your sidebar to select the quality # from 150 to 500, step of 50, default value of 200 # Store this value in a WIDTH variable WIDTH = st.sidebar.select_slider('QUALITY (May reduce the speed)', list(range(150, 501, 50)), value=200) content = imutils.resize(content, width=WIDTH) generated = style_transfer(content, model) # 3.2. Show the source image (content) in the sidebar in BGR channel st.sidebar.image(content, width=300, channels='BGR') # 3.3 Show the final result (generated) right in your app st.image(generated, channels='BGR', clamp=True)
#default values : content = 0.025, style = 5.0, var_w = 1.0 content_weight = 0.025 style_weight = 5.0 var_weight = 1. ### Layer used for the Loss calculations ln_content = ["block5_conv2"] ln_style = [ "block1_conv1", "block2_conv1", "block3_conv1", "block4_conv1", "block5_conv1" ] style_transfer( content_image_path, #Path of the content image style_image_path, #Path of the style image output_image_path, #Path of the output image loadDims, #True if using native image dim withBaseImage, #True if using content image as starting image, false for random noises. rescale, #Rescale the image, only useful if loadDims = true max_size, #Automatically rescale if height*width > max_size. -1 to ignore. height, #wanted height of the images, useless if loadDims. width, #wanted width of the images, useless if loadDims. nb_iterations, #number of iterations stepsBeforeSaveAndShow, # content_weight, style_weight, var_weight, ln_content, #Layers used for loss content calculation ln_style #Layers used for style content calculation. )