Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconfiguration of Annotators #212

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions robosherlock/config/config_reconfig_demo.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[camera]
interface=MongoDB

[mongodb]
host=localhost
db=classification_test_table
continual=false
loop=true
playbackSpeed=0.0

[tf]
semanticMap=semantic_map_iai_kitchen.yaml
26 changes: 26 additions & 0 deletions robosherlock/descriptors/analysis_engines/reconfig_demo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
ae:
name: demo
fixedflow:
- CollectionReader
- ImagePreprocessor
- PointCloudFilter
- NormalEstimator
- PlaneAnnotator
- PointCloudClusterExtractor
- ClusterMerger
- SacModelAnnotator
- CaffeAnnotator
- KnnAnnotator
#- ReconfigAnnotator

CollectionReader:
camera_config_files: ['config_reconfig_demo.ini']

PointCloudFilter:
minX: -1.0
maxX: 1.0
minY: 0.0
maxY: 1.0
minZ: 0.0
maxZ: 1.0
transform_cloud: true
19 changes: 19 additions & 0 deletions robosherlock/descriptors/annotators/annotation/CaffeAnnotator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,22 @@ parameters:
capabilities:
inputs: ['rs.scene.MergedHypothesis']
outputs: ['rs.annotation.Features']

reconfiguration:
# BVLC setup
setup_bvlc:
parameters:
caffe_annotator_model_file: '/caffe/models/bvlc_reference_caffenet/deploy.prototxt' # paths are relative to rs_resources
caffe_annotator_trained_file: '/caffe/models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel'
caffe_annotator_mean_file: '/caffe/data/imagenet_mean.binaryproto'
caffe_annotator_label_file: '/caffe/data/synset_words.txt'
caffe_annotator_noramlize: true

# VHF setup
setup_vfh:
parameters:
caffe_annotator_model_file: 'vfh path' # paths are relative to rs_resources
caffe_annotator_trained_file: 'vfh path'
caffe_annotator_mean_file: 'vfh path'
caffe_annotator_label_file: 'vfh path'
caffe_annotator_noramlize: true
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
annotator:
implementation: rs_SacModelAnnotator
name: SacModelAnnotator

capabilities:
inputs:
- rs.scene.MergedHypothesis
- rs.pcl.NormalsCloud
outputs:
- rs.annotation.Shape: [cylinder]
domain: [cylinder]

parameters:
apply_to_clusters: true
distanceThreshold: 0.05
Expand All @@ -19,5 +21,29 @@ parameters:
minPoints: 200
radiusLimit1: 0.01
radiusLimit2: 0.5
sacModel: 6
sacModel: "CYLINDER"
useNormals: true

reconfiguration:
# Definition of sphere reconfiguration
setup_spheres:
capabilities:
outputs:
- rs.annotation.Shape: [sphere]
domain: [sphere]

# Overwrite or define new parameters:
parameters:
distanceThreshold: 0.10
sacModel: "SPHERE"

# Example setup
setup_cylinder:
capabilities:
outputs:
- rs.annotation.Shape: [cylinder]
domain: [cylinder]

parameters:
minPoints: 400
sacModel: "CYLINDER"
127 changes: 118 additions & 9 deletions robosherlock/prolog/rs_query_reasoning.pl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@
retract_query_lang/0,
assert_test_case/0,
retract_all_annotators/0,
retract_query_assertions/0
retract_query_assertions/0,
set_annotator_setup_names/2,
assert_reconfiguration_pipeline/0,
load_sphere_setup/0,
find_sphere_setup/2,
test_overwrite_param/0,
load_knn_one/0,
load_knn_two/0
]).

:- rdf_meta
Expand All @@ -56,9 +63,22 @@
set_annotator_output_type_domain(r,t,r),
set_annotator_input_type_constraint(r,t,r),
compute_annotator_output_type_domain(r,r,t),
compute_annotator_input_type_restriction(r,r,t).
compute_annotator_input_type_restriction(r,r,t),
% reconfiguration:
set_annotator_setup_names(r,t),
set_annotator_setup_output_type_domain(r,t,t,t),
set_annotator_setup_input_type_constraint(r,t,t,t),
set_annotator_setup_parameter(r,t,t,t),
load_annotator_setup(r,t),
load_annotator_setup_input(r,t),
load_annotator_setup_output(r,t),
load_annotator_setup_parameter(r,t,t,t),
find_annotator_setup_for_output_type_domain(r,t,t,t),
find_annotator_setup_for_input_type_constraint(r,t,t,t).


:- use_foreign_library('librs_prologQueries.so').


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Pipeline Planning
Expand All @@ -68,12 +88,12 @@

compute_annotators(A) :-
owl_subclass_of(A,rs_components:'RoboSherlockComponent'),
not(A = 'http://knowrob.org/kb/rs_components.owl#RoboSherlockComponent'),
not(A = 'http://knowrob.org/kb/rs_components.owl#AnnotationComponent'),
not(A = 'http://knowrob.org/kb/rs_components.owl#DetectionComponent'),
not(A = 'http://knowrob.org/kb/rs_components.owl#IoComponent'),
not(A = 'http://knowrob.org/kb/rs_components.owl#PeopleComponent'),
not(A = 'http://knowrob.org/kb/rs_components.owl#SegmentationComponent').
not(A = rs_components:'RoboSherlockComponent'),
not(A = rs_components:'AnnotationComponent'),
not(A = rs_components:'DetectionComponent'),
not(A = rs_components:'IoComponent'),
not(A = rs_components:'PeopleComponent'),
not(A = rs_components:'SegmentationComponent').


