When traning a neural network, there is lot’s of details that require attention, like how to set the learning rate, how to plot the fig, how to manage your project, etc. These details have no relations with the fundamental basis or the first principle of machine learning, they are just a sort of words of experience.
For green hands, there exists a huge gap between simply comprehending and copying other peoples neural networks from coding one’s own neural network. It’s a tough but effective process. Thus, I want to record my road of practicing deep learning by updating my Blog. This passage won’t discuss the basic principle and only involve my own experiences and insights during my practical process.
If you want to update this blog with your own experiences, just contact with the author.
20250310 Using matplotlib in Linux
When using matplotlib in my WSL subsystem, I encountered errors as follows:
1 2 3 4 5 6
qt.qpa.plugin: Could not load the Qt platform plugin "xcb"in"" even though it was found. This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
It seems that Linux cannot load the Qt platform plugin, which as a result failed to load the images.
Solutions
We cannot let Linux to directly show the plotted figure in the terminal for its lack of GUI interface. But we can realize it by changing Matplotlib’s backend:
1 2 3 4 5 6 7 8 9 10 11 12 13
import matplotlib as mpl mpl.use('Agg') #... #... import matplotlib.plt as plt # forbid scientific notation np.set_printoptions(suppress=True)
# Then showing the figure by saving the figures.
plt.savefig("save/img.png")
Of course, you can use juypter notebook instead. Remember! Use plt.close() if you want to save more than one image.
# Example output directory output_dir = "your_project/outputs/20231025_123456"
# Save model checkpoint model_checkpoint_path = os.path.join(output_dir, "model_checkpoint.pth") # torch.save(model.state_dict(), model_checkpoint_path) # PyTorch example
# Save training log log_file_path = os.path.join(output_dir, "training_log.txt") withopen(log_file_path, "w") as f: f.write("Epoch 1, Loss: 0.123\n")