source: internals/2016/aptoideimagesdetector/trunk/Source Code/Illustration2Vector/illustration2vec-master/analyse_image.py @ 16326

Last change on this file since 16326 was 16326, checked in by dferreira, 3 years ago

Otimizing scripts using object serialization.

File size: 1.1 KB
Line 
1# Diogo Ferreira
2# Aptoide, 2016
3# This script analyses a list of images, printing the output safe/explicit.
4# As argument passed in the command line sould be the name of all files wanted to analyse.
5# For example, python analyse_image.py aptoide_images/nude/1.jpg
6
7
8import i2v
9from PIL import Image
10import os
11import glob
12import sys
13import pickle
14
15
16def analyse_explicit(illust2vec, image_dir):
17
18        img = Image.open(os.path.join(image_dir))
19
20        list = illust2vec.estimate_specific_tags([img], ["explicit", "safe"])
21   
22        if list[0]['explicit']>list[0]['safe']:
23                print "explicit"
24        else:
25                print "safe"
26
27if __name__ == "__main__":
28       
29        print "Loading Neural Network Model..."
30        try:
31                illust2vec_f = open("illust2vec.pickle", "rb")
32                illust2vec = pickle.load(illust2vec_f)
33                illust2vec_f.close()
34        except IOError:
35                illust2vec = i2v.make_i2v_with_chainer(
36            "illust2vec_tag_ver200.caffemodel", "tag_list.json")
37                save_model = open("illust2vec.pickle", "wb")
38                pickle.dump(illust2vec, save_model)
39                save_model.close()
40
41
42        for image_dir in sys.argv:
43                if image_dir!=sys.argv[0]:
44                        print "Analysing image..."
45                        analyse_explicit(illust2vec, image_dir)
Note: See TracBrowser for help on using the repository browser.