yizhiwang96 / deepvecfont

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

An error occurs using my own mean.npz and stdev.npz #10

Closed ssotobayashi-m closed 2 years ago

ssotobayashi-m commented 2 years ago

I've customized my own dataset and I'm getting errors loading mean.npz and stdev.npz when running main.py. I found out that the type of the loaded data was numpy.lib.npyio.NpzFile. The mean and stdev files downloaded from Google drive seem to be actually .npy format, so the problem does not occur. write_data_to_pkl.py saves them by np.savez, so for example it seems that the load side can support both formats if you do as follows:

@@ -89,9 +89,14 @@ def train_main_model(opts):

     if opts.tboard:
         writer = SummaryWriter(log_dir)
-    
-    mean = np.load('./data/mean.npz')
-    std = np.load('./data/stdev.npz')
+
+    def extract_npz_if_needed(data):
+        if not isinstance(data, np.ndarray):
+            data = data[data.files[0]]
+        return data
+
+    mean = extract_npz_if_needed(np.load('./data/mean.npz'))
+    std = extract_npz_if_needed(np.load('./data/stdev.npz'))
     mean = torch.from_numpy(mean).to(device).to(torch.float32)
     std = torch.from_numpy(std).to(device).to(torch.float32)
     network_modules= [img_encoder, img_decoder, modality_fusion, vggptlossfunc, svg_encoder, svg_decoder, mdn_top_layer, neural_rasterizer]
ssotobayashi-m commented 2 years ago

I'm sorry. I overlooked the correction: https://github.com/yizhiwang96/deepvecfont/commit/764ab68f96479c27740f837abb31365baa5b7d1b

So, I close this issue.

yizhiwang96 commented 2 years ago

I'm sorry. I overlooked the correction: 764ab68

So, I close this issue.

Yes, The mean and stdev files are actually .npy format. I rename the npy to npz to avoid modifying `main.py'. For English fonts, it is suggested to use the mean and stddev files we provided. If you use the mean and stddev files calculated from your own data, you need to retrain the neural rasterizer. If you have any questions, please do not hesitate to contact me.👍