def __init__(self, surround_config): surround = Surround( [WranglingData(), ModellingAndPrediction(), DisplayOutput()], __name__) surround.set_config(surround_config) super().__init__(surround)
def __init__(self): #initialize surround and pass stages as parameters surround = Surround( [InputBlob(), OutputLayer(), Confidence(), NMS(), DrawBoxes()], __name__) super().__init__(surround)
def main(): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind(('0.0.0.0', 1024)) surround = Surround([ValidateData(), VadDetection()]) config = Config() surround.set_config(config) surround.init_stages() audio_input = [] last_packet_time = time.time() packet_id = -1 while True: source_addr = None while len(audio_input) < 48000: # Retrieve data from client (9600 samples in bytes = 9600 * 2 bytes (2 bytes per sample)) data_bytes, source_addr = sock.recvfrom(2400 * 2 + 4) # If last packet received was 5 seconds ago, clear cache if last_packet_time + 5 < time.time(): audio_input.clear() last_packet_time = time.time() # Get the packet id from the end of the byte array packet_id = int.from_bytes(data_bytes[2400 * 2:], sys.byteorder, signed=True) # Convert the byte array into an array of float samples (-1 to 1) for i in range(0, len(data_bytes) - 4, 2): sample = int.from_bytes(data_bytes[i : i + 2], sys.byteorder, signed=True) sample /= 32767.0 audio_input.append(sample) # Process the audio data for voice activity data = VadData(audio_input) surround.process(data) # Rolling window of 2400 samples (50ms) audio_input = audio_input[2400:] if data.error is None and data.output_data is not None: print("Noise: " + str(data.output_data[0] * 100.0) + " Voice: " + str(data.output_data[1] * 100.0)) # Sending the results back to who made the request results = { "id": packet_id, "noise": float(data.output_data[0]), "voice": float(data.output_data[1]) } sock.sendto(json.dumps(results).encode(), (source_addr[0], 25565)) else: print(data.error) break
def face_recognition_pipeline(): """ Returns the stages that form part of the face recognition pipeline. """ return Surround([ DecodeImage(), DownsampleImage(), RotateImage(), ImageTooDark(), DetectAndAlignFaces(), LargestFace(), FaceTooBlurry(), ExtractFaceEncodings() ])
def test_surround_config(self): path = os.path.dirname(__file__) config = Config() config.read_config_files([os.path.join(path, "config.yaml")]) surround = Surround([HelloStage()]) surround.set_config(config) data = BasicData() surround.process(data) self.assertEqual(data.config_value, "Scott")
def test_surround_override(self): path = os.path.dirname(__file__) surround = Surround([FirstStage()]) config = Config() config.read_config_files([os.path.join(path, "stages.yaml")]) surround.set_config(config) data = BasicData() surround.process(data) self.assertEqual(data.stage1, "first stage") self.assertEqual(data.stage2, "second stage")
def main(): logging.basicConfig(level=logging.INFO) surround = Surround( [WranglingData(), ModellingAndPrediction(), DisplayOutput()]) surround_config = Config() surround_config.read_config_files(["config.yaml"]) surround.set_config(surround_config) surround.init_stages() # Fetch the data from the data folder. raw_data = fetch_data(surround_config) # epl_data is created as the SurroundData type. epl_data = EplData() # raw_data is fed into epl_data. epl_data.feed_data(raw_data) # Surround process started. surround.process(epl_data)
def main(config=None): default_runner = config.get_path('runner.default') default_assembler = config.get_path('assembler.default') parser = argparse.ArgumentParser( prog='linear', description="Surround mode(s) available to run this module") parser.add_argument( '-r', '--runner', help="Runner for the Assembler (index or name)", default=default_runner if default_runner is not None else "0") parser.add_argument( '-a', '--assembler', help="Assembler to run (index or name)", default=default_assembler if default_assembler is not None else "0") parser.add_argument('-ne', '--no-experiment', dest='experiment', help="Don't consider this run an experiment", action="store_false") parser.add_argument( '--status', help= "Display information about the project such as available RUNNERS and assemblers", action="store_true") parser.add_argument('-n', '--note', help="Add a note to the experiment", type=str) parser.add_argument('--mode', help="Mode to run (train, batch)", default="batch") args = parser.parse_args() surround = Surround(RUNNERS, ASSEMBLIES, "linear", "linear eqaution", os.path.dirname(os.path.dirname(__file__))) if args.status: surround.show_info() else: surround.run(args.runner, args.assembler, args.mode, args.experiment, args)
def operate(self, surround_data, config): surround_data.text = "Hello" class WriteWorld(Stage): def dump_output(self, surround_data, config): dir_path = os.path.dirname(os.path.realpath(__file__)) text_file = open(dir_path + "/stages/WriteWorld/Output.txt", "w") text_file.write(surround_data.text) text_file.close() def operate(self, surround_data, config): surround_data.text = "World" class BasicData(SurroundData): text = None if __name__ == "__main__": logging.basicConfig(level=logging.INFO) surround = Surround([WriteHello(), WriteWorld()]) adapter = FileSystemRunner( surround, description="A sample project to show dump intermediate ouput", config_file="Path to configuration file") adapter.start() surround.process(BasicData())
class ParseData(Stage): def operate(self, surround_data, config): surround_data.output = {"result": "Hi, " + surround_data.input['name']} def metadata(): return { "input": { "name": { "type": "text" } }, "output": { "result": { "type": "text" } }, "version": "1.0.0" } surround = Surround([ParseData()]) runner = WebServiceRunner(surround, metadata()) app = runner.app if __name__ == "__main__": logging.basicConfig(level=logging.INFO) app.run(host='0.0.0.0', port=8000)
import logging from surround import Surround, Config from svr.SVR_stages import FeedData, SVRData, ComputeForecast, PlotResult logging.basicConfig(level=logging.INFO) # def main(): # wrapper = PipelineWrapper() # config = wrapper.get_config() # output = wrapper.run(json.dumps({"data": "hello"})) # with open(os.path.join(config["output_path"], "output.txt"), 'w') as f: # f.write(output["output"]) # logging.info(output) if __name__ == "__main__": logging.basicConfig(level=logging.INFO) surround = Surround([FeedData(), ComputeForecast(), PlotResult()]) surround_config = Config() surround_config.read_config_files(["config.yaml"]) surround.set_config(surround_config) surround.init_stages() svr_data = SVRData() svr_data.get_data() surround.process(svr_data)
class ProcessCSV(Stage): def operate(self, surround_data, config): surround_data.word_count = len( surround_data.row_dict['Consumer complaint narrative'].split()) if config and config.get_path("ProcessCSV.include_company"): surround_data.company = surround_data.row_dict['Company'] class BasicData(SurroundData): word_count = None company = None def __init__(self, row_dict): self.row_dict = row_dict if __name__ == "__main__": logging.basicConfig(level=logging.INFO) surround = Surround([ProcessCSV()]) adapter = CustomFileSystemRunner( surround, description="A sample project to process a CSV file", output_dir="Directory to store the output", config_file="Path to configuration file", file0="Input CSV file") adapter.start()
def init_stage(self, config): file_ = open(config.get_path("surround.path_to_HelloSurround"), "r") self.data = file_.read() def operate(self, surround_data, config): print(self.data) class HelloWorld(Stage): def __init__(self): self.data = None def init_stage(self, config): file_ = open(config.get_path("surround.path_to_HelloWorld"), "r") self.data = file_.read() def operate(self, surround_data, config): print(self.data) class BasicData(SurroundData): text = None if __name__ == "__main__": logging.basicConfig(level=logging.INFO) surround = Surround([HelloSurround(), HelloWorld()]) surround_config = Config() surround_config.read_config_files(["examples/init-stage-with-data/config.yaml"]) surround.set_config(surround_config) surround.init_stages() surround.process(BasicData())
def __init__(self): surround = Surround([ValidateData()], __name__) super().__init__(surround)
import logging from surround import Stage, SurroundData, Surround class HelloStage(Stage): def operate(self, surround_data, config): surround_data.text = "hello" class BasicData(SurroundData): text = None if __name__ == "__main__": logging.basicConfig(level=logging.INFO) surround = Surround([HelloStage()]) data = BasicData() surround.process(data) print(data.text)
def __init__(self): surround = Surround([HelloStage(), RotateImage()]) type_of_uploaded_object = AllowedTypes.IMAGE self.config = surround.config super().__init__(surround, type_of_uploaded_object)
def __init__(self): surround = Surround([DataInput()], __name__) super().__init__(surround)
def test_happy_path(self): surround = Surround([HelloStage()]) data = BasicData() surround.process(data) self.assertEqual(data.text, "hello")
def test_rejecting_attributes(self): surround = Surround([HelloStage()]) data = BasicData() surround.process(data) self.assertRaises(AttributeError, getattr, data, "no_text")