Skip to content

Commit

Permalink
Merge branch 'kubeedge:main' into TinyMS-Support-and-Demos
Browse files Browse the repository at this point in the history
  • Loading branch information
Lj1ang authored Aug 1, 2022
2 parents 2c5d08c + b317015 commit d1b1204
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 20 deletions.
12 changes: 9 additions & 3 deletions hack/run-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ SEDNA_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"

cd "$SEDNA_ROOT"

# source local-up script
# Prepare all-in-one env
{
__WITH_SOURCE__=true
# this will export KUBECONFIG
source hack/local-up.sh
trap cleanup EXIT
echo "Prepare all-in-one env"
cat scripts/installation/all-in-one.sh | KUBEEDGE_VERSION=v1.8.0 NUM_EDGE_NODES=0 bash -
}

# Running e2e
echo "Running e2e..."
go test ./test/e2e -v


# Clean all-in-one env
echo "Chean all-in-one env"
cat scripts/installation/all-in-one.sh | bash /dev/stdin clean
1 change: 1 addition & 0 deletions lib/requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ plato-learn~=0.26 # Apache-2.0
scikit-learn~=0.24.1 # BSD
# multi_edge_inference
kafka-python~=2.0.2 # Apache-2.0
opencv-python~=4.6.0 # Apache-2.0
1 change: 0 additions & 1 deletion lib/sedna/algorithms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@
from . import hard_example_mining
from . import multi_task_learning
from . import unseen_task_detect
from . import optical_flow
from . import reid
46 changes: 30 additions & 16 deletions lib/sedna/algorithms/optical_flow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

"""Optical Flow Algorithms"""
import abc

import numpy
import cv2
from sedna.common.class_factory import ClassFactory, ClassType
from sedna.common.log import LOGGER

Expand All @@ -40,6 +38,8 @@ def __call__(self, old_frame=None, current_frame=None):

@ClassFactory.register(ClassType.OF, alias="LukasKanadeOF")
class LukasKanade(BaseFilter, abc.ABC):
import cv2

"""
Class to detect movement between two consecutive images.
"""
Expand All @@ -49,7 +49,7 @@ def __init__(self, **kwargs):
dict(maxCorners=100, qualityLevel=0.3, minDistance=7, blockSize=7)

# Parameters for Lucas Kanade optical flow
_criteria = cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT
_criteria = self.cv2.TERM_CRITERIA_EPS | self.cv2.TERM_CRITERIA_COUNT

self.lk_params = dict(
winSize=(15, 15),
Expand All @@ -67,14 +67,15 @@ def __call__(self, old_frame=None, current_frame=None):

movement = False
try:
old_gray = cv2.cvtColor(old_frame, cv2.COLOR_BGR2GRAY)
p0 = cv2.goodFeaturesToTrack(
old_gray = self.cv2.cvtColor(old_frame, self.cv2.COLOR_BGR2GRAY)
p0 = self.cv2.goodFeaturesToTrack(
old_gray, mask=None, **self.feature_params)

current_gray = cv2.cvtColor(current_frame, cv2.COLOR_BGR2GRAY)
current_gray = \
self.cv2.cvtColor(current_frame, self.cv2.COLOR_BGR2GRAY)

# Calculate Optical Flow
p1, st, err = cv2.calcOpticalFlowPyrLK(
p1, st, err = self.cv2.calcOpticalFlowPyrLK(
old_gray, current_gray, p0, None, **self.lk_params
)

Expand All @@ -88,7 +89,10 @@ def __call__(self, old_frame=None, current_frame=None):
# Allclose is used instead of array_equal to support
# array of floats (if we remove rounding).
movement = \
not numpy.allclose(numpy.rint(good_new), numpy.rint(good_old))
not numpy.allclose(
numpy.rint(good_new),
numpy.rint(good_old)
)
except Exception as ex:
LOGGER.error(
f"Error during the execution of\
Expand All @@ -99,6 +103,9 @@ def __call__(self, old_frame=None, current_frame=None):

@ClassFactory.register(ClassType.OF, alias="LukasKanadeOF_CUDA")
class LukasKanadeCUDA(BaseFilter, abc.ABC):
import cv2
import numpy

"""
Class to detect movement between
two consecutive images (GPU implementation).
Expand All @@ -107,7 +114,7 @@ def __init__(self, **kwargs):
# Parameters for ShiTomasi corner detection
self.feature_params = \
dict(
srcType=cv2.CV_8UC1,
srcType=self.cv2.CV_8UC1,
maxCorners=100,
qualityLevel=0.3,
minDistance=7,
Expand All @@ -120,8 +127,11 @@ def __init__(self, **kwargs):
)

self.corner_detector = \
cv2.cuda.createGoodFeaturesToTrackDetector(**self.feature_params)
self.of = cv2.cuda.SparsePyrLKOpticalFlow_create(**self.lk_params)
self.cv2.cuda.createGoodFeaturesToTrackDetector(
**self.feature_params
)
self.of = \
self.cv2.cuda.SparsePyrLKOpticalFlow_create(**self.lk_params)

def __call__(self, old_frame=None, current_frame=None):
"""
Expand All @@ -131,16 +141,17 @@ def __call__(self, old_frame=None, current_frame=None):
`False` means that there is no movement.
"""

old_frame = cv2.cuda_GpuMat(old_frame)
current_frame = cv2.cuda_GpuMat(current_frame)
old_frame = self.cv2.cuda_GpuMat(old_frame)
current_frame = self.cv2.cuda_GpuMat(current_frame)

movement = False
try:
old_gray = cv2.cuda.cvtColor(old_frame, cv2.COLOR_BGR2GRAY)
old_gray = \
self.cv2.cuda.cvtColor(old_frame, self.cv2.COLOR_BGR2GRAY)
p0 = self.corner_detector.detect(old_gray)

current_gray = \
cv2.cuda.cvtColor(current_frame, cv2.COLOR_BGR2GRAY)
self.cv2.cuda.cvtColor(current_frame, self.cv2.COLOR_BGR2GRAY)

# Calculate Optical Flow
p1, st, err = self.of.calc(
Expand All @@ -161,7 +172,10 @@ def __call__(self, old_frame=None, current_frame=None):
# Allclose is used instead of array_equal to
# support array of floats (if we remove rounding).
movement = \
not numpy.allclose(numpy.rint(good_new), numpy.rint(good_old))
not numpy.allclose(
numpy.rint(good_new),
numpy.rint(good_old)
)
except Exception as ex:
LOGGER.error(
f"Error during the execution of\
Expand Down

0 comments on commit d1b1204

Please sign in to comment.