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

Add aarch64 python 3.10 build support #103

Open
wants to merge 5 commits into
base: FixInstallRequirements
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
17 changes: 12 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,28 @@ PYTHON ?= $(shell which python3)
MAKEFILE_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
PY3_VER ?= $(shell $(PYTHON) -c "import sys;print('%d%d' % sys.version_info[:2])")
OS := $(shell uname -s)
ARCH := $(shell uname -p)

ifeq ($(PYTHON),)
$(error PYTHON must be set)
endif

# Allowed CPU values: k8, armv7a, aarch64, darwin
ifeq ($(OS),Linux)
CPU ?= k8
else ifeq ($(OS),Darwin)
ifeq ($(ARCH),arm)
CPU ?= darwin_arm64
DARWIN_CPU := darwin_arm64
else
CPU ?= darwin

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @yasdum!
I'm not super familiar with MacOS, why is there a need for a darwin and a darwin_x86_64?

DARWIN_CPU := darwin_x86_64
endif
else
$(error $(OS) is not supported)
endif
ifeq ($(filter $(CPU),k8 armv7a aarch64 darwin),)
$(error CPU must be k8, armv7a, aarch64, or darwin)

ifeq ($(filter $(CPU),k8 armv7a aarch64 darwin darwin_arm64),)
$(error CPU must be k8, armv7a, aarch64, darwin, or darwin_arm64)
endif

# Allowed COMPILATION_MODE values: opt, dbg, fastbuild
Expand All @@ -46,7 +53,7 @@ COMMON_BAZEL_BUILD_FLAGS := --compilation_mode=$(COMPILATION_MODE) \

BAZEL_BUILD_FLAGS_Linux := --linkopt=-L$(MAKEFILE_DIR)/libedgetpu_bin/direct/$(CPU) \
--linkopt=-l:libedgetpu.so.1
BAZEL_BUILD_FLAGS_Darwin := --linkopt=-L$(MAKEFILE_DIR)/libedgetpu_bin/direct/$(CPU) \
BAZEL_BUILD_FLAGS_Darwin := --linkopt=-L$(MAKEFILE_DIR)/libedgetpu_bin/direct/$(DARWIN_CPU) \
--linkopt=-ledgetpu.1

ifeq ($(COMPILATION_MODE), opt)
Expand All @@ -72,7 +79,7 @@ else ifeq ($(CPU),armv7a)
BAZEL_BUILD_FLAGS_Linux += --copt=-ffp-contract=off
PY_WRAPPER_SUFFIX := arm-linux-gnueabihf.so
PY_DIST_PLATFORM := linux-armv7l
else ifeq ($(CPU), darwin)
else ifeq ($(findstring darwin,$(CPU)),darwin)
PY_WRAPPER_SUFFIX := darwin.so
endif

Expand Down
2 changes: 1 addition & 1 deletion examples/classify_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def main():
raise ValueError('Only support uint8 input type.')

size = common.input_size(interpreter)
image = Image.open(args.input).convert('RGB').resize(size, Image.ANTIALIAS)
image = Image.open(args.input).convert('RGB').resize(size, Image.LANCZOS)
Copy link

@Namburger Namburger Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There're too many things going on in this one PR, changes like this should be in a separate pr.
Anyhow, I recently merged another pr that've done this.


# Image data must go through two transforms before running inference:
# 1. normalization: f = (input - mean) / std
Expand Down
2 changes: 1 addition & 1 deletion examples/detect_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def main():

image = Image.open(args.input)
_, scale = common.set_resized_input(
interpreter, image.size, lambda size: image.resize(size, Image.ANTIALIAS))
interpreter, image.size, lambda size: image.resize(size, Image.LANCZOS))

