-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredict.py
executable file
·49 lines (39 loc) · 2.78 KB
/
predict.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
######################################################################
# dataset location
prefix = "/work/kastnerm/test"
# list of words
# script expects a subfolder prefix/ for each word with num_images number of images
#words = ["a", "b"]
words = ['coast', 'plate', 'fort', 'name', 'south', 'temple', 'men', 'below', 'boy', 'district', 'bath', 'harbor', 'transport', 'fauna', 'estate', 'something', 'funny', 'rural', 'myself', 'subway', 'woman', 'plant', 'dress', 'friend', 'cold', 'mission', 'guy', 'tourist', 'future', 'beauty', 'focus', 'random', 'breakfast', 'plastic', 'abstract', 'boulder', 'west', 'union', 'aerial', 'charity', 'sound', 'pool', 'mirror', 'solo', 'concrete', 'apartment', 'pizza', 'card', 'scuba', 'rust', 'flag', 'demonstration', 'lady', 'force', 'resolution', 'email', 'daughter', 'leaf', 'yard', 'space', 'motor', 'early', 'inside', 'puppy', 'kitten', 'research', 'provide', 'dusk', 'self', 'rail', 'famous', 'guitar', 'wanted', 'picnic', 'break', 'chair', 'need', 'floor', 'company', 'navy', 'kitty', 'gallery', 'dad', 'pond', 'roof', 'mini', 'alpha', 'past', 'explore', 'exposure', 'journey', 'slide', 'smoke', 'spider', 'pretty', 'honor', 'stop', 'challenge', 'government', 'summit', 'plaza', 'weather', 'neon', 'review', 'hour', 'case', 'doing', 'silver', 'pattern', 'crew', 'classic', 'religion', 'factory', 'cycle', 'vehicle', 'monkey', 'call', 'truck']
# number of images for each word
# pretrained models only available for [1000, 2500, 5000]
num_images = 5000
######################################################################
# import pretrained model
# generated by old/svm_imageability.py (running this takes 6-8 weeks without caches)
import pickle
with open('models/randomforest_' + str(num_images) + '.pickle', 'rb') as handle:
predictor = pickle.load(handle)
# feature selection
# pretrained model use all features, so don't change
from lib.Feature import FeatureType
#features = [FeatureType.ColorHSV, FeatureType.YOLO_NUM_9000, FeatureType.YOLO_COMPOSITION, FeatureType.SURF, FeatureType.GIST]
features = [FeatureType.YOLO_NUM_9000, FeatureType.YOLO_COMPOSITION, FeatureType.SURF, FeatureType.ColorHSV, FeatureType.GIST]
# get visual features for each word
from lib.create_matrix import processLooseWord, processImageabilityDatasetTerm
X = []
for word in words:
# get visual features for each term
# function will try to load as much as possible from cache/
# or calculate them newly if not found
location = prefix + "/" + word + "/"
#_x = processLooseWord(word, location, features, num_images)
_x = processImageabilityDatasetTerm(word, features, num_images)
X.append(_x)
# make prediction from random forest model
results = predictor.predict(X)
#results = [(x*6)+100 for x in results]
# output
print(results)