In [13]:
import sys
sys.path.insert(0, '..')
import time
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
In [14]:
import numpy as np
from lib.segmentation import FormFeatureExtraction
def _invalidate_cache(extractor):
for method in extractor.__dict__.copy():
del extractor.__dict__[method]
extractor.segmentation = segmentation
def plot_bar(segmentation, cache=False):
extractor = FormFeatureExtraction(segmentation)
times = []
for method in FormFeatureExtraction.methods:
t = time.process_time()
getattr(extractor, method)
t = time.process_time() - t
times.append(t)
if not cache:
_invalidate_cache(extractor)
times = np.array(times)
percentages = 100 * times / times.sum()
plt.rcParams['figure.figsize'] = (15, 5)
ticks = range(percentages.size)
plt.bar(ticks, percentages, color='black', tick_label=ticks)
plt.ylabel('Percentage')
In [15]:
from lib.datasets import PascalVOC
from lib.segmentation import slic
image = PascalVOC('../test_data').test.next_batch(3, shuffle=False)[0][2]
segmentation = slic(image, num_segments=800, compactness=30, max_iterations=10, sigma=0)
In [16]:
plot_bar(segmentation, cache=False)
In [17]:
for i, method in enumerate(FormFeatureExtraction.methods):
print('{}: {}'.format(i, method))
In [18]:
plot_bar(segmentation, cache=True)