% cache the annotators
Expand Down Expand Up @@ -369,7 +389,7 @@
kb_create(rs_components:'CaffeAnnotator',_),
kb_create(rs_components:'KnnAnnotator',KNNI),set_annotator_output_type_domain(KNNI,[kitchen:'WhiteCeramicIkeaBowl', kitchen:'KoellnMuesliKnusperHonigNuss'], rs_components:'RsAnnotationClassification'),
kb_create(rs_components:'HandleAnnotator',HI),set_annotator_output_type_domain(HI,[rs_components:'Handle'], rs_components:'RsAnnotationDetection').

assert_query:-
assert(requestedValueForKey(shape,rs_components:'Box')).

Expand Down Expand Up @@ -422,3 +442,92 @@
retract_query_assertions:-
retract(requestedValueForKey(_,_)).

%% Reconfiguration Rules

assert_reconfiguration_pipeline:-
assert_test_pipeline,
owl_individual_of(I, rs_components:'SacModelAnnotator'),
set_annotator_setup_names(I, ['SetupCylinder', 'SetupSphere']),
set_annotator_setup_output_type_domain(I, 'SetupCylinder', rs_components:'RsAnnotationShape', [rs_components:'Cylinder']),
set_annotator_setup_output_type_domain(I, 'SetupSphere', rs_components:'RsAnnotationShape', [rs_components:'Sphere']),
set_annotator_setup_input_type_constraint(I, 'SetupSphere', rs_components:'perceptualInputRequired', [rs_components:'RsSceneMergedhypothesis'] ).


set_annotator_setup_names(AnnotatorI, Setups) :-
foreach(member(Setup, Setups),
assert(annotator_setup_names(AnnotatorI, Setup))).

set_annotator_setup_output_type_domain(AnnotatorI, Setup, Type, Domain) :-
annotator_setup_names(AnnotatorI, Setup), %% check if setup exists
assert(annotator_setup_output_type((AnnotatorI, Setup), Type)),
assert(annotator_setup_output_domain((AnnotatorI, Setup), Domain)).

set_annotator_setup_input_type_constraint(AnnotatorI, Setup, Type, Constraint) :-
annotator_setup_names(AnnotatorI, Setup), %% check if setup exists
assert(annotator_setup_input_type((AnnotatorI, Setup), Type)),
assert(annotator_setup_input_constraint((AnnotatorI, Setup), Constraint)).

set_annotator_setup_parameter(AnnotatorI, Setup, Parameter, Value) :-
annotator_setup_names(AnnotatorI, Setup), %% check if setup exists
assert(annotator_setup_parameter((AnnotatorI, Setup), [Parameter, Value])).


load_annotator_setup(AnnotatorI, Setup) :-
annotator_setup_names(AnnotatorI, Setup), %% check if setup exists
%% Update output and input
load_annotator_setup_input(AnnotatorI, Setup),
load_annotator_setup_output(AnnotatorI, Setup),
write('Loading new setup: '), nl, write(AnnotatorI), nl, write(Setup),
cpp_reconfigure_annotator(AnnotatorI, Setup).

load_annotator_setup_input(AnnotatorI, Setup) :-
annotator_setup_input_type((AnnotatorI, Setup), Type),
annotator_setup_input_constraint((AnnotatorI, Setup), Constraint),
write(Type),nl,write(Constraint),nl,
%% TODO: retract old input
set_annotator_input_type_constraint(AnnotatorI, Constraint, Type).

load_annotator_setup_output(AnnotatorI, Setup) :-
annotator_setup_output_type((AnnotatorI, Setup), Type),
annotator_setup_output_domain((AnnotatorI, Setup), Domain),
write('Annotator: '),writeln(AnnotatorI),
write('Domain: '),writeln(Domain),
write('Type: '),writeln(Type),
%% TODO: retract old output
set_annotator_output_type_domain(AnnotatorI, Domain, Type).

load_annotator_setup_parameter(AnnotatorI, Setup, Parameter, Value) :-
annotator_setup_names(AnnotatorI, Setup), %% check if setup exists
annotator_setup_parameter((AnnotatorI, Setup), Parameter, Value),
write('Overwriting param now'), nl, write(AnnotatorI), nl,
cpp_overwrite_param(AnnotatorI, Parameter, 2, Value).


find_annotator_setup_for_output_type_domain(AnnotatorI, Setup, Type, Domain) :-
annotator_setup_output_type((AnnotatorI, Setup), Type),
annotator_setup_output_domain((AnnotatorI, Setup), Domain).

find_annotator_setup_for_input_type_constraint(AnnotatorI, Setup, Type, Constraint) :-
annotator_setup_input_type((AnnotatorI, Setup), Type),
annotator_setup_input_constraint((AnnotatorI, Setup), Constraint).


%% TEST TODO: REMOVE
find_sphere_setup(A, S) :-
find_annotator_setup_for_output_type_domain(A, S, rs_components:'RsAnnotationShape', [rs_components:'Sphere']).

load_sphere_setup:-
cpp_reconfigure_annotator('SacModelAnnotator', 'setup_spheres').

load_cylinder_setup:-
owl_individual_of(I,rs_components:'SacModelAnnotator'),
load_annotator_setup(I, 'SetupCylinder').

test_overwrite_param:-
cpp_overwrite_param('SacModelAnnotator', 'sacModel', ['CYLINDER']).

load_knn_one:-
cpp_reconfigure_annotator('KnnAnnotator', 'setup_one').

load_knn_two:-
cpp_reconfigure_annotator('KnnAnnotator', 'setup_two').
Loading