AI를 활용한 재밌는 것들을 개발합니다

2017년 1월 4일 수요일

Tensorflow slim library installation and image set download on windows

0. Intro
1. Installing the Tensorflow GPU version in Windows
1.5 Introduction to TF-Slim
2.1 Deep Learning slim library installation and image set download
2.2 Learning the Deep Learning Model
2.3 Evaluating the Deep Learning Model
3. Learning from my images (using caltech images)
4. Using learned models
5. Creating a Python Tkinter GUI application

Finally, We will try TF-Slim practice.

The exercises follow exactly what is in https://github.com/tensorflow/models/tree/master/slim, but as you can see from the content, it is in Linux code. We have Tensorflow in Windows Anaconda, so some code does not work. And TF-Slim Python code used in the practice is written in Python2, so in our Tensorflow installed with Python3, an error will occur when executing the code. Let's fix these things one at a time.


1) Download TF-Slim image model library






 There are a lot of models that are implemented with the Tensorflow. There is also an RNN example and an autoencoder example. Click on the buttons shown on the picture to download the files and extract them to a suitable location on your computer. You do not need to install it separately.



If you go into the slim folder in the unpacked folder, you can see the above files. I will briefly introduce the contents of the file.

- download_and_conver_data.py: Download image sets and generate TFRecord format
- train_image_classifier.py: Learning the target image sets
- eval_image_cliassifier.py: Evaluate the learned model (accuracy)
- slim_walkthough.ipynb: slim code describing how to use the IPython notebook file

Let's look at the other subfolders while practicing.

2) Downloading image sets and converting TFRecord


 Let's open download_and_convert_data.py, which we introduced earlier. If an error occurs during code execution, the error code line number is displayed together. Please use the editor that displays the code line as below. If you do not have a Python editor on your computer, just use the Spyder installed when you install Anaconda.


 Let's take a look at the code. Examples of code execution are shown on lines 17-31. Currently there are three image sets cifar10, flowers, and mnist. To practice, we will download a set of flowers. Before running the Python code, open download_and_convert_flowers.py in the datasets folder and comment out the code on line 210 (enter # before the sentence). This will prevent the downloaded flower images from being deleted.


 After commenting and saving, go to anaconda and run the python code with the following command. --dataset_dir specifies the storage folder you want. 
python download_and_convert_data.py --dataset_name=flowers --dataset_dir=/tmp/flowers
Oh ... I get an error immediately.


 In line 29 of the download_and_convert_cifar10.py file in the datasets folder, there was an error saying that there is no module named cPickle. In Python3, we use _pickle instead of cPickle. Open the file with Spyder and modify line 29 and save it.

Import _pickle as cPickle #import cPickle


Let's run the code again with the error.
python download_and_convert_data.py --dataset_name=flowers --dataset_dir=/tmp/flowers
 This time, I downloaded the flowers image set archive file well ... but then I encountered an error in converting to TFRecord format. Do not give up at this time and look at where the error occurred. If you look at what is shown in the Anaconda window

File "D:\utils\models-master\slim\datasets\download_and_convert_flowers.py", line 146, 
...
TypeError: 'jpg' has type <class 'str'>, but expected one of: ((<class 'bytes'>,

Do not be embarrassed, and if you google it, 'b' before 'jpg' will fix the error like below picture.


Let's run it again.
python download_and_convert_data.py --dataset_name=flowers --dataset_dir=/tmp/flowers
 Huh ~ Now there is no error. Let's go to download folder. TFRecord format conversion is complete!


You can see that there are 5 TFRecords for train, 5 TFRecords for validation, and a labels file that defines classification class. We will now use this TFRecord format file instead of the original image when we train model.

댓글 없음:

댓글 쓰기

가장 많이 본 글