mert-kurttutan / torchview

torchview: visualize pytorch models
https://torchview.dev
MIT License
822 stars 37 forks source link

Missing font on Windows #84

Open cngmid opened 1 year ago

cngmid commented 1 year ago

I have installed torchview on Windows using conda install. When diaplying a simple graph, I'm getting the following warning: (process:20416): Pango-WARNING **: 09:23:59.938: couldn't load font "Linux libertine Not-Rotated 10", falling back to "Sans Not-Rotated 10", expect ugly output. The graph is displayed correctly after the warning. Is there a way to configure the module to avoid this?

Steps to reproduce the behavior:

  1. Install torchview from conda-forge: conda install torchview. Version installed: torchview-0.2.6.
  2. Create a simple torch model: torch.nn.Linear(in_features=1, out_features=1, device=device).
  3. Create a model graph: from torchview import draw_graph; model_graph = draw_graph(model, input_size=(32, 1), device='cuda').
  4. Display it: model_graph.visual_graph.
  5. Get the warning.
mert-kurttutan commented 1 year ago

I was able to reproduce it. It turns out Linux libertine and some other fonts are not available in Windows (as you said) but available in Linux. Until I can find an similar font for windows and put it into the codebase, you try to change it manually right after the creation of graph object as a temporary solution. In your case this would be,

import torch

device = "cpu"
from torchview import draw_graph;
model = torch.nn.Linear(in_features=1, out_features=1, device=device)
model_graph = draw_graph(model, input_size=(32, 1), device=device)
model_graph.visual_graph.node_attr["fontname"] = "Helvetica"

If you have a font suggestion that resembles Linux libertine visually and available in windows, I would appreciate it.

cngmid commented 1 year ago
model_graph.visual_graph.node_attr["fontname"] = "Helvetica"

Thanks!! This works. Helvetica looks good. According to wikipedia Linux libertine is an "interpretation" of the Time New Roman font. So it might be a good idea to use "Times-Roman", which works well on my machine too.

mert-kurttutan commented 1 year ago

Now that you mention times new roman, I recall that I wanted Linux libertine because its purpose was to provide open source alternative . I think Times Roman would be OK.

nchaly commented 1 year ago

Just a piece of advice: Linux libertine is indeed a part of Open Fonts Project, which means that you can distribute it freely. You can include the font into your package distribution, and refer to it locally as a usual resource.