Skip to content

Instantly share code, notes, and snippets.

@rogerhub
Created December 8, 2015 09:02
Show Gist options
  • Save rogerhub/a01d999a74655b98b018 to your computer and use it in GitHub Desktop.
Save rogerhub/a01d999a74655b98b018 to your computer and use it in GitHub Desktop.
Running time graph for SGDF.
from sgdf.fusion.alternatives.reference import *
from sgdf.fusion.alternatives.quickdescent import *
from sgdf.benchmarking.headless import *
import time
def b(algorithm, n):
mask = np.zeros((n, n), dtype=np.bool)
mask[n/4:3*n/4, n/4:3*n/4] = True
source = np.random.random((n, n, 3)).astype(np.float32)
target = np.random.random((n, n, 3)).astype(np.float32)
fusion = algorithm()
fusion.set_target_image(target)
fusion.set_source_image(source)
fusion.set_anchor_points(np.array([0, 0]), np.array([0, 0]))
fusion.update_blend(mask)
before = time.time()
fusion.get_fusion()
after = time.time()
elapsed = after-before
print repr(algorithm), n, elapsed
return elapsed
sizes = {
QuickdescentFusion: [10, 15, 20, 30, 40, 60, 80, 100, 120, 160, 200, 240, 280, 320, 400, 550, 700, 850, 1000, 1500, 2000, 4000, 6000],
ReferenceFusion: [10, 15, 20, 30, 40, 60, 80, 100, 120, 160, 200, 240, 280, 320, 400, 550, 700],
}
times_per_algorithm = {}
for algorithm in (QuickdescentFusion, ReferenceFusion):
times_per_algorithm[algorithm] = []
for n in sizes[algorithm]:
times_per_algorithm[algorithm].append(b(algorithm, n))
import logging
import matplotlib
import numpy as np
from sgdf.fusion import get_fusion_algorithm
from sgdf.util.io import imread, imsave
from sgdf.util.preprocessing import to_mask
matplotlib.use('Agg')
import matplotlib.pyplot as plt
def save_image(fig, name, dont_clear=False):
fig.savefig(name, bbox_inches='tight', dpi=144)
if not dont_clear:
fig.clear()
fig, ax = plt.subplots()
ax.set_title("Running time of Reference vs Quickdescent")
ax.scatter(sizes[QuickdescentFusion], times_per_algorithm[QuickdescentFusion], c=(1., 0.4, 0.4, 1.), label="Quickdescent")
ax.scatter(sizes[ReferenceFusion], times_per_algorithm[ReferenceFusion], c=(0.4, 0.4, 1., 1.), label="Reference")
ax.set_ylabel("Time (seconds)")
ax.set_yscale("log")
ax.set_ylim(bottom=0.0005, top=5000)
ax.set_xlim(left=5, right=5000)
ax.set_xscale("log")
ax.set_xlabel("Input size (image edge length)")
ax.legend()
save_image(fig, "output-graph2.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment