forked from Azure/ImageSimilarityUsingCntk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_featurizeImages.py
27 lines (23 loc) · 1007 Bytes
/
3_featurizeImages.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
# -*- coding: utf-8 -*-
from helpers import *
from helpers_cntk import *
locals().update(importlib.import_module("PARAMETERS").__dict__)
################################################
# MAIN
################################################
# Init
printDeviceType()
makeDirectory(workingDir)
model = load_model(cntkRefinedModelPath)
# Compute features for each image and write to disk
print("Featurizing test set..")
featuresTest = featurizeImages(model, imgFilenamesTestPath, imgDir, workingDir + "/featurizer_map.txt", "poolingLayer", run_mbsize)
print("Featurizing training set..")
featuresTrain = featurizeImages(model, imgFilenamesTrainPath, imgDir, workingDir + "/featurizer_map.txt", "poolingLayer", run_mbsize)
features = mergeDictionaries(featuresTrain, featuresTest)
for feat in list(features.values()):
assert(len(feat) == rf_modelOutputDimension)
# Save features to file
print("Writting CNTK outputs to file %s ..." % featuresPath)
saveToPickle(featuresPath, features)
print("DONE.")