Example #1
0
def main():
    import numpy as np
    from models import vgg19_model
    from algorithms import neural_best_buddies as NBBs
    from util import util
    from util import MLS

    vgg19 = vgg19_model.define_Vgg19(opt)
    img_nums, images = get_imgs()

    for imgnum in tqdm(missing):
        print(imgnum)
        save_dir = os.path.join(opt.results_dir, str(imgnum))
        if os.path.exists(os.path.join(save_dir, 'BtoA.npy')):
            continue
        try:
            print('Working on', imgnum)

            source_path = os.path.join(opt.source, f'{base_name}_{imgnum}.png')
            A = util.read_image(source_path, opt.imageSize)
            B = util.read_image(opt.target, opt.imageSize)
            print(A.shape, B.shape)
            nbbs = NBBs.sparse_semantic_correspondence(
                vgg19, opt.gpu_ids, opt.tau, opt.border_size, save_dir,
                opt.k_per_level, opt.k_final, opt.fast)
            points = nbbs.run(A, B)
            mls = MLS.MLS(v_class=np.int32)
            mls.run_MLS_in_folder(root_folder=save_dir)
        except Exception as e:
            print(e)
            with open(os.path.join(save_dir, 'no_correspondence.txt'),
                      'w') as f:
                f.write('')
Example #2
0
def main():
    import numpy as np
    from models import vgg19_model
    from algorithms import neural_best_buddies as NBBs
    from util import util
    from tqdm import tqdm
    from util import MLS

    vgg19 = vgg19_model.define_Vgg19(opt)
    img_nums, images = get_imgs()

    for imgnum in tqdm(range(start_imgnum, start_imgnum + N)):
        save_dir = os.path.join(opt.results_dir, str(img_nums[imgnum]))
        print('Working on', images[imgnum])
        try:
            source_path = os.path.join(opt.source, images[imgnum])
            A = util.read_image(source_path, opt.imageSize)
            B = util.read_image(opt.target, opt.imageSize)
            nbbs = NBBs.sparse_semantic_correspondence(vgg19, opt.gpu_ids, opt.tau,
                                                    opt.border_size, save_dir,
                                                    opt.k_per_level, opt.k_final,
                                                    opt.fast)
            points = nbbs.run(A, B)
            mls = MLS.MLS(v_class=np.int32)
            mls.run_MLS_in_folder(root_folder=save_dir)
        except Exception as e:
            print(e)
Example #3
0
def run_NBB_and_get_points(opt, nbbs):
    A = util.read_image(opt.sourceImg, opt.imageSize)
    B = util.read_image(opt.targetImg, opt.imageSize)
    points = nbbs.run(A, B)
    new_file_name = os.path.basename(opt.sourceImg) + "_" + os.path.basename(
        opt.targetImg) + ".txt"

    with open(os.path.join(opt.results_dir, new_file_name), 'w') as f:
        for item in points:
            f.write("%s\n" % item)
    f.close()
    dist = get_distance(points, A, B)

    return dist, points
Example #4
0
 def post(self):
     image_key = read_image(self, "project_image")
     p = self.create_project(image_key)
     session = get_current_session()
     self.create_project_admin(p, session['me_email'])
     intercomio_api.events(session['me_email'], event_name='created_project')
     mixpanel_api.events(session['me_email'], 'created_project')
     self.redirect('/projects/skills?project_id='+str(p.id))
Example #5
0
 def post(self):
     image_key = read_image(self, "project_image")
     p = self.create_project(image_key)
     session = get_current_session()
     self.create_project_admin(p, session['me_email'])
     intercomio_api.events(session['me_email'],
                           event_name='created_project')
     mixpanel_api.events(session['me_email'], 'created_project')
     self.redirect('/projects/skills?project_id=' + str(p.id))
Example #6
0
 def run(self):
     count = 0
     for filepath in self.files:
         ext = filepath.split('.')[-1]
         h5_obj = h5py.File(filepath, 'r') if ext in ('cxi', 'h5') else None
         lcls_data = util.get_lcls_data(filepath) if ext == 'lcls' else None
         data_shape = util.get_data_shape(filepath)
         for i in range(data_shape[self.dataset][0]):
             img = util.read_image(filepath,
                                   frame=i,
                                   h5_obj=h5_obj,
                                   lcls_data=lcls_data,
                                   dataset=self.dataset)['image']
             if img is None:
                 continue
             img = img.astype(np.float64)
             if count == 0:
                 img_mean = img
                 img_sigma = np.zeros_like(img_mean)
             else:
                 img_mean_prev = img_mean.copy()
                 img_mean += (img - img_mean) / (count + 1.)
                 img_sigma += (img - img_mean_prev) * (img - img_mean)
             count += 1
             ratio = count * 100. / self.max_frame
             self.update_progress.emit(ratio)
             if count == self.max_frame:
                 break
         if count >= self.max_frame:
             break
     img_sigma = img_sigma / count
     img_sigma = np.sqrt(img_sigma)
     # write to file
     time.sleep(0.1)
     if self.output is None:
         output = 'output.npz'
     else:
         output = self.output
     dir_ = os.path.dirname(output)
     if not os.path.isdir(dir_):
         os.mkdir(dir_)
     np.savez(output, mean=img_mean, sigma=img_sigma)
Example #7
0
import time
import numpy as np
from models import vgg19_model
from algorithms import neural_best_buddies as NBBs
from util import util
from util import MLS

from options.options import Options
opt = Options().parse()

vgg19 = vgg19_model.define_Vgg19(opt)
# save_dir = os.path.join(opt.results_dir, opt.name)
save_dir = os.path.join(opt.results_dir)

print('\n\n---------------------------')
print('Started Neural Best-Buddies')
print('---------------------------')
start_time = time.time()

nbbs = NBBs.sparse_semantic_correspondence(vgg19, opt.gpu_ids, opt.tau,
                                           opt.border_size, save_dir,
                                           opt.k_per_level, opt.k_final,
                                           opt.fast)
A = util.read_image(opt.datarootA, opt.imageSize)
B = util.read_image(opt.datarootB, opt.imageSize)
points = nbbs.run(A, B, opt.datarootA, opt.datarootB)

end_time = time.time()
total_time = end_time - start_time
print('\nFinished after {:04.3f} seconds'.format(total_time))
Example #8
0
 def post(self):
     image_key = read_image(self, "project_image")
     self.update_project(image_key)
     self.redirect('/member/projects/dashboard')
Example #9
0
 def post(self):
     image_key = read_image(self, "project_image")
     self.update_project(image_key)
     self.redirect('/member/projects/dashboard')