树莓派 神经网络植入_使用自动编码器和TensorFlow进行神经植入
樹莓派 神經網絡植入
直覺 (Intuition)
Photo by Markus Winkler on Unsplash Markus Winkler在Unsplash上拍攝的照片Imagine you’re solving a Jigsaw puzzle. You have completed most of it. Suppose you need to fix a piece in the middle of a picture ( which is nearly complete ). You need a choose a piece from the box which would into a fit in the space and also complete the whole picture.
想象您正在解決拼圖游戲。 您已經完成了大部分工作。 假設您需要在圖片中間修復一塊(幾乎完成了)。 您需要從包裝盒中選擇一塊,以適合該空間并完成整個圖片。
I’m sure you can do this quickly. But how’s your brain doing this?
我確定您可以快速完成此操作。 但是你的大腦怎么樣?
First, it analyses the picture around the empty slot ( where you need to fix a piece of the puzzle ). If there’s a tree in the picture, you’ll search for a green coloured piece ( which is obvious! ). So, in a nutshell, our brain is able to predict the piece ( which will fit into the slot ) by knowing the surrounding context of the image.
首先,它分析空白插槽(您需要修復其中的難題)周圍的圖片。 如果圖片中有一棵樹,您將搜索一塊綠色的(這很明顯!)。 因此,簡而言之,我們的大腦就能通過了解圖像的周圍環境來預測片段(將適合插槽)。
Our model, in this tutorial, is going to perform a similar task. It will learn the image’s context and then predict a part of the image ( which is missing ) using this learned context.
在本教程中,我們的模型將執行類似的任務。 它將學習圖像的上下文,然后使用此學習的上下文預測圖像的一部分(丟失)。
代碼實施 (Code Implementation)
I recommend you should open this notebook (the TF implementation) in another tab so that you have an intuition of what’s going on.
我建議您在另一個選項卡中打開此筆記本(TF實現),以便直觀了解正在發生的事情。
問題陳述 (Problem Statement)
We’d like our model to predict a part of an image. Given an image with a hole (a part of the image array which contains only zeros), our model will predict the original image which is complete.
我們希望我們的模型能夠預測圖像的一部分。 給定一個帶Kong的圖像(圖像數組的一部分僅包含零),我們的模型將預測完整的原始圖像。
So our model will reconstruct the missing part of the image using the context it learned during training.
因此,我們的模型將使用在訓練中學習到的上下文來重建圖像的缺失部分。
Image By Author圖片作者數據 (The Data)
We’ll select a single domain for our task. We are choosing a number of mountain images that are a part of the Intel Image Classification dataset by Puneet Bansal on Kaggle.
我們將為任務選擇一個域。 我們正在選擇許多山峰圖像,這些山峰圖像是Kaggle上Puneet Bansal 撰寫的“ 英特爾圖像分類”數據集中的一部分。
Why only images of mountains?
為什么只有山的影像?
Here, we choose images which belong to a particular domain. If we choose a dataset which has in the wild images, our model will not perform well. Hence, we restrict it to a single domain.
在這里,我們選擇屬于特定域的圖像。 如果我們選擇包含野外圖像的數據集,則我們的模型將無法正常運行。 因此,我們將其限制為單個域。
Some images from the dataset. Image By Author數據集中的一些圖像。 圖片作者Download the data which I have hosted on GitHub using wget
使用wget下載我在GitHub上托管的數據
!wget https://github.com/shubham0204/Dataset_Archives/blob/master/mountain_images.zip?raw=true -O images.zip!unzip images.zipTo make our training data, we’ll iterate through each image in our dataset and perform the below tasks on it,
為了制作訓練數據,我們將遍歷數據集中的每個圖像,并在其上執行以下任務,
Image By Author圖片作者First, we’ll read our image file using PIL.Image.open(). Convert this Image object to a NumPy array using np.asarray().
首先,我們將使用PIL.Image.open()讀取圖像文件。 使用np.asarray()將此Image對象轉換為NumPy數組。
Generate 2 random numbers within the range [ 0 , image_dim — window_size ]. Where image_dim is the size of our square input image.
生成[ 0 , image_dim — window_size ]范圍內的2個隨機數。 其中image_dim是正方形輸入圖像的大小。
These two numbers (called px and py) are the positions from where the original image will be cropped. Select the part of the image array and replace it with a zero array.
這兩個數字(稱為px和py )是裁剪原始圖像的位置。 選擇圖像陣列的一部分,并將其替換為零陣列。
The code looks like this,
代碼看起來像這樣,
1. Preparing the training data.1.準備訓練數據。具有跳過連接的自動編碼器模型 (Auto Encoder model with skip connections)
We add skip connections to our autoencoder model. These skip connections provide better upsampling. By using max-pooling layers, much of the spatial information is lost as it goes down the encoder. In order to reconstruct the image from its latent representation ( produced by the encoder ), we add skip connections, which bring in information from the encoder to the decoder.
我們將跳躍連接添加到我們的自動編碼器模型中。 這些跳過連接提供了更好的上采樣。 通過使用最大池化層,許多空間信息在沿著編碼器傳輸時會丟失。 為了從圖像的潛在表示(由編碼器生成)重建圖像,我們添加了跳過連接,這些連接將信息從編碼器引入解碼器。
2. The AutoEncoder model.2.自動編碼器模型。Finally, we train our autoencoder model with skip connections,
最后,我們使用跳過連接訓練自動編碼器模型,
model.fit( x_train , y_train , epochs=150 , batch_size=25 , validation_data=( x_test , y_test ) )Image By Author圖片作者The above results were obtained on a few test images. We observe the model has nearly learnt how to fill the black boxes! But we can still make out where the box lied in the original image. So this way, we can construct a model to predict the missing part of the image.
以上結果是在一些測試圖像上獲得的。 我們觀察到該模型幾乎學會了如何填充黑匣子! 但是我們仍然可以確定盒子在原始圖像中的位置。 因此,通過這種方式,我們可以構建模型來預測圖像的缺失部分。
進一步閱讀 (Further Reading)
If you liked this blog, make sure you read more stories of mine here, on Medium.
如果您喜歡此博客,請確保在此處的“中等”上閱讀我的更多故事。
就這樣! (That’s All!)
This is just a cool application of Auto Encoders. I got the inspiration for this video from here. Thanks for reading!
這只是自動編碼器的一個很酷的應用程序。 我從這里獲得了這段視頻的靈感。 謝謝閱讀!
翻譯自: https://medium.com/swlh/neural-implanting-with-autoencoders-and-tensorflow-9c2c7b532198
樹莓派 神經網絡植入
總結
以上是生活随笔為你收集整理的树莓派 神经网络植入_使用自动编码器和TensorFlow进行神经植入的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Redmi A2系列即将发布!搭载500
- 下一篇: opencv 运动追踪_足球运动员追踪-