I wanted to learn the truth of the image at Colaboratory, but it was difficult to collect information in various places. So I decided to ** paste the finished product as it is **. For those who understand Python somehow.
Don't https://colab.research.google.com/drive/1ETjxVKCA3zv391tEAY5RHM_cyipIA9D-?hl=ja
I don't think anyone can use it as it is, but I hope it helps someone. ** I made it without knowing Jupyter-notebook or Python, so I hope you can point out something. ** **
This is what I wanted to do.
--Use Colaboratory ――I want to learn the truth of the image --Deep learning --Training data (image) is on Google Drive --The image is a PNG file with a width of 100px and a height of 150px. --The image is compressed with ZIP, and the folder structure is as follows. ――I want to see the learning history in a graph, and I want to save the graph and model information in Google Drive.
Write an explanation of what you are doing easily. Visit the Colaboratory and see the code.
Mount Google Drive. As you can see. It seems that GitHub is often used in the world. With Google Drive, authentication is troublesome every time.
Extract the ZIP file of the training data in Google Drive to a disk. It is possible to read each image of training data from Google Drive, but it is slow. I do this because it's much faster to zip it up, unzip it all to disk, and then read it from disk.
I wanted the training data and test data to have the same number of truths, so I made a generator generate_paths
that shuffles and returns image paths alternately.
That is,
As false 0-1, 0-2, 0-3, 0-4, 0-5
As true 1-1, 1-2, 1-3, 1-4, 1-5
Assuming there were 10 images of
0-3, 1-5, 0-1, 1-1, 0-2, 1-3, 0-4, 1-4, 0-5, 1-2
Returns like.
It might have been easier to understand if you shuffled the list normally without using a generator.
In the load_data
method, the image is actually read and made into an array. Most of the images dealt with this time have a white background, so I set them to 1 --X / 255
and invert them to a floating point number of 0 to 1. It is roughly 0, and sometimes there is a 1.
There are also color images, so the number of input channels is 3.
I will do my best to learn. Don't forget to save the time you finished so you know when you finished learning.
import datetime
tz_jst = datetime.timezone(datetime.timedelta(hours=9), name="JST")
now = datetime.datetime.now(tz_jst)
str_now = now.strftime("%Y/%m/%d %H:%M:%S")
print(f"Training is over{str_now}")
Save the entire model and its architecture.
Display it on the screen with % matplotlib inline
and save it in Google Drive.
Colaboratory, GPU, etc. are very convenient to use for free. It would be nice to be able to access it from anywhere, even from an iPhone. However, it's sad that GPU and TPU can't be used in the daytime.
Regarding the learning result, accuracy, over 0.7 ... I tried various trials and errors, but it's a little subtle ... I can't say what the training data is, but I believe the training data is bad (or rather bad) for this result.
Recommended Posts