카페 모형의 이동 학습을 해보도록 하겠습니다.

2365 단어 CaffeTransferLearning
라벨은 인공지능으로 표시된 것이다.인간이 표시한 데이터에 따르면 허용도가 높고,'선글라스 낀 고양이','애니메이션 고양이'도 고양이로 표시하기 때문에fine tuning은 적합하지 않으니 포기하자.
wget https://storage.googleapis.com/openimages/2017_07/images_2017_07.tar.gz
tar -zxvf images_2017_07.tar.gz
wget https://storage.googleapis.com/openimages/2017_07/annotations_machine_2017_07.tar.gz
tar -zxvf annotations_machine_2017_07.tar.gz
import csv
import os
import time
from PIL import Image
import urllib
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

all_tgt = ["cat", "dog", "person", "yard"]

for cur_tgt in all_tgt:
    print '\nClass : ' + str(cur_tgt) + '\n\n'
    f1 = open('/home/ubuntu/labels_'+str(cur_tgt)+'.csv', 'r')
    reader1 = csv.reader(f1)
    f2 = open('/home/ubuntu/2017_07/train/images.csv', 'r')
    reader2 = csv.reader(f2)
    confidence = 1.0
    if cur_tgt == 'yard':
        confidence = 0.9

    cnt = 0
    for row1 in reader1:

        if float(row1[3]) == confidence:

            for row2 in reader2:
                if row1[0] == row2[0]:
                    break
            print str(cnt)+' : '+row2[2]

            #load image
            try:
                urlimg = urllib.urlopen(row2[2])            
                img = Image.open(urlimg)
            except:
                continue # skip if error happened

            fname = '/home/ubuntu/downloaded_images/'+str(cur_tgt)+'.'+str(cnt)+'.jpg'
            if urlimg.url.find('unavailable') == -1:
                if cur_tgt != 'yard':
                    #resize image
                    ratio = img.width / 227.0
                    if img.height < img.width:
                        ratio = img.height / 227.0
                    img_resize = img.resize((int(round(img.width/ratio)), int(round(img.height/ratio))))
                    img_resize.save(fname)
                else:
                    img.save(fname)

                cnt = cnt + 1
                if 10000 <= cnt:
                    break
    f1.close()
    f2.close()

좋은 웹페이지 즐겨찾기