print('----INFERENCE TIME----')
print('Note: The first inference is slow because it includes',
Expand Down
2 changes: 1 addition & 1 deletion examples/model_pipelining_classify_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def main():
size = common.input_size(runner.interpreters()[0])
name = common.input_details(runner.interpreters()[0], 'name')
image = np.array(
Image.open(args.input).convert('RGB').resize(size, Image.ANTIALIAS))
Image.open(args.input).convert('RGB').resize(size, Image.LANCZOS))

def producer():
for _ in range(args.count):
Expand Down
2 changes: 1 addition & 1 deletion examples/movenet_pose_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def main():
interpreter.allocate_tensors()

img = Image.open(args.input)
resized_img = img.resize(common.input_size(interpreter), Image.ANTIALIAS)
resized_img = img.resize(common.input_size(interpreter), Image.LANCZOS)
common.set_input(interpreter, resized_img)

interpreter.invoke()
Expand Down
4 changes: 2 additions & 2 deletions examples/semantic_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def main():
img = Image.open(args.input)
if args.keep_aspect_ratio:
resized_img, _ = common.set_resized_input(
interpreter, img.size, lambda size: img.resize(size, Image.ANTIALIAS))
interpreter, img.size, lambda size: img.resize(size, Image.LANCZOS))
else:
resized_img = img.resize((width, height), Image.ANTIALIAS)
resized_img = img.resize((width, height), Image.LANCZOS)
common.set_input(interpreter, resized_img)

interpreter.invoke()
Expand Down
2 changes: 1 addition & 1 deletion libedgetpu
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions libedgetpu_bin/throttled/darwin_arm64/libedgetpu.1.dylib
1 change: 1 addition & 0 deletions libedgetpu_bin/throttled/darwin_x86_64/libedgetpu.1.dylib
2 changes: 1 addition & 1 deletion pycoral/adapters/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,4 @@ def make(i):
bbox=BBox(xmin=xmin, ymin=ymin, xmax=xmax,
ymax=ymax).scale(sx, sy).map(int))

return [make(i) for i in range(count) if scores[i] >= score_threshold]
return [make(i) for i in range(len(scores)) if scores[i] >= score_threshold]
10 changes: 8 additions & 2 deletions pycoral/pipeline/pipelined_model_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@ def __init__(self, interpreters):
def __del__(self):
if self._runner:
# Push empty request to stop the pipeline in case user forgot.
self.push({})
num_unconsumed = 0
try:
print("Push empty request to stop the pipeline...")
self.push({})
except RuntimeError:
print("The pipeline has already been closed successfully.")
return

# Release any unconsumed tensors if any.
num_unconsumed = 0
while self.pop():
num_unconsumed += 1
if num_unconsumed:
Expand Down
2 changes: 1 addition & 1 deletion tests/detect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_objects(model_file, delegate, image_file, score_threshold=0.0):
interpreter.allocate_tensors()
image = Image.open(test_utils.test_data_path(image_file))
_, scale = common.set_resized_input(
interpreter, image.size, lambda size: image.resize(size, Image.ANTIALIAS))
interpreter, image.size, lambda size: image.resize(size, Image.LANCZOS))
interpreter.invoke()
return detect.get_objects(
interpreter, score_threshold=score_threshold, image_scale=scale)
Expand Down
2 changes: 1 addition & 1 deletion tests/multiple_tpus_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def detection_task(num_inferences):
_, scale = common.set_resized_input(
interpreter,
img.size,
lambda size, image=img: image.resize(size, Image.ANTIALIAS))
lambda size, image=img: image.resize(size, Image.LANCZOS))
interpreter.invoke()
ret = detect.get_objects(
interpreter, score_threshold=0.7, image_scale=scale)
Expand Down
2 changes: 1 addition & 1 deletion tests/segment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def segment_image(model_file, delegate, image_file, mask_file):
interpreter.allocate_tensors()

image = Image.open(test_utils.test_data_path(image_file)).resize(
common.input_size(interpreter), Image.ANTIALIAS)
common.input_size(interpreter), Image.LANCZOS)
common.set_input(interpreter, image)
interpreter.invoke()

Expand Down