Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ssotobayashi-m opened this issue Dec 16, 2021 · 2 comments
Closed

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

ssotobayashi-m opened this issue Dec 16, 2021 · 2 comments

Comments

@ssotobayashi-m
Copy link

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
Copy link
Author

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

So, I close this issue.

@yizhiwang96
Copy link
Owner

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.👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants