add dataset methods

pull/249/head
edgarriba 2015-11-18 13:51:05 +00:00
rodzic 1fc0d1e1e1
commit b9e8ee6b51
3 zmienionych plików z 74 dodań i 91 usunięć

27
scripts/dataset.py 100644
Wyświetl plik

@ -0,0 +1,27 @@
import os
import context
import datatypes
def load_dataset(images_dir, args, photos):
# check if the extension is sopported
def supported_extension(file_name):
(pathfn, ext) = os.path.splitext(file_name)
return ext.lower() in context.supported_extensions
# find files in the given directory
files = os.listdir(images_dir)
# filter images for its extension type
# by now only 'jpg' and 'jpeg are supported
files = [f for f in files if supported_extension(f)]
#photos = []
# create ODMPhoto list
for f in files:
file_name = os.path.join(images_dir, f)
photos.append(datatypes.ODMPhoto(file_name, args))
#return photos

Wyświetl plik

@ -2,11 +2,11 @@ import os
import subprocess import subprocess
import log import log
import context import dataset
from tasks import ODMTaskManager from tasks import ODMTaskManager
class ODMApp: class ODMApp:
''' ODMJob - a class for ODM Activities ''' ODMApp - a class for ODM Activities
''' '''
def __init__(self, images_dir, args=None): def __init__(self, images_dir, args=None):
# Internal app config # Internal app config
@ -14,11 +14,12 @@ class ODMApp:
self.images_dir = os.path.abspath(images_dir) self.images_dir = os.path.abspath(images_dir)
# Initialize odm photos # Initialize odm photos
self.photos = self.init_photos(self.images_dir, self.args) #self.photos = dataset.load_dataset(self.images_dir, self.args)
self.photos = []
# Task manager # Task manager
# configure and schedule tasks # configure and schedule tasks
self.task_manager = ODMTaskManager() self.task_manager = ODMTaskManager(self)
# Run all tasks given an starting point # Run all tasks given an starting point
def run(self, initial_task_id): def run(self, initial_task_id):
@ -27,30 +28,6 @@ class ODMApp:
self.task_manager.run_tasks() self.task_manager.run_tasks()
def init_photos(self, images_dir, args):
# check if the extension is sopported
def supported_extension(file_name):
(pathfn, ext) = os.path.splitext(file_name)
return ext.lower() in context.supported_extensions
# find files in the given directory
files = os.listdir(images_dir)
# filter images for its extension type
# by now only 'jpg' and 'jpeg are supported
files = [f for f in files if supported_extension(f)]
photos = []
# create ODMPhoto list
for f in files:
file_name = os.path.join(images_dir, f)
photos.append(ODMPhoto(file_name, args))
return photos
class ODMPhoto: class ODMPhoto:
""" ODMPhoto - a class for ODMPhotos """ ODMPhoto - a class for ODMPhotos
""" """
@ -92,6 +69,11 @@ class ODMPhoto:
# TODO(edgar): compute global min/max # TODO(edgar): compute global min/max
# def compute_min_max() # def compute_min_max()
# min_width = min(min_width, width)
# max_width = max(max_width, width)
# min_height = min(min_height, heigth)
# max_height = max(max_height, height)
## populate & update max/mins ## populate & update max/mins
# #
#if objODMJob.minWidth == 0: #if objODMJob.minWidth == 0:

Wyświetl plik

