def processor_obj(): return fsm.Processor(name='test_proc', callable_obj=processor_zoo.DummyProcessor( dummy_input='dummy_input_value'))
# -*- coding: utf-8 -*- """Simple example of using gabrieltool.statemachine. """ from __future__ import absolute_import, division, print_function from functools import partial from gabrieltool.statemachine import fsm, predicate_zoo, processor_zoo # create a two state state machine st_start = fsm.State( name='start', processors=[ fsm.Processor(name='proc_start', callable_obj=processor_zoo.DummyProcessor()) ], transitions=[ fsm.Transition(name='tran_start_to_end', predicates=[ fsm.TransitionPredicate( partial_obj=partial(predicate_zoo.always)) ]) ]) st_end = fsm.State(name='end') st_start.transitions[0].next_state = st_end # save to disk with open('examples/simple.pbfsm', 'wb') as f: f.write(fsm.StateMachine.to_bytes(name='simple_fsm', start_state=st_start))
def build_sandwich_fsm(): # change data_dir, proto_path, model_path and labels below according to Antti's caffe model data_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../data/sandwich-model') #img_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'images_feedback') labels = [ "tomato", "cheese", "full", "ham", "lettuce", "cucumber", "half", "hamwrong", "bread" ] proc = processor_zoo.FasterRCNNOpenCVProcessor( proto_path=os.path.join(data_dir, 'faster_rcnn_test.pt'), model_path=os.path.join(data_dir, 'model.caffemodel'), labels=labels) common_processor = fsm.Processor(callable_obj=proc) st_start = fsm.State(name='start', processors=[common_processor]) st_bread = fsm.State(name='bread', processors=[common_processor]) st_ham = fsm.State(name='ham', processors=[common_processor]) st_lettuce = fsm.State(name='lettuce', processors=[common_processor]) st_end = fsm.State(name='end', processors=[common_processor]) # fill in transitions st_start.transitions.append( fsm.Transition( predicates=[ fsm.TransitionPredicate( partial_obj=partial(predicate_zoo.always)) ], instruction=fsm.Instruction( audio='Now put a piece of bread on the table.' #image=_load_image_bytes(os.path.join(img_dir, 'bread.jpeg')) ), next_state=st_bread)) st_bread.transitions.append( fsm.Transition( predicates=[ fsm.TransitionPredicate(partial_obj=partial( predicate_zoo.has_obj_cls, cls_name='bread')) ], instruction=fsm.Instruction( audio='Now put a piece of ham on the bread.' #image=_load_image_bytes(os.path.join(img_dir, 'ham.jpeg')) ), next_state=st_ham)) st_ham.transitions.append( fsm.Transition( predicates=[ fsm.TransitionPredicate(partial_obj=partial( predicate_zoo.has_obj_cls, cls_name='ham')) ], instruction=fsm.Instruction( audio='Now put a piece of lettuce on the ham.' #image=_load_image_bytes(os.path.join(img_dir, 'lettuce.jpeg')) ), next_state=st_lettuce)) st_lettuce.transitions.append( fsm.Transition(predicates=[ fsm.TransitionPredicate(partial_obj=partial( predicate_zoo.has_obj_cls, cls_name='lettuce')) ], instruction=fsm.Instruction( audio='Congratulations! You have finished!'), next_state=st_end)) return st_start