yizhiwang96 / deepvecfont

[SIGGRAPH Asia 2021] DeepVecFont: Synthesizing High-quality Vector Fonts via Dual-modality Learning
MIT License
182 stars 31 forks source link

The command length for SVG <=50 #30

Open graphl opened 1 year ago

graphl commented 1 year ago

Hi,Does the model only support fonts with a length SVG command length of less than 50? I found that the is_valid_path function of the svg_util is called on line 71 of the write_data_to_dirs.py file,An SVG command is only valid if the length < = 50

image

I'd like to change this to 50 instead of 100, 200, 300 or 1000, is that okay? Was it set to 50 because it worked best when it was set to 50?

christinalc commented 1 year ago

Hi, I have a similar question. For context, I am testing with an input font that has a character with about 1200 paths.

After writing data to dirs, in the data_utils/font_sfds logs folder, there's this error: font 0000, char 00's sfd is not valid path. So I changed the command length from 50 to 2000 in svg_util, and the error stopped appearing in the log. But in the terminal I received this ValueError: cannot reshape array of size 20010 into shape when running python write_data_to_dirs.py --split test. This is the full error:

  File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
Traceback (most recent call last):
  File "/usr/lib/python3.9/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/home/christina/Desktop/deepvecfont/data_utils/write_data_to_dirs.py", line 78, in process
    example = svg_utils.create_example(pathunibfp)
  File "/home/christina/Desktop/deepvecfont/data_utils/svg_utils.py", line 964, in create_example
    final['sequence'] = np.reshape(final['sequence'], [51 * 10]).astype(np.float32).tolist()
  File "<__array_function__ internals>", line 200, in reshape
  File "/home/christina/.local/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 298, in reshape
    return _wrapfunc(a, 'reshape', newshape, order=order)
  File "/home/christina/.local/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 57, in _wrapfunc
    return bound(*args, **kwds)
  File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/usr/lib/python3.9/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/home/christina/Desktop/deepvecfont/data_utils/write_data_to_dirs.py", line 78, in process
    example = svg_utils.create_example(pathunibfp)
ValueError: cannot reshape array of size 20010 into shape (510,)
  File "/home/christina/Desktop/deepvecfont/data_utils/svg_utils.py", line 964, in create_example
    final['sequence'] = np.reshape(final['sequence'], [51 * 10]).astype(np.float32).tolist()
  File "<__array_function__ internals>", line 200, in reshape
  File "/home/christina/.local/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 298, in reshape
    return _wrapfunc(a, 'reshape', newshape, order=order)
  File "/home/christina/.local/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 57, in _wrapfunc
    return bound(*args, **kwds)
ValueError: cannot reshape array of size 20010 into shape (510,)
Traceback (most recent call last):
  File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/usr/lib/python3.9/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/home/christina/Desktop/deepvecfont/data_utils/write_data_to_dirs.py", line 78, in process
    example = svg_utils.create_example(pathunibfp)
  File "/home/christina/Desktop/deepvecfont/data_utils/svg_utils.py", line 964, in create_example
    final['sequence'] = np.reshape(final['sequence'], [51 * 10]).astype(np.float32).tolist()
  File "<__array_function__ internals>", line 200, in reshape
  File "/home/christina/.local/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 298, in reshape
    return _wrapfunc(a, 'reshape', newshape, order=order)
  File "/home/christina/.local/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 57, in _wrapfunc
    return bound(*args, **kwds)
ValueError: cannot reshape array of size 20010 into shape (510,)
Traceback (most recent call last):
  File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/usr/lib/python3.9/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/home/christina/Desktop/deepvecfont/data_utils/write_data_to_dirs.py", line 78, in process
    example = svg_utils.create_example(pathunibfp)
  File "/home/christina/Desktop/deepvecfont/data_utils/svg_utils.py", line 964, in create_example
    final['sequence'] = np.reshape(final['sequence'], [51 * 10]).astype(np.float32).tolist()
  File "<__array_function__ internals>", line 200, in reshape
  File "/home/christina/.local/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 298, in reshape
    return _wrapfunc(a, 'reshape', newshape, order=order)
  File "/home/christina/.local/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 57, in _wrapfunc
    return bound(*args, **kwds)
ValueError: cannot reshape array of size 20010 into shape (510,)
Process Process-1:
Traceback (most recent call last):
  File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/usr/lib/python3.9/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/home/christina/Desktop/deepvecfont/data_utils/write_data_to_dirs.py", line 78, in process
    example = svg_utils.create_example(pathunibfp)
  File "/home/christina/Desktop/deepvecfont/data_utils/svg_utils.py", line 964, in create_example
    final['sequence'] = np.reshape(final['sequence'], [51 * 10]).astype(np.float32).tolist()
  File "<__array_function__ internals>", line 200, in reshape
  File "/home/christina/.local/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 298, in reshape
    return _wrapfunc(a, 'reshape', newshape, order=order)
  File "/home/christina/.local/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 57, in _wrapfunc
    return bound(*args, **kwds)
ValueError: cannot reshape array of size 20010 into shape (510,)

CC: @yihui-hu

yizhiwang96 commented 1 year ago

Sorry, I am tied up recently. I will try to make a response later.

graphl commented 1 year ago

@christinalc

After writing data to dirs, in the data_utils/font_sfds logs folder, there's this error: font 0000, char 00's sfd is not valid path. So I changed the command length from 50 to 2000 in svg_util, and the error stopped appearing in the log. But in the terminal I received this ValueError: cannot reshape array of size 20010 into shape when running python write_data_to_dirs.py --split test

You may also need to modify two other places: Here 50 is modified to 1200 Here 51 is modified to 1201

yizhiwang96 commented 1 year ago

Thank you @graphl for the answering! LSTMs are not good at modeling long range dependencies. In DeepVecFont-V2 we replaced LSTM with Transformers, and produce much better results for long drawing sequences. We will release the code as soon as possible, Thank you! @christinalc @yihui-hu