Hello everyone. In the previous video, we have started the training process. And the here are results of the training. Our training function has created checkpoint files of our model. As you can see here, because training this model can take a lot of time for some PCs, I will provide checkpoint files to the GitHub repository of the project. So you can easily download them and the test pipeline on your site as well.
You may remember this image from earlier in the course, only this time two dense layers are circled. This image will help us to understand what to do to create image vectors from our data set. For the image search engines, we need to represent images somehow. And that could be easily done by choosing some arbitrary vectors. But if we do that, there are no correlation between them. To overcome this, we'll use pre trained layers from our model In our example, we will use dense layer two and dense layer four.
Because our dense layer four has 124 units, and then Slayer to 256 units, each vector will have 128 units to get or numbers in this project will use hamming distance for example, In this video, we are going to complete the Create training set factors function. The first thing that we have to create is TensorFlow session session, right session equals TF dot session. And before we can use it, we need to initialize all global variables. To do that, right session dot run TF dot global variables initializer because the network is randomly initialized, at this moment, we have to create a saver and use it to restore models weights To define the saver right saver equals TF dot train dot saver and use it to restore network weights by typing saver dot restore, and define session and path to the checkpoint. Before we jump to our main for loop for the function, let's define two empty lists.
Each corresponds to different layer features. Now that everything is ready, let's define our for loop and define it in the same way as we did in our train function. For II, in the range, dq dm and in brackets provide a range of ln of x train divided divided or full division of batch size. In this for loop based the top part of the training loop. As you can see, the syntax here is the same as we had in the train loop. Only this time We won't be using y batch part deleted.
And now let's create the feed dict model dot inputs x batch model dot dropout rate is 00. We set it to 00 here because we don't need to throw any data in the production environment. Then as a result set dense to a dense four equals two session dot run. And in the brackets firstly provide model dot dense two features and model dot dense four features. And the second argument for the surround method is faded. dict does provide the one that we defined.
Now let's append dense to and dense for to appropriate top level lists. To change the size of dense features, we need to stack them vertically. To do that use MP dot v stack. Let's copy the line of dense two features and paste it below. Change to to four, and we are done with a boat with the resizing and stacking part. Now it's time to check what distance are we using in the case of Hamming binarize.
The vectors, which simply MP were function. Dense for features is the same as we did for dense two features concat the two vectors by horizontally stacking them. To do this use NP dot h stack. Now that we have generated vectors, we need to save them in some way. We'll do this by using pickle library. Open the file and call it hemming train vectors dot pickle and open it in the right binary mode.
Use the pickle dot dump. The first argument is the file or in this case array that we're trying to save. And the second argument is open file, in this case F. Now we need to add the same thing for the cosine distance. copy everything Below without binarization from the hamming part of the code, the only change here is to change Hamming train vectors to cost and train vectors. Execute the cell and let's define our training set vectors Firstly, let's define our model equals two image search model. And provide arguments for learning rate set learning rate from the config for the image size, use it already defined image size in our config file called the creative method.
Create training set vectors and his arguments provide Model X train, y train, batch size and checkpoint use the latest one for the image size. Put 32 by 32 because of the secret 10 data set, and finally distance say Hamming Okay, vector generation is finished. Let's check the root folder for the file. And you can see that it has the hamming distance vectors dot pickle file. And that's it for this video. If you have any comments questions, please post them in the comment section.
Otherwise, I'll see you in the next tutorial.