Created
October 30, 2019 15:52
-
-
Save Namburger/7b99d4622dff53ee4f76d720a92e286c to your computer and use it in GitHub Desktop.
crashing Edgetpu Accelerator with multi-thread access
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
from edgetpu.classification.engine import ClassificationEngine | |
from edgetpu.utils import dataset_utils | |
from PIL import Image | |
import multiprocessing | |
from multiprocessing import Process | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
'--model', help='File path of Tflite model.', required=True) | |
parser.add_argument('--label', help='File path of label file.', required=True) | |
parser.add_argument( | |
'--image', help='File path of the image to be recognized.', required=True) | |
args = parser.parse_args() | |
# Prepare labels. | |
labels = dataset_utils.read_label_file(args.label) | |
# Initialize engine. | |
# Run inference. | |
img = Image.open(args.image) | |
def f(args, img): | |
engine = ClassificationEngine(args.model) | |
for result in engine.ClassifyWithImage(img, top_k=3): | |
print('---------------------------') | |
print(labels[result[0]]) | |
print('Score : ', result[1]) | |
p1 = Process(target=f, args=(args, img)) | |
p2 = Process(target=f, args=(args, img)) | |
p3 = Process(target=f, args=(args, img)) | |
p4 = Process(target=f, args=(args, img)) | |
p1.start() | |
p2.start() | |
p3.start() | |
p4.start() | |
p1.join() | |
p2.join() | |
p3.join() | |
p4.join() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment