def load_model(model_config): """ Loads the model specified by the model config. """ model_name = model_config['architecture'].lower() if model_name == 'vrnn': from vrnn import VRNN return VRNN(model_config) elif model_name == 'srnn': from srnn import SRNN return SRNN(model_config) # elif model_name == 'dvbf': # from dvbf import DVBF # return DVBF(model_config) elif model_name == 'svg': from svg import SVG return SVG(model_config) elif model_name in ['conv', 'convolutional']: from convolutional import ConvolutionalDLVM return ConvolutionalDLVM(model_config) elif model_name in ['fc', 'fully_connected']: from fully_connected import FullyConnectedDLVM return FullyConnectedDLVM(model_config) else: raise Exception('Model architecture not found.')
def Document(filename): tree = ElementTree.parse(filename) root = tree.getroot() if root.tag != namespace + 'svg': text = 'File "%s" does not seem to be a valid SVG file' % filename raise TypeError(text) return SVG(root)
def __init__(self, width=600, height=600): self.width = width self.height = height self.svg = SVG(viewBox=f"0 0 {width} {height}", style="stroke: black; fill: none;") self.background("white") self.tcount = 0
def __init__(self, name, colour): self.longName = name self.displayedName = name self.colour = colour self.devices = list() self.svgFile = SVG() self.svgRoot = self.svgFile.getSvg()
def load_svg(self, path): with open(path) as file: svg = SVG(file.read()) self.svg = svg self.geojson = GeoJSON(self.svg) self.layer_output = list(self.svg.get_layers()) self.update_result() self.ui.load_preview(path) layers = self.svg.get_layers() self.ui.load_layers(layers)
def main(): ''' Fonction principale ''' drawing = SVG("dessin.svg", 1000, 1000) drawing.header() lines = generate_random_lines() lines = get_symmetric(lines) for line in lines: drawing.draw_line(line) drawing.footer() drawing.write_file()
observation_space = env.observation_space.shape[0] # pred_length = 13+ was ok. Too far, because of 'to point' controller (U is proportional to error) predictor = Predictor(obs_length=10, pred_length=14) # h_dim 100 was ok, batch normalisation does not improve net = StochasticNet(action_space, observation_space, h_dim=100, on_bn=0) # 1000 samples was ok replay_buffer = SimpleReplayPool(1000, observation_space, action_space) svg = SVG(epoch=500, min_buffer_size=256, pi_lr=1e-3, q_lr=1e-4, scale_reward=2.5, batch_size=64, tau=0.01, sess=tf.Session(), env=env, max_path_length=max_steps_per_episode, predictor=predictor, net=net, action_space=action_space, observation_space=observation_space, replay_buffer=replay_buffer) # save_every - does not work - keep higher than the number of epoch # steps_to_solve - defines for how many steps in succession without sampling from LSTM a run is considered solved # resample - switch on sampling from the predictor svg.train(plot_every=5, save_every=10000, resample=True, steps_to_solve=10)
def save_graph(histogram: Histogram, bin_color: colors.Color): scale = 1 w = h = 1024 / 2 * scale stroke_width = 2 left_margin = 0.075 * w right_margin = left_margin top_margin = 0.4 * h bottom_margin = 0.1 * h x_min = left_margin x_max = w - right_margin y_min = top_margin y_max = h - bottom_margin time_min = 0 time_max = histogram.bin_width * len(histogram.counts) time_to_x = lambda t: (t - time_min) / (time_max - time_min) * (x_max - x_min) + x_min percentage_min = 0 percentage_max = 0.3 percentage_to_y = lambda p: (1 - (p - percentage_min) / (percentage_max - percentage_min)) * \ (y_max - y_min) + y_min # draw background elements: List[Element] = [] margin = 0 elements.append(Polygon( vertices=[ Point(margin, margin), Point(w - margin, margin), Point(w - margin, h - margin), Point(margin, h - margin), ], fill=colors.white, stroke=None, )) # draw bins percentages = [count / histogram.total_count for count in histogram.counts] for (i, percentage) in enumerate(percentages): t1 = i * histogram.bin_width t2 = (i + 1) * histogram.bin_width x1 = time_to_x(t1) - 0.5 x2 = time_to_x(t2) + 0.5 y1 = percentage_to_y(0) y2 = percentage_to_y(percentage) elements.append(Polygon( vertices=[ Point(x1, y1), Point(x2, y1), Point(x2, y2), Point(x1, y2), ], fill=bin_color, stroke=None, )) # draw x axis elements.append(Polyline(stroke=Stroke(colors.black, stroke_width), points=[ Point(x_min - 0.5, y_max), Point(x_max + 0.5, y_max), ])) # draw x axis ticks for i in range(len(histogram.counts) + 1): t = i * histogram.bin_width x = time_to_x(t) elements.append(Polyline( stroke=Stroke(colors.black, 1), points=[ Point(x, y_max), Point(x, y_max - 5), ], )) # TODO: draw x axis labels # draw median line x_median = time_to_x(histogram.median) elements.append(Polyline(stroke=Stroke(colors.black, 1.25), points=[ Point(x_median, y_min), Point(x_median, y_max), ])) # TODO: draw median text # TODO: title # TODO: subtitle svg = SVG(width=w, height=h, elements=elements) path = os.path.join(GRAPHS_DIR, histogram.filename) svg.write_xml(path)
''' Fichier permettant d'effectuer différents tests au fur et à mesure du développement ''' from svg import SVG from math import pi from geometry import random_line, random_point from geometry import Point dessin = SVG("dessin.svg", 1000, 1000) def test_line(): ''' Test affichant une ligne aléatoire sur le dessin svg ''' ligne = random_line() dessin.draw_line(ligne) def test_multiple_random(): ''' Test affichant 7 lignes aléatoires sur le dessin svg ''' for _ in range(7): ligne = random_line((500, 1000), (0, 1000)) dessin.draw_line(ligne) def test_symmetrical_point():
def __create_svg_file(self): self.svg = SVG([self.card_width, self.card_height])
# outlines outlines.objects.append(Path("cut", [m(self.material_width,self.material_width)]+ self.make_tongues(my_width, True, True)+ self.make_tongues(my_width, False, True) ,closed=True)) return (outlines,Group(transformation=(self.material_width,self.material_width))) if __name__=="__main__": casing=Casing(100,60,30) sides=[ ("top",casing.top), ("side13",casing.side13), ("side24",casing.side24) ] for name,func in sides: svg=SVG((100,60),"casing") outlines,subview=func() outlines.objects.append(subview) svg.children.append(outlines) # test rectangle #subview.objects.append(Rectangle(style_cut, (0,0), (10,10))) with open("cut_{}.svg".format(name),"w") as f: f.write(svg.get_svg())
import gym from gym import wrappers import tensorflow as tf import os import argparse from rllab.envs.gym_env import GymEnv from net import StochasticNet from svg import SVG from replay_buffer import SimpleReplayPool parser = argparse.ArgumentParser() parser.add_argument('--log', type=str, default='log_svg') args = parser.parse_args() env = GymEnv('Pendulum-v0', record_video=True, log_dir=args.log) env_spec = dict( action_space=env.action_space, observation_space=env.observation_space) net = StochasticNet(env_spec) replay_buffer = SimpleReplayPool(1000000, env_spec['observation_space'].shape[0], env_spec['action_space'].shape[0]) config = tf.ConfigProto(inter_op_parallelism_threads=1, intra_op_parallelism_threads=1) sess = tf.Session(config=config) agent = SVG(epoch=100000, net=net, env_spec=env_spec, replay_buffer=replay_buffer, sess=sess, env=env, scale_reward=0.01, max_path_length=200, batch_size=32) agent.train_step()