Giter VIP home page Giter VIP logo

alexandre01 / deepsvg Goto Github PK

View Code? Open in Web Editor NEW
877.0 23.0 87.0 11.29 MB

[NeurIPS 2020] Official code for the paper "DeepSVG: A Hierarchical Generative Network for Vector Graphics Animation". Includes a PyTorch library for deep learning with SVG data.

Home Page: https://www.lingosub.com

License: MIT License

Python 5.05% Shell 0.04% Jupyter Notebook 94.76% kvlang 0.15%
deep-learning pytorch svg svg-animations transformer library python deep-svg machine-learning autoencoder

deepsvg's Introduction

Hi there! 👋

Contact me:

  Reshot AI

With Reshot AI, create professional photo shoots for your brand with fully controllable face poses, lighting, and expressions: https://www.reshot.ai


  AI Unfolded

AI Unfolded is the largest database of AI tools and resources. Browse 3000+ AI tools in 100+ categories, read our comprehensive guides, and find the right tool for your project: https://www.aiunfolded.co


  Litso AI

Check my work on Litso APP: https://litso.io


Check out our NeurIPS2020 paper on SVG image generation!

https://github.com/alexandre01/deepsvg

deepsvg's People

Contributors

alexandre01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deepsvg's Issues

About own datasets

Hello! Dear author, I am honored to be able to read your work, as a vector diagram beginner, I use my own data set training when the following errors, I do not know how to solve, you can answer for me, if you can reply to me, I will be grateful! All the best!
Uploading QQ20231005-105116.png…

How to adjust max_num_groups and max_total_len

@alexandre01 , in the deepsvg project you posted, I found that I encountered a tensor mismatch problem when using my own svg image. I found that you specified max_num_groups=8, max_total_len= 50 in deepsvg/configs/deepsvg/default_icons.py. I hope to be able to adjust the configuration of max_num_groups and max_total_len in this project and train my own max_num_groups and max_total_len to solve the problem of tensor inconsistency. Matching problem. Unfortunately, I didn't make any progress. Can you give me some guidance? I would be infinitely grateful and look forward to hearing from you!

From Generation to Translation

This is a very interesting work!
Do you think this model can be easily adapted to tackle SVG translation problem? (ie translating a SVG from one type to another)
Do you have any related literatures in your mind for these line of work?
Would love to hear your thought!

Loading SVGs does not carry over their stroke attributes

Hey there, awesome project. I want to use the SVG normalizing capabilities and ran into issues. Precisely, I am running into the issue that all output has 3.0 stroke width and 0.3 stroke opacity.

I personally attribute this to the SVG loading from XML, where the attributes are read but not further used:

def from_xml(x: minidom.Element):
stroke = x.getAttribute('stroke')
dasharray = x.getAttribute('dasharray')
stroke_width = x.getAttribute('stroke-width')
fill = not x.hasAttribute("fill") or not x.getAttribute("fill") == "none"
filling = Filling.OUTLINE if not x.hasAttribute("filling") else int(x.getAttribute("filling"))
s = x.getAttribute('d')
return SVGPath.from_str(s, fill=fill, filling=filling)

But I am not sure at the moment. Is there a way to keep the original stroke attributes of the paths?

Dolphin example

The minimal reproducable code for this is the dolphin example from the README. This is the result of running that exact code for me:
image

