For example, when running this code
from import plot_model
plot_model(model, to_file='images/model_mnist.png', show_shapes=True, show_layer_names=True)
will report an error
In [8]: FileNotFoundError: [Errno 2] No such file or directory: 'images/model_mnist.png'
The name of the py file running at this point is
If the files to be imported are in the same level of the images folder, then you should make sure that the files to be imported are in the same level of the images folder.
imagesmodel_mnist.png
To be in the same directory as the previous temp file (not satisfied, you can move imagesmodel_mnist.png to the same directory) or to provide the full directory of the file to be imported i.e. writing absolute path as follows:
from import plot_model
plot_model(model, to_file='C:/Users/MMIS/.spyder-py3/imagesmodel_mnist.png', show_shapes=True, show_layer_names=True)
Try the import again and the console prompts that the import was successful:
In [9]: plot_model(model, to_file='C:/Users/MMIS/.spyder-py3/images/model_mnist.png', show_shapes=True, show_layer_names=True)
Additional knowledge:Python:incorrectFileNotFoundError: [Errno 2] No such file or directory: 'objects/
preamble
I watched WeChat push a fun app intensive learning dinosrun, but when I ran it, I ran into this problem and couldn't figure it out:
FileNotFoundError: [Errno 2] No such file or directory: ‘objects/
After studying, the solution was found:
account for
There is no such folder or the file, that is, you access the non-existent file, but in fact, you access the file if it does not exist, cut access to use the w method of the method, it will be a new document, so the problem is mainly, there is no such folder, a new one can be.
elaborate
The python, os library has requirements for reading and writing files. Since your file's open mode is 'w', that is, file is created when it doesn't exist, so that pkl file (I mean pkl in relative path) will be created automatically if it doesn't exist, this is not a problem, the problem lies in that relative path, that is, whether that path exists or not, this folder doesn't exist, as well as the problem will occur. So you need to determine whether the path exists first. If it doesn't exist, it will be created.
import os if not (path): (path)
And note that for paths you can only create one layer at a time, that is to say the existence of the layer above your objects, otherwise you will still get an error.
The above article to solve the Python FileNotFoundError problem when importing files is all that I have shared with you.