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

Last change on this file since 16390 was 16390, checked in by dferreira, 4 years ago

Text categorization changed

File size: 1.3 KB
Line 
1# Diogo Ferreira
2# Aptoide, 2016
3# This script analyses a list of images, printing the output safe/explicit and its percentage.
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
7try:
8        import Illustration2Vector.illustration2vec_master.i2v
9except:
10        import i2v
11from PIL import Image
12import os
13import glob
14import sys
15import pickle
16
17
18def analyse_explicit(illust2vec, image_dir):
19
20        img = Image.open(os.path.join(image_dir))
21
22        list = illust2vec.estimate_specific_tags([img], ["explicit", "safe"])
23   
24        if list[0]['explicit']>list[0]['safe']:
25                return ('explicit',list[0]['explicit']) # Explicit
26        else:
27                return ('safe',list[0]['safe']) # Safe
28
29if __name__ == "__main__":
30       
31        print "Loading Neural Network Model..."
32        try:
33                illust2vec_f = open("illust2vec.pickle", "rb")
34                illust2vec = pickle.load(illust2vec_f)
35                illust2vec_f.close()
36        except IOError:
37                illust2vec = i2v.make_i2v_with_chainer(
38            "illust2vec_tag_ver200.caffemodel", "tag_list.json")
39                save_model = open("illust2vec.pickle", "wb")
40                pickle.dump(illust2vec, save_model)
41                save_model.close()
42
43
44        for image_dir in sys.argv:
45                if image_dir!=sys.argv[0]:
46                        print "Analysing image..."
47                        analyse_explicit(illust2vec, image_dir)
Note: See TracBrowser for help on using the repository browser.