model_dir = './mobilenet_v1_1.0_224_quant/' model_name = 'mobilenet_v1_1.0_224_quant.tflite' repeat = 10 model_dir = download_model_zoo(model_dir, model_name) tflite_model_file = os.path.join(model_dir, model_name) tflite_model_buf = open(tflite_model_file, "rb").read() try: import tflite tflite_model = tflite.Model.GetRootAsModel(tflite_model_buf, 0) except AttributeError: import tflite.Model tflite_model = tflite.Model.Model.GetRootAsModel(tflite_model_buf, 0) interpreter = Interpreter(tflite_model_file, num_threads=get_cpu_count()) interpreter.allocate_tensors() _, height, width, _ = interpreter.get_input_details()[0]['shape'] image = load_test_image('uint8', height, width) numpy_time = np.zeros(repeat) for i in range(0, repeat): start_time = time.time() results = classify_image(interpreter, image) elapsed_ms = (time.time() - start_time) * 1000 numpy_time[i] = elapsed_ms print("tflite %-20s %-19s (%s)" % (model_name, "%.2f ms" % np.mean(numpy_time),
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) GLib.timeout_add(500, self.update) # Chart # CPU self.cpu_circle = Chart( _("CPU"), "#f44336", "#9E9E9E" ) # Memory self.memory_circle = Chart( _("Memory"), "#E91E63", "#9E9E9E" ) # Swap self.swap_circle = Chart( _("Swap"), "#4CAF50", "#9E9E9E" ) # Speed # Disk self.disk_speed = SpeedBox( _("Disk"), _("Read Speed"), _("Write Speed"), "#9C27B0", "#FF9800" ) # Network self.network_speed = SpeedBox( _("Network"), _("Send Speed"), _("Recive Speed"), "#3F51B5", "#FF5722" ) # Finalize speed = Gtk.VBox(spacing=10) speed.set_homogeneous(True) speed.pack_start(self.disk_speed, True, True, 0) speed.pack_start(self.network_speed, True, True, 0) # Process List # CPU self.process_cpu = CPUProcess() # Memory self.process_memory = MemoryProcess() # Graph # Label cpu_label = Gtk.VBox(spacing=10) for number in range(util.get_cpu_count()): cpu_label.pack_start( HeaderLabel(CPU_COLOR[number], label=f"CPU{number}"), True, True, 0 ) memory_label = LabelBox( _("Memory"), _("Swap"), "#E91E63", "#4CAF50" ) disk_label = LabelBox( _("Read Speed"), _("Write Speed"), "#9C27B0", "#FF9800" ) network_label = LabelBox( _("Send Speed"), _("Recive Speed"), "#3F51B5", "#FF5722" ) # Memory self.memory_graph = Graph( "#E91E63", "#4CAF50" ) # Disk self.disk_graph = VariableGraph( "#9C27B0", "#FF9800" ) # Network self.network_graph = VariableGraph( "#3F51B5", "#FF5722" ) # Main Layout 1 # Layout 1 layout_1 = Gtk.HBox(spacing=10) layout_1.set_homogeneous(True) layout_1.pack_start(self.cpu_circle, True, True, 0) layout_1.pack_start(self.memory_circle, True, True, 0) layout_1.pack_start(self.swap_circle, True, True, 0) layout_1.pack_start(speed, True, True, 0) # Layout 2 layout_2 = Gtk.HBox(spacing=10) layout_2.set_homogeneous(True) layout_2.pack_start(self.process_cpu, True, True, 0) layout_2.pack_start(self.process_memory, True, True, 0) # Finalize main_layout_1 = Gtk.VBox(spacing=10) main_layout_1.set_homogeneous(True) main_layout_1.pack_start(layout_1, True, True, 0) main_layout_1.pack_start(layout_2, True, True, 0) # Main Layout 2 # Layout 1 layout_1 = Gtk.VBox(spacing=10) layout_1.set_homogeneous(True) layout_1.pack_start(cpu_label, True, True, 0) layout_1.pack_start(memory_label, True, True, 0) layout_1.pack_start(disk_label, True, True, 0) layout_1.pack_start(network_label, True, True, 0) # Layout 2 layout_2 = Gtk.VBox(spacing=10) layout_2.set_homogeneous(True) layout_2.pack_start(Dazzle.CpuGraph(), True, True, 0) layout_2.pack_start(self.memory_graph, True, True, 0) layout_2.pack_start(self.disk_graph, True, True, 0) layout_2.pack_start(self.network_graph, True, True, 0) # Finalize main_layout_2 = Gtk.HBox(spacing=10) main_layout_2.pack_start(layout_1, False, False, 0) main_layout_2.pack_start(layout_2, True, True, 0) # Stack self.stack = Gtk.Stack() self.stack.add_titled(main_layout_1, "circle", _("Overview")) self.stack.add_titled(main_layout_2, "graph", _("Graph")) stack_switcher = Gtk.StackSwitcher() stack_switcher.set_stack(self.stack) # Finalize self.header.add(stack_switcher) self.main.add(self.stack) self.update() self.show_all()