This is the output when save_svg is called on the SVG object:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0.0 0.0 24.0 24.0" height="200px" width="200px">
<path fill="none" stroke="black" stroke-width="3.0" stroke-opacity="0.3"  filling="0" d="M19.29208755493164 17.08875274658203 C19.0003604888916 17.26874542236328 18.665618896484375 17.179052352905273 18.55558967590332 17.14957046508789 C18.351573944091797 17.09490394592285 18.108379364013672 16.993528366088867 17.767244338989258 16.820850372314453 C17.499290466308594 16.68522071838379 17.270736694335938 16.560340881347656 17.069175720214844 16.450275421142578 C16.672706604003906 16.2336368560791 16.386165618896484 16.07703971862793 16.097652435302734 15.999732971191406 C15.935028076171875 15.956157684326172 15.619440078735352 15.94711685180664 15.285219192504883 15.937570571899414 C14.764851570129395 15.922700881958008 14.117305755615234 15.904151916503906 13.528430938720703 15.746363639831543 C12.933895111083984 15.587058067321777 12.320493698120117 15.373151779174805 11.935758590698242 15.231826782226562 C11.673254013061523 15.68767261505127 11.144759178161621 16.413766860961914 10.282265663146973 16.803768157958984 C9.109655380249023 17.333890914916992 8.302614212036133 17.494300842285156 8.268816947937012 17.500858306884766 C8.062347412109375 17.54096031188965 7.855262756347656 17.435482025146484 7.766499996185303 17.244794845581055 C7.677706718444824 17.05422592163086 7.730056285858154 16.827720642089844 7.893519878387451 16.695514678955078 C7.898970603942871 16.69097137451172 8.561553955078125 16.140411376953125 8.747669219970703 15.371997833251953 C8.821741104125977 15.066312789916992 8.874481201171875 14.825379371643066 8.911786079406738 14.641104698181152 C8.265583992004395 14.657169342041016 7.140110015869141 14.778581619262695 6.415033340454102 15.380525588989258 C5.316692352294922 16.292226791381836 4.525607109069824 17.93700408935547 4.460894584655762 18.528764724731445 C4.393395900726318 19.145307540893555 4.404304504394531 19.148231506347656 4.685268878936768 19.223514556884766 C5.297435283660889 19.387544631958008 5.80500602722168 19.55040740966797 6.299775123596191 20.02096176147461 C6.737459182739258 20.43709945678711 6.937915325164795 20.81779670715332 6.959256172180176 20.859853744506836 C7.039971351623535 21.01830291748047 7.021628379821777 21.20917510986328 6.912227153778076 21.349294662475586 C6.80279541015625 21.489530563354492 6.6221160888671875 21.553672790527344 6.448828220367432 21.51381492614746 C6.28159761428833 21.47563934326172 5.769392967224121 21.38313865661621 5.416074752807617 21.413726806640625 C5.22844123840332 21.429994583129883 5.061683654785156 21.463172912597656 4.900393486022949 21.49528694152832 C4.642367362976074 21.546667098999023 4.398634433746338 21.595176696777344 4.139557838439941 21.557546615600586 C4.055301666259766 21.54533576965332 3.9701900482177734 21.527585983276367 3.8912200927734375 21.504844665527344 C3.741024971008301 21.695083618164062 3.5147924423217773 21.909183502197266 3.195315361022949 22.041549682617188 C2.9507532119750977 22.14292335510254 2.718639373779297 22.18368148803711 2.5138702392578125 22.219562530517578 C2.262392044067383 22.263721466064453 2.063711166381836 22.298583984375 1.8830337524414062 22.430408477783203 C1.4094963073730469 22.775928497314453 1.1621580123901367 23.22187042236328 1.1597576141357422 23.226350784301758 C1.0621509552001953 23.40476417541504 0.8579807281494141 23.498321533203125 0.65936279296875 23.454647064208984 C0.6524868011474609 23.453182220458984 0.6456165313720703 23.451465606689453 0.6388339996337891 23.449647903442383 C0.4506797790527344 23.39923095703125 0.31365299224853516 23.23536491394043 0.30036354064941406 23.0394287109375 C0.2943086624145508 22.951414108276367 0.2591733932495117 22.150197982788086 0.859130859375 21.15196990966797 C1.073622703552246 20.795122146606445 1.3351068496704102 20.50653839111328 1.587946891784668 20.227333068847656 C1.999312400817871 19.773265838623047 2.354580879211426 19.381141662597656 2.4059295654296875 18.797744750976562 C2.647205352783203 16.055723190307617 3.2495040893554688 13.935039520263672 4.195972919464111 12.49482250213623 C5.667790412902832 10.254865646362305 8.003429412841797 9.412933349609375 8.456668853759766 9.266988754272461 C8.681556701660156 9.19446849822998 8.883283615112305 9.131731033325195 9.052956581115723 9.080123901367188 C8.946891784667969 8.93655776977539 8.805723190307617 8.77777099609375 8.625152587890625 8.636550903320312 C8.214173316955566 8.315095901489258 8.03367805480957 8.208970069885254 7.9831109046936035 8.181642532348633 C7.979600429534912 8.180830001831055 7.976239204406738 8.17992877960205 7.972878932952881 8.179028511047363 C7.7803449630737305 8.127501487731934 7.666408061981201 7.960718631744385 7.660402774810791 7.757887363433838 C7.6541428565979 7.547279357910156 7.818886756896973 7.367133140563965 8.021797180175781 7.310590744018555 C8.060404777526855 7.299764633178711 8.981307983398438 7.050039291381836 10.031401634216309 7.331410884857178 C10.248095512390137 7.389473915100098 10.458047866821289 7.467029094696045 10.655391693115234 7.5619330406188965 C11.270244598388672 7.857690334320068 11.678993225097656 8.162938117980957 12.074275016784668 8.458067893981934 C12.460226058959961 8.746273040771484 12.824797630310059 9.018510818481445 13.399856567382812 9.310179710388184 C13.679200172424316 9.451892852783203 13.938959121704102 9.573063850402832 14.190105438232422 9.69028377532959 C15.054240226745605 10.093473434448242 15.800516128540039 10.44169807434082 16.81147003173828 11.353596687316895 C18.130874633789062 12.543868064880371 18.761526107788086 13.628332138061523 18.587364196777344 14.407089233398438 C18.550647735595703 14.571233749389648 18.508243560791016 14.715338706970215 18.46017074584961 14.839091300964355 C18.58405113220215 14.948943138122559 18.73365592956543 15.085912704467773 18.882488250732422 15.23284912109375 C19.488374710083008 15.83094310760498 19.706562042236328 16.21575927734375 19.635496139526367 16.56092643737793 C19.586000442504883 16.80108642578125 19.470491409301758 16.978622436523438 19.29208755493164 17.08875274658203 Z"></path></svg>```

Hello, I probably find I bug in 'deepsvg/svglib /svg.py' (merge_group)

From the line 250 to 255, there is a func called merge_groups().
the code is as follows:

    def merge_groups(self):
        path_group = self.svg_path_groups[0]
        for path_group in self.svg_path_groups[1:]:
            path_group.svg_paths.extend(path_group.svg_paths)
        self.svg_path_groups = [path_group]
        return self

The variable path_group is being reused in the for loop, which causes confusion to me when I use this function. Inside the loop, path_group.svg_paths.extend(path_group.svg_paths) doesn't make sense because it is trying to extend path_group.svg_paths with itself. This is likely an error.
I think it is should be(the **group** is the difference between the two codes):

    def merge_groups(self):
        path_group = self.svg_path_groups[0]
        for **group** in self.svg_path_groups[1:]:
            path_group.svg_paths.extend(**group**.svg_paths)
        self.svg_path_groups = [path_group]
        return self

I use a different variable name (group) in the for loop. Here, path_group.svg_paths.extend(group.svg_paths) correctly extends the svg_paths of the first group.
Hopefully, You can notice this message.

CUDA error: CUBLAS_STATUS_EXECUTION_FAILED

Hi Alexandre,

Many thanks for the paper and the code. Excellent work!

I am getting a CUDA error for which I have no immediate explanation. Maybe you have an idea (also in case of other users experiencing the same issue). Googling the error message resulted in some hits but none that I could work with.

Where does error occur?

  • notebooks/fonts.ipynb
  • Random font generation

Environment

  • Ubuntu 20.04
  • Cuda compilation tools, release 11.1, V11.1.105; Build cuda_11.1.TC455_06.29190527_0
  • Python 3.7 (installed requirements.txt)
  • GPU RTX 3090

Error message

Immediate code context:

z = get_z()

for c in glyph2label:
    sample_class(c, z=z, with_points=True, with_handles=True, with_moves=False)

Error message:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-14-5f29ff27738d> in <module>
      2 
      3 for c in glyph2label:
----> 4     sample_class(c, z=z, with_points=True, with_handles=True, with_moves=False)

<ipython-input-8-af5b7f4d729f> in sample_class(label, z, temperature, filename, do_display, return_svg, return_png, *args, **kwargs)
      6 
      7     label, = batchify((torch.tensor(label_id),), device=device)
----> 8     commands_y, args_y = model.greedy_sample(None, None, None, None, label=label, z=z)
      9     tensor_pred = SVGTensor.from_cmd_args(commands_y[0].cpu(), args_y[0].cpu())
     10 

~/Documents/q/04_deepsvg/deepsvg/deepsvg/model/model.py in greedy_sample(self, commands_enc, args_enc, commands_dec, args_dec, label, z, hierarch_logits, concat_groups, temperature)
    416                       concat_groups=True, temperature=0.0001):
    417         if self.cfg.pred_mode == "one_shot":
--> 418             res = self.forward(commands_enc, args_enc, commands_dec, args_dec, label=label, z=z, hierarch_logits=hierarch_logits, return_tgt=False)
    419             commands_y, args_y = _sample_categorical(temperature, res["command_logits"], res["args_logits"])
    420             args_y -= 1  # shift due to -1 PAD_VAL

~/Documents/q/04_deepsvg/deepsvg/deepsvg/model/model.py in forward(self, commands_enc, args_enc, commands_dec, args_dec, label, z, hierarch_logits, return_tgt, params, encode_mode, return_hierarch)
    375 
    376         out_logits = self.decoder(z, commands_dec_, args_dec_, label, hierarch_logits=hierarch_logits,
--> 377                                   return_hierarch=return_hierarch)
    378 
    379         if return_hierarch:

~/anaconda3/envs/deepsvg/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    530             result = self._slow_forward(*input, **kwargs)
    531         else:
--> 532             result = self.forward(*input, **kwargs)
    533         for hook in self._forward_hooks.values():
    534             hook_result = hook(self, input, result)

~/Documents/q/04_deepsvg/deepsvg/deepsvg/model/model.py in forward(self, z, commands, args, label, hierarch_logits, return_hierarch)
    250             if hierarch_logits is None:
    251                 src = self.hierarchical_embedding(z)
--> 252                 out = self.hierarchical_decoder(src, z, tgt_mask=None, tgt_key_padding_mask=None, memory2=l)
    253                 hierarch_logits, z = self.hierarchical_fcn(out)
    254 

~/anaconda3/envs/deepsvg/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    530             result = self._slow_forward(*input, **kwargs)
    531         else:
--> 532             result = self.forward(*input, **kwargs)
    533         for hook in self._forward_hooks.values():
    534             hook_result = hook(self, input, result)

~/Documents/q/04_deepsvg/deepsvg/deepsvg/model/layers/transformer.py in forward(self, tgt, memory, memory2, tgt_mask, memory_mask, tgt_key_padding_mask, memory_key_padding_mask)
    235                          memory_mask=memory_mask,
    236                          tgt_key_padding_mask=tgt_key_padding_mask,
--> 237                          memory_key_padding_mask=memory_key_padding_mask)
    238 
    239         if self.norm is not None:

~/anaconda3/envs/deepsvg/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    530             result = self._slow_forward(*input, **kwargs)
    531         else:
--> 532             result = self.forward(*input, **kwargs)
    533         for hook in self._forward_hooks.values():
    534             hook_result = hook(self, input, result)

~/Documents/q/04_deepsvg/deepsvg/deepsvg/model/layers/improved_transformer.py in forward(self, tgt, memory, memory2, tgt_mask, tgt_key_padding_mask, *args, **kwargs)
    126     def forward(self, tgt, memory, memory2=None, tgt_mask=None, tgt_key_padding_mask=None, *args, **kwargs):
    127         tgt1 = self.norm1(tgt)
--> 128         tgt2 = self.self_attn(tgt1, tgt1, tgt1, attn_mask=tgt_mask, key_padding_mask=tgt_key_padding_mask)[0]
    129         tgt = tgt + self.dropout1(tgt2)
    130 

~/anaconda3/envs/deepsvg/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    530             result = self._slow_forward(*input, **kwargs)
    531         else:
--> 532             result = self.forward(*input, **kwargs)
    533         for hook in self._forward_hooks.values():
    534             hook_result = hook(self, input, result)

~/Documents/q/04_deepsvg/deepsvg/deepsvg/model/layers/attention.py in forward(self, query, key, value, key_padding_mask, need_weights, attn_mask)
    159                 training=self.training,
    160                 key_padding_mask=key_padding_mask, need_weights=need_weights,
--> 161                 attn_mask=attn_mask)

~/Documents/q/04_deepsvg/deepsvg/deepsvg/model/layers/functional.py in multi_head_attention_forward(query, key, value, embed_dim_to_check, num_heads, in_proj_weight, in_proj_bias, bias_k, bias_v, add_zero_attn, dropout_p, out_proj_weight, out_proj_bias, training, key_padding_mask, need_weights, attn_mask, use_separate_proj_weight, q_proj_weight, k_proj_weight, v_proj_weight, static_k, static_v)
     90         if torch.equal(query, key) and torch.equal(key, value):
     91             # self-attention
---> 92             q, k, v = F.linear(query, in_proj_weight, in_proj_bias).chunk(3, dim=-1)
     93 
     94         elif torch.equal(key, value):

~/anaconda3/envs/deepsvg/lib/python3.7/site-packages/torch/nn/functional.py in linear(input, weight, bias)
   1370         ret = torch.addmm(bias, input, weight.t())
   1371     else:
-> 1372         output = input.matmul(weight.t())
   1373         if bias is not None:
   1374             output += bias

RuntimeError: CUDA error: CUBLAS_STATUS_EXECUTION_FAILED when calling `cublasSgemm( handle, opa, opb, m, n, k, &alpha, a, lda, b, ldb, &beta, c, ldc)`

RuntimeError: The size of tensor a (45) must match the size of tensor b (8) at non-singleton dimension 0

Hello, dear @alexandre01 , I am honored to read your work. I tried to use the model you designed to get the latent space vector z. I extracted some of the module interface combinations you designed to extract the latent space z of an SVG image. Code, I found that through CAD conversion to get the svg image to get the latent space vector z, an error of tensor dimension mismatch will appear in the encode interface, and the latent space vector z, code and error message can be obtained by downloading a simple svg icon As follows, I don’t know why this is, can you help me solve this question?
1.The svg image obtained from the CAD conversion that needs to be processed is as follows:
kuangkuang
kuangkuang

1.The code to extract the latent space vector z is as follows

import os
os.chdir("..")
#%%
from deepsvg.svglib.svg import SVG

from deepsvg import utils
from deepsvg.difflib.tensor import SVGTensor
from deepsvg.svglib.utils import to_gif
from deepsvg.svglib.geom import Bbox
from deepsvg.svgtensor_dataset import SVGTensorDataset, load_dataset, SVGFinetuneDataset
from deepsvg.utils.utils import batchify, linear

import torch
import numpy as np
from torch.utils.data import DataLoader
import torch.nn as nn
device = torch.device("cuda:0"if torch.cuda.is_available() else "cpu")
from IPython.display import display




#%%
pretrained_path = "./pretrained/hierarchical_ordered.pth.tar"
from configs.deepsvg.hierarchical_ordered import Config
print(0)
cfg = Config()
cfg.model_cfg.dropout = 0.  # for faster convergence
model = cfg.make_model().to(device)
utils.load_model(pretrained_path, model)
model.eval();
dataset = load_dataset(cfg)
print(1)
def encode(data):
    model_args = batchify((data[key] for key in cfg.model_args), device)
    with torch.no_grad():
        z = model(*model_args, encode_mode=True)
        return z

def encode_svg(svg):
    data = dataset.get(svg=svg)
    return encode(data)
def load_svg(filename):
    svg = SVG.load_svg(filename)
    svg = dataset.simplify(svg)
    svg = dataset.preprocess(svg, mean=True)
    return svg
print(2)
lego = load_svg("C:/Users/15653/deepsvg/dataset/test/kuangkuang.svg")


print(3)
print(lego)
z = encode_svg(lego)

print(z)
2.The code where the error occurs is as follows
import math
import torch
import torch.nn as nn


class PositionalEncodingSinCos(nn.Module):
    def __init__(self, d_model, dropout=0.1, max_len=250):
        super(PositionalEncodingSinCos, self).__init__()
        self.dropout = nn.Dropout(p=dropout)

        pe = torch.zeros(max_len, d_model)
        position = torch.arange(0, max_len, dtype=torch.float).unsqueeze(1)
        div_term = torch.exp(torch.arange(0, d_model, 2).float() * (-math.log(10000.0) / d_model))
        pe[:, 0::2] = torch.sin(position * div_term)
        pe[:, 1::2] = torch.cos(position * div_term)
        pe = pe.unsqueeze(0).transpose(0, 1)
        self.register_buffer('pe', pe)

    def forward(self, x):
        x = x + self.pe[:x.size(0), :]
        return self.dropout(x)


class PositionalEncodingLUT(nn.Module):

    def __init__(self, d_model, dropout=0.1, max_len=250):
        super(PositionalEncodingLUT, self).__init__()
        self.dropout = nn.Dropout(p=dropout)

        position = torch.arange(0, max_len, dtype=torch.long).unsqueeze(1)
        self.register_buffer('position', position)

        self.pos_embed = nn.Embedding(max_len, d_model)

        self._init_embeddings()

    def _init_embeddings(self):
        nn.init.kaiming_normal_(self.pos_embed.weight, mode="fan_in")

    def forward(self, x):
        pos = self.position[:x.size(0)]
        x = x + self.pos_embed(pos)
        return self.dropout(x)

error

Training classifier on bottleneck

@alexandre01 I am trying to train a classifier on the icons using the bottleneck embeddings that I get by model inference using pretrained model. In some cases though it doesnt seem to work. I used the code in your latent_ops notebook and encode each icon. In some cases I get this error
The size of tensor a (10) must match the size of tensor b (8) at non-singleton dimension 0
Am I missing something?

Errors while preprocessing svg files

Hi,

I used preprocess.py to process icons from the iconfinder dataset, which is a public site for icons. I am getting the following errors. The svg file for one of the icons from the iconfinder dataset is provided below, as an example. Does preprocess.py only work for the icons8 dataset? I would appreciate some guidance for how it can be adapted to process the svg format provided below, which does not include the "viewbox" attribute.

Thanks

svg = SVG.load_svg(svg_file)
File "../deepsvg/svglib/svg.py", line 74, in load_svg
    return SVG.from_str(f.read())
File "../deepsvg/svglib/svg.py", line 124, in from_str
    viewbox_list = list(map(float, svg_root.getAttribute("viewBox").split(" ")))
ValueError: could not convert string to float: 

<?xml version="1.0" ?><svg height="100" id="svg6584" version="1.1" width="100" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg"><defs id="defs6586"/><g id="layer1" transform="translate(0,-952.362)"><path d="m 45.833336,973.19536 -39.583305,22.91663 8.333327,0 0,4.16661 0,25.0001 0,4.1666 c 0,2.0834 1.858332,4.1667 4.166664,4.1667 l 12.499991,0 0,-20.8333 c 0,-2.3084 1.858291,-4.1667 4.166664,-4.1667 l 29.166646,0 c 2.308373,0 4.09458,1.8595 4.166663,4.1667 l 0,20.8333 12.499992,0 c 2.308331,0 4.166663,-1.8583 4.166663,-4.1667 l 0,-4.1666 0,-25.0001 0,-4.16661 8.333328,0 -39.583305,-22.91663 C 52.38554,972.16411 50.632666,971.11412 50,971.11203 c -0.63275,-0.002 -2.358248,1.03625 -4.166664,2.08333 z m -10.416659,39.58334 0,4.1666 29.166646,0 0,-4.1666 z m 0,8.3333 0,4.1667 29.166646,0 0,-4.1667 z m 0,8.3333 0,4.1667 29.166646,0 0,-4.1667 z" id="path4181" style="color:#000000;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"/></g></svg>

Tensor sizes do not match

@alexandre01 congratulations on your work! I have a question to a tensor problem that I encountered.

When using 'interpolate_icons(icon1, icon2)' on different SVGs (created with Adobe/Rhino3d + preprocessed using preprocess.py + to batch convert SVGs to *.pkl tensors from @matuz-z here: #5), I got the following message:

RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 35 and 32 in dimension 1 at C:\w\1\s\windows\pytorch\aten\src\TH/generic/THTensor.cpp:612

For some SVGs created with Adobe Illustrator this worked and there was no error.

Have I misunderstood something? I would appreciate very much your help!

Misleading Markdown

Hello,

I just wanted to point out a possible error in the description of your encoding.
Here you say that the first row containts the command, but in reality, each row describes a whole command, with the first column being the command type and the rest being its args.

Is that correct?

Regards,
Wamiq

Metrics for RE and IS

Hej Alexandre, thanks for the cool work on SVGs!

I am trying to reproduce your table with quantitative measurements, but cannot find the Reconstruction Error (RE) and Interpolation Smoothness (IS) in the codebase. Could you point me to them (or do you mind sharing them)?

Requirments setup error

Hello there ,
I am trying to install the dependencies by following the instrucition in the read me file but this error happens after executing pip install requirments.txt
ERROR: Could not find a version that satisfies the requirement torch==1.4.0 (from versions: 1.7.0, 1.7.1, 1.8.0, 1.8.1, 1.9.0, 1.9.1, 1.10.0, 1.10.1, 1.10.2, 1.11.0)
ERROR: No matching distribution found for torch==1.4.0

Enhancement: Google Colab

This is such an amazing project, but my lack of coding knowledge has rendered me incapable of testing it out for myself. I do not want to inconvenience you, but I am sure others would find this helpful as well. Could you add a Google Colab Notebook as a way to democratize?

I can not open the pretrained model file

Screenshot from 2020-07-27 11-00-15

I think download is good,but I can not uncompressed this。

I try to some method but all failed, and I download twice the result is the same

How I fix it ??

More robust svg parser :)

Thank you for your work and contribution ! but when I want to process my datasets , it's not work .
Can you support more SVG methods looks like svgpathtools?
Two error svg data samples :
<svg class="icon" height="1024px" p-id="37334" style="" version="1.1" viewbox="0 0 1191 1024" width="1191px" x="0px" xmlns="http://www.w3.org/2000/svg" y="0px"> <path d="M1167.959613 65.770695c-0.996526 0 0 0 0 0-40.857553-61.784593-115.59698-83.708158-168.412841-49.826284 0 0-122.57266 84.704683-274.044564 195.319035L149.510361 39.861027c-23.916616-6.97568-39.861027 22.920091-20.92704 38.864502l356.756196 315.898643C393.659154 469.363599 307.957945 541.113448 249.162929 596.918887c-1.993051 1.993051-3.986103 2.989577-6.975679 1.993051L52.847369 528.158614C9.996765 511.217678-19.899006 568.019642 15.975919 594.925835l155.458007 113.603929 39.861027 188.343354c8.968731 44.843656 73.742901 39.861027 76.732478-4.982628l13.95136-202.294714c0-2.989577 1.993051-4.982628 3.986103-5.979155 75.735952-30.892296 174.391995-78.725529 280.023718-132.537916L727.495259 1007.48747c6.97568 23.916616 40.857553 20.927039 44.843656-2.989577L853.057496 408.575532c163.430213-91.680363 290.985501-168.412841 290.985501-168.412841 51.819336-33.881873 62.781118-112.607403 23.916616-174.391996z m-67.763747 145.492751l-26.906193 17.937462-93.673415-145.49275 26.906194-17.937463c37.867976-23.916616 87.69426-12.954834 111.610877 23.916617l5.979154 8.968731c24.913142 37.867976 13.95136 87.69426-23.916617 112.607403z m67.763747-145.492751c-0.996526 0 0 0 0 0z" fill="#FE8950" p-id="37335"> </path> </svg>
<svg class="icon" height="1024px" p-id="37323" style="" version="1.1" viewbox="0 0 1024 1024" width="1024px" x="0px" xmlns="http://www.w3.org/2000/svg" y="0px"><path d="M871.1 642.1c27.7-31.9 40.8-60.8 30.7-72.9-7-8.4-23.9-7.2-45.7 1.4l-7.7-36.5c24.6-30.7 35.2-58.1 24.7-71.1-6.8-8.5-21.5-9.5-40.6-4.5l-20.2-95.9C931 221.9 980.1 104.6 949.4 73.9c-30.7-30.7-148 18.4-288.8 137.1l-95.9-20.2c5-19.1 4-33.8-4.5-40.6-13-10.5-40.4 0.1-71.1 24.7l-36.5-7.7c8.6-21.8 9.8-38.7 1.4-45.7-12.1-10.1-41 3-72.9 30.7L237.7 122l-76.9 76.9 132 68.2c-11.3 25.1-13.7 45-4.4 52.7 10.9 9.1 35.1-0.5 63-22.5l32.2 16.6c-10.8 27.5-12.1 49.1-1.2 57.9 12.7 10.2 39 0.3 68.8-23l45.4 23.4c-1.3 1.5-2.7 3-4 4.5-85 96.8-161.2 187.6-216.9 262.9L122.4 622l-57.7 57.7 135.6 77c-18.6 37.2-23.5 64-10.6 76.9 12.9 12.9 39.7 8 76.9-10.6l77 135.6 57.7-57.7-17.7-153.3c75.3-55.7 166.1-131.9 262.9-216.9 1.5-1.3 3-2.7 4.5-4l23.4 45.4c-23.3 29.8-33.2 56.1-23 68.8 8.7 10.9 30.4 9.5 57.9-1.2l16.6 32.2c-22 27.9-31.5 52.1-22.5 63 7.7 9.3 27.6 6.8 52.7-4.4l68.2 132 76.9-76.9-30.1-143.5z m0 0" p-id="37324"></path></svg>

how to build a dataset

I want to train with my own dataset, it is like FONT-SVG dataset.

but the original data format is .ttf, So My qestion is how to build a dataset as yours(.csv and *.pth)

  1. Mybe I can export some_char from *.ttf to some_char.svg, but if you know how to batch export , please tell me

  2. How some_char.svg convert to *.pth ?
    My guess:

svg=SVG.load_svg("some_char.svg“).normalize().zoom(0.9).canonicalize().simplify_heuristic()
tensor_data = svg.to_tensor()
svg_data = SVGTensor.from_data(tensor_data)

torch.save("filename", tensor_data) ???
  1. In svgtensor.ipynb , if I want to optimize from Img2 to Img1 ,not from SVG.unit_circle() to Img1, how should I do,
    I tried replaced svg_pred with other SVG.load_data() , but occur the Error:

Attribute Error: 'Point' object has no attribute ”control1“, "control2", "requires_grad_"

Feature request: support transform

SVG files use usually contain transform tags like the following, but the current library does not seem to support it (as long as I see in svg.py).

<g transform="rotate(-10 50 100) translate(-36 45.5) skewX(40) scale(1 0.5)">

Is there any plan to support?

TypeError: must be real number, not NoneType

Hello, I'm trying out the svglib.ipynb but whenever I call icon.animate(frame_duration=0.1) I get
'TypeError: must be real number, not NoneType'.

I've also tried it in a fresh notebook, only using:

from deepsvg.svglib.svg import SVG
from deepsvg.svglib.geom import Point, Angle

icon = SVG.load_svg("docs/imgs/dolphin.svg").normalize()
icon.simplify_heuristic() # path simplifcation
icon.zoom(0.75).translate(Point(0, 5)).rotate(Angle(15)) # scale, translate, rotate
icon.draw()
icon.animate()
and get the same error. Here's the full stack trace:


TypeError Traceback (most recent call last)
/tmp/ipykernel_8601/3006857264.py in
----> 1 icon.animate(frame_duration=0.1)

~/Documents/Master_Thesis/Research_Projects/deepsvg/deepsvg/svglib/svg.py in animate(self, file_path, frame_duration, do_display)
388 if do_display:
389 src = clip if file_path is None else file_path
--> 390 ipd.display(ipython_display(src, fps=24, rd_kwargs=dict(logger=None), autoplay=1, loop=1))
391
392 def numericalize(self, n=256):

~/anaconda3/envs/deepsvg/lib/python3.7/site-packages/moviepy/video/io/html_tools.py in ipython_display(clip, filetype, maxduration, t, fps, rd_kwargs, center, **html_kwargs)
218
219 return HTML2(html_embed(clip, filetype=filetype, maxduration=maxduration,
--> 220 center=center, rd_kwargs=rd_kwargs, **html_kwargs))

~/anaconda3/envs/deepsvg/lib/python3.7/site-packages/moviepy/video/io/html_tools.py in html_embed(clip, filetype, maxduration, rd_kwargs, center, **html_kwargs)
95 kwargs = {'filename':filename, 'verbose':False, 'preset':'ultrafast'}
96 kwargs.update(rd_kwargs)
---> 97 clip.write_videofile(**kwargs)
98 elif isinstance(clip,AudioClip):
99 filename = TEMP_PREFIX+".mp3"

~/anaconda3/envs/deepsvg/lib/python3.7/site-packages/decorator.py in fun(*args, **kw)
230 if not kwsyntax:
231 args, kw = fix(args, kw, sig)
--> 232 return caller(func, *(extras + args), **kw)
233 fun.name = func.name
234 fun.doc = func.doc

~/anaconda3/envs/deepsvg/lib/python3.7/site-packages/moviepy/decorators.py in requires_duration(f, clip, *a, **k)
52 raise ValueError("Attribute 'duration' not set")
53 else:
---> 54 return f(clip, *a, **k)
55
56

~/anaconda3/envs/deepsvg/lib/python3.7/site-packages/decorator.py in fun(*args, **kw)
230 if not kwsyntax:
231 args, kw = fix(args, kw, sig)
--> 232 return caller(func, *(extras + args), **kw)
233 fun.name = func.name
234 fun.doc = func.doc

~/anaconda3/envs/deepsvg/lib/python3.7/site-packages/moviepy/decorators.py in use_clip_fps_by_default(f, clip, *a, **k)
135 for (k,v) in k.items()}
136
--> 137 return f(clip, *new_a, **new_kw)

~/anaconda3/envs/deepsvg/lib/python3.7/site-packages/decorator.py in fun(*args, **kw)
230 if not kwsyntax:
231 args, kw = fix(args, kw, sig)
--> 232 return caller(func, *(extras + args), **kw)
233 fun.name = func.name
234 fun.doc = func.doc

~/anaconda3/envs/deepsvg/lib/python3.7/site-packages/moviepy/decorators.py in convert_masks_to_RGB(f, clip, *a, **k)
20 if clip.ismask:
21 clip = clip.to_RGB()
---> 22 return f(clip, *a, **k)
23
24 @decorator.decorator

~/anaconda3/envs/deepsvg/lib/python3.7/site-packages/moviepy/video/VideoClip.py in write_videofile(self, filename, fps, codec, bitrate, audio, audio_fps, preset, audio_nbytes, audio_codec, audio_bitrate, audio_bufsize, temp_audiofile, rewrite_audio, remove_temp, write_logfile, verbose, threads, ffmpeg_params, logger)
324 verbose=verbose, threads=threads,
325 ffmpeg_params=ffmpeg_params,
--> 326 logger=logger)
327
328 if remove_temp and make_audio:

~/anaconda3/envs/deepsvg/lib/python3.7/site-packages/moviepy/video/io/ffmpeg_writer.py in ffmpeg_write_video(clip, filename, fps, codec, bitrate, preset, withmask, write_logfile, audiofile, verbose, threads, ffmpeg_params, logger)
209 preset=preset, bitrate=bitrate, logfile=logfile,
210 audiofile=audiofile, threads=threads,
--> 211 ffmpeg_params=ffmpeg_params) as writer:
212
213 nframes = int(clip.duration*fps)

~/anaconda3/envs/deepsvg/lib/python3.7/site-packages/moviepy/video/io/ffmpeg_writer.py in init(self, filename, size, fps, codec, audiofile, preset, bitrate, withmask, logfile, threads, ffmpeg_params)
83 '-s', '%dx%d' % (size[0], size[1]),
84 '-pix_fmt', 'rgba' if withmask else 'rgb24',
---> 85 '-r', '%.02f' % fps,
86 '-i', '-', '-an',
87 ]

TypeError: must be real number, not NoneType

I'd be very grateful I anybody could tell me how to run the notebook :)

Differentiable .draw

How would one go about extending the library to include a differentiable SVG.draw() function? Ideally, this would allow a neural network to flow gradients from the output SVG image to the SVG code.

Thanks!

Request of full version of the font dataset

I want to test my ideas to improve DeepSVG using the font dataset.
First, I followed the instruction.

To download the Font-dataset, we recommend following SVG-VAE's instructions: https://github.com/magenta/magenta/tree/master/magenta/models/svg_vae

However, as I see here, the code to convert .tff format -> parquetio database format does not exist, and it is too hard for me. I guess you have successfully made it. Could you kindly share scripts to do that, or the full version of the font dataset directly?

How to optimize from Img2 to Img1 ,not from SVG.unit_circle() to Img1

In svgtensor.ipynb , if I want to optimize from Img2 to Img1 ,not from SVG.unit_circle() to Img1, how should I do,
I tried replaced svg_pred with other SVG.load_data() , but occur the Error:
Attribute Error: 'Point' object has no attribute ”control1“, "control2", "requires_grad_"

Could you post a simple example of how to view the icon .pkl files?

I'm interested in taking a look at the icons in the dataset. As currently only the .pkl files are available would it be possible to get an example of how to view these? The notebooks all either work from .svg or generating an SVG from scratch.

So far I have something like this:

from pathlib import Path
from deepsvg.svglib.geom import Bbox
from deepsvg.svglib.svg import SVG
from deepsvg.difflib.tensor import SVGTensor
from deepsvg.svgtensor_dataset import load_dataset
from configs.deepsvg.hierarchical_ordered import Config


cfg = Config()
dataset = load_dataset(cfg)
idx = 1
svg_tensor = SVGTensor.from_cmd_args(dataset[idx]["commands"][0], dataset[idx]["args"][0])
svg_obj = SVG.from_tensor(svg_tensor.data, viewbox=Bbox(256), allow_empty=True).normalize().split_paths().set_color("random")
png_file = Path(f"dataset_{idx}.png")
svg_obj.save_png(png_file)
    

But this gives me a ValueError: 'SOS' is not a valid SVGCmdEnum error.
Any advice on fixing this code or more generally the best way to look at the .pkl data?
Thanks in advance for your help!

DeepSVG for text-conditioned vector generation.

I wonder if it's possible to adapt DeepSVG to replace the VAE block in stable diffusion to generate vector graphics?

I see a couple of problems.

  1. The latent embedding size in DeepSVG (256) does not match latent embedding size of SD (64).
  2. diffusers library expects bin file instead of pth. There is a script to convert it to diffusers but it seems to use AutoencoderKL, which I'm not sure the right architecture.

I wonder if you know an easy way to adopt DeepSVG for diffusers library?

Path Encodings

Hi @alexandre01, amazing work! For a university project, we are planning to use the deepSVG architecture to obtain path encodings from SVG files. According to your paper, I think the output of decoder D(2) is what I am looking for. To get the latent vector z of a SVG file, I used the encode function from notebooks/latent_ops.ipynb. I now need to use the decoder D(2) to obtain the path encodings. Unfortunately, I couldn't figure out how to perform that step. I would appreciate it if you could help me out!

SVG.from_tensor()

Hello!
I'm trying to get a svg file from tensor by using your method from_tensor() in deepsvg.svglib.svg, but as I open the svg file exported, there is nothing displayed, it's just all white in the Chrome.
I don`t understand the reason.
Thank you!

ALSA lib errors when importing SVG

Hi,
I tried out the following small example program that is in the README. as a python script and ran it on the command line. But I am get errors related to ALSA lib when the import SVG line is executed. The code and errors are provided below. I have installed all the dependencies listed in the requirements file, but I am using a more recent version of torch (1.8.1) and torchvision. ALSA lib seems to be related to sound card, I am not sure how it is related to the SVG library. I would appreciate any suggestions for fixing these ALSA lib errors.

thanks

import sys
sys.path.append("../")
from deepsvg.svglib.svg import SVG    #<--- results in the errors below
from deepsvg.svglib.geom import Point, Angle

icon = SVG.load_svg("../docs/imgs/dolphin.svg").normalize()
icon.simplify_heuristic()  #simplify path
icon.zoom(0.75).translate(Point(0, 5)).rotate(Angle(15)) #scale,translate,rotate
icon.draw()

ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM default
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM default


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.