def process_genome( best ): ######## # Write the genome to disk so that minimize and maximize can use it ######## if options.stop_after is None: genome = "genome.%d" % best[ 0 ] else: genome = "genome.%d-%d" % ( options.stop_after, best[ 0 ] ) this_genome = os.path.join( results, genome ) + ".orig" if not os.path.exists( this_genome ) or options.force: infomsg( "INFO: saving genome to", this_genome ) with open( this_genome, 'w' ) as fh: infomsg( " ".join( lower_genome( best[ 1 ].split() ) ), file = fh ) ######## # Maximize the genome for all inputs ######## if input_size not in options.inputs: options.inputs = [ input_size ] + options.inputs infomsg( "INFO: maximizing genome for inputs:", *options.inputs ) with saving( "multi.cache" ): for test_input in options.inputs: next_genome = this_genome + "." + test_input if not os.path.exists( next_genome ) or options.force: with mkconfig( test_cmd( test_input ) ) as config: check_call( [ maximize, genprog, config, "--genome-file", this_genome, "--save-genome", next_genome ] ) with open( '/dev/null', 'w' ) as null: status = call( [ "diff", this_genome, next_genome ], stdout = null, stderr = null ) if status != 0: this_genome = next_genome infomsg( "INFO: final genome stored at", this_genome ) ######## # Minimize the genome for the original input ######## if not options.skip_minimize: min_genome = this_genome + ".min" min_binary = min_genome + ".bin" min_source = min_genome + ".src" fnames = [ min_genome, min_binary, min_source ] if options.force or any( [ not os.path.exists( f ) for f in fnames ] ): with mkconfig( test_cmd ) as config: cmd = [ minimize, genprog, config, "--genome-file", this_genome, "--save-binary", min_binary, "--save-genome", min_genome, "--save-sources", min_source ] if options.low_error is not None: cmd += [ "--low-error", str( options.low_error ) ] check_call( cmd ) this_genome = min_genome ######## # Measure the improvement over the original ######## if options.stop_after is None: cache = lambda i: os.path.join( results, "genome.%s-%s.cache" % ( options.filter, i ) ) else: cache = lambda i: os.path.join( results, "genome.%d-%s-%s.cache" % ( options.stop_after, options.filter, i ) ) genome_key = os.path.basename( this_genome ) with ImprovementTable( os.path.join( results, "improvement" ) ) as imprv: for test_input in options.inputs: if not options.force and ( genome_key, test_input ) in imprv: continue with mkconfig( test_cmd( test_input ) ) as config: cmd = [ minimize, genprog, config, "--search", "none", "--genome-file", this_genome, ] if not options.force: cmd += [ "--cache", cache( test_input ) ] if options.low_error is not None: cmd += [ "--low-error", str( options.low_error ) ] with mktemp() as log: try: pipeline( [ cmd, [ "tee", log ] ] ) except CalledProcessError: if ( genome_key, test_input ) in imprv: del imprv[ genome_key, test_input ] continue imprv[ genome_key, test_input ] = " ".join( map( str, get_improvement( log ) ) )
#importing some useful packages import matplotlib.pyplot as plt import matplotlib.image as mpimg import numpy as np import cv2 import util as u import os from moviepy.editor import VideoFileClip # for file_name in os.listdir("test_images/"): # # #reading in an image # image = cv2.imread('test_images/' + file_name) # print(file_name) # # plt.imshow(u.pipeline(image)) # plt.show() # for file in os.listdir('.'): # if file.endswith('.mp4'): import os for file in os.listdir("test_images/"): image = cv2.imread('test_images/' + file) marked_image = u.pipeline(image) cv2.imwrite('test_images/' + 'marked-' + file, marked_image) # clip = VideoFileClip('challenge.mp4') # white_clip = clip.fl_image(u.pipeline) # white_clip.write_videofile('marked/marked-' + 'challenge.mp4', audio=False)
for fname in fnames: if fname != "flags.make": continue fname = os.path.join(d, fname) with open(fname) as fh: lines = fh.readlines() with open(fname, "w") as fh: for line in lines: line = line.rstrip() if line.startswith("C_FLAGS") or line.startswith("CXX_FLAGS"): line = line + " -save-temps=obj" print(line, file=fh) infomsg("INFO: running make") with mktemp() as log: pipeline([["make", "-C", buildir, "VERBOSE=1", "V=1", "install"], ["tee", log]]) infomsg("INFO: collecting assembly files") asmfiles = dict() with open("multi.txt", "w") as fh: for d, dnames, fnames in os.walk(buildir): for fname in fnames: if os.path.splitext(fname)[1] == ".s": fname = os.path.join(d, fname) relpath = fname[len(buildir) + 1 :] print(relpath, file=fh) objname = os.path.splitext(relpath)[0] + ".o" asmfiles[objname] = relpath depgraph = dict() argflags = ["-o", "-isystem"]