@ -2,27 +2,33 @@ import log
import resize import resize
import opensfm import opensfm
import datatypes
from dataset import load_dataset
from resize import resize
# Define pipeline tasks # Define pipeline tasks
tasks_dict = { '0': 'resize', tasks_dict = { '0': 'load_dataset',
'1': 'opensfm', '1': 'resize',
'2': 'cmvs', '2': 'opensfm',
'3': 'pmvs', '3': 'cmvs',
'4': 'odm_meshing', '4': 'pmvs',
'5': 'odm_texturing', '5': 'odm_meshing',
'6': 'odm_georeferencing', '6': 'odm_texturing',
'7': 'odm_orthophoto', '7': 'odm_georeferencing',
'8': 'zip_results' } '8': 'odm_orthophoto',
'9': 'zip_results' }
class ODMTaskManager(object): class ODMTaskManager(object):
"""docstring for ODMTaskManager""" """docstring for ODMTaskManager"""
def __init__(self): def __init__(self, odm_app):
self.odm_app = odm_app
self.initial_task_id = 0 self.initial_task_id = 0
self.current_task_id = 0 self.current_task_id = 0
self.tasks = self.init_tasks(tasks_dict) self.tasks = self.init_tasks(tasks_dict, self.odm_app)
def init_tasks(self, _tasks_dict): def init_tasks(self, _tasks_dict, _odm_app):
# dict to store tasks objects # dict to store tasks objects
tasks = {} tasks = {}
@ -37,79 +43,57 @@ class ODMTaskManager(object):
# Setup each tasks i/o # Setup each tasks i/o
command = None command = None
if task_name == 'resize': if task_name == 'load_dataset':
# setup this task # setup this task
num_inputs = 1 command = load_dataset
num_outputs = 1 inputs = { 'images_dir': _odm_app.images_dir,
command = task_name + '.' + task_name 'args': _odm_app.args ,
inputs = {} 'photos': _odm_app.photos }
outputs = {}
elif task_name == 'resize':
# setup this task
command = resize
inputs = { 'photos': _odm_app.photos }
elif task_name == 'opensfm': elif task_name == 'opensfm':
# setup this task # setup this task
num_inputs = 0
num_outputs = 0
inputs = {} inputs = {}
outputs = {}
elif task_name == 'cmvs': elif task_name == 'cmvs':
# setup this task # setup this task
num_inputs = 0
num_outputs = 0
inputs = {} inputs = {}
outputs = {}
elif task_name == 'pmvs': elif task_name == 'pmvs':
# setup this task # setup this task
num_inputs = 0
num_outputs = 0
inputs = {} inputs = {}
outputs = {}
elif task_name == 'odm_meshing': elif task_name == 'odm_meshing':
# setup this task # setup this task
num_inputs = 0
num_outputs = 0
inputs = {} inputs = {}
outputs = {}
elif task_name == 'odm_texturing': elif task_name == 'odm_texturing':
# setup this task # setup this task
num_inputs = 0
num_outputs = 0
inputs = {} inputs = {}
outputs = {}
elif task_name == 'odm_georeferencing': elif task_name == 'odm_georeferencing':
# setup this task # setup this task
num_inputs = 0
num_outputs = 0
inputs = {} inputs = {}
outputs = {}
elif task_name == 'odm_orthophoto': elif task_name == 'odm_orthophoto':
# setup this task # setup this task
num_inputs = 0
num_outputs = 0
inputs = {} inputs = {}
outputs = {}
elif task_name == 'zip_results': elif task_name == 'zip_results':
# setup this task # setup this task
num_inputs = 0
num_outputs = 0
inputs = {} inputs = {}
outputs = {}
else:
log.ODM_ERROR('task_name %s is not valid' % task_name)
# setup values else:
log.ODM_ERROR('task_name %s is not valid' % task_name)
# setup task configuration
task = tasks[key] task = tasks[key]
task.command = command task.command = command
task.num_inputs = num_inputs
task.num_outputs = num_outputs
task.inputs = inputs task.inputs = inputs
task.outputs = outputs
return tasks return tasks
@ -119,6 +103,7 @@ class ODMTaskManager(object):
# catch task with current id # catch task with current id
task = self.tasks[str(id)] task = self.tasks[str(id)]
# update task tracking # update task tracking
log.ODM_INFO('Running task %s: %s' % (task.id, task.name))
self.current_task_id = task.id self.current_task_id = task.id
# run task # run task
task.state = task.run() task.state = task.run()
@ -130,33 +115,23 @@ class ODMTask(object):
# task definition # task definition
self.id = id self.id = id
self.name = name self.name = name
self.command = None
# task i/o # task i/o
self.num_inputs = 0 self.command = None
self.num_outputs = 0
self.inputs = {} self.inputs = {}
self.num_outputs = {}
# Current task state (0:waiting, 1:running, 2:succeded: 3:failed) # Current task state (0:waiting, 1:running, 2:succeded: 3:failed)
# By default we set a task in waiting state # By default we set a task in waiting state
self.state = 0 self.state = 0
# Launch task # Launch task
def run(self): def run(self):
log.ODM_INFO('Running task %s %s ' % (self.id, self.name))
# while doing something # while doing something
self.state = 1 self.state = 1
self.launch_command() self.launch_command()
# if succeeded with current task # if succeeded with current task
if True: if True:
self.state = 2 self.state = 2
else: else:
self.state = 3 self.state = 3
# Return task state # Return task state
return self.state return self.state
@ -164,12 +139,11 @@ class ODMTask(object):
if self.command is None: if self.command is None:
log.ODM_ERROR('Call method for task %s not defined' % self.name) log.ODM_ERROR('Call method for task %s not defined' % self.name)
return return
# run configured conmmand
method_call_str = str(self.command) + '()'
try: try:
eval(method_call_str) self.command(**self.inputs)
except Exception, e: except Exception, e:
log.ODM_ERROR('Method %s cannot be called' % method_call_str) log.ODM_ERROR('Method %s cannot be called' % str(self.command))
log.ODM_ERROR(str(e)) log.ODM_ERROR(str(e))