Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.
Merged
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
8 changes: 6 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@
- id: detect-private-key
files: (?!.*tar.gz)^.*$
- id: end-of-file-fixer
files: \.md$
files: \.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$
- id: trailing-whitespace
files: \.md$
files: \.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$
- repo: https://github.com/Lucas-C/pre-commit-hooks.git
sha: v1.0.1
hooks:
- id: forbid-crlf
files: \.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$
- id: remove-crlf
files: \.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$
- id: forbid-tabs
files: \.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$
- id: remove-tabs
files: \.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$
- repo: local
hooks:
- id: clang-format-with-version-check
Expand Down
13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dist: trusty
os:
- linux
env:
- JOB=PRE_COMMIT
- JOB=pre_commit

addons:
apt:
Expand All @@ -15,23 +15,26 @@ addons:
- python
- python-pip
- python2.7-dev
- clang-format-3.8
ssh_known_hosts: 52.76.173.135

before_install:
- sudo pip install -U virtualenv pre-commit pip

script:
- exit_code=0
- .travis/pre_commit.sh || exit_code=$(( exit_code | $? ))
- if [[ "$JOB" == "pre_commit" ]]; then sudo ln -s /usr/bin/clang-format-3.8 /usr/bin/clang-format; fi
- |
function timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; }
- |
timeout 600 .travis/${JOB}.sh # 10min timeout
RESULT=$?; if [ $RESULT -eq 0 ] || [ $RESULT -eq 142 ]; then true; else exit 1; fi;
- |
if [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then exit 0; fi;
if [[ "$TRAVIS_BRANCH" != "develop" && ! "$TRAVIS_BRANCH" =~ ^v[[:digit:]]+\.[[:digit:]]+(\.[[:digit:]]+)?(-\S*)?$ ]]; then echo "not develop branch, no deploy"; exit 0; fi;
export DEPLOY_DOCS_SH=https://raw.githubusercontent.com/PaddlePaddle/PaddlePaddle.org/master/scripts/deploy/deploy_docs.sh
export MOBILE_DIR=`pwd`
cd ..
curl $DEPLOY_DOCS_SH | bash -s $CONTENT_DEC_PASSWD $TRAVIS_BRANCH $MOBILE_DIR
exit_code=$(( exit_code | $? ))
exit $exit_code

notifications:
email:
Expand Down
8 changes: 3 additions & 5 deletions .travis/pre_commit.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#!/bin/bash
function abort(){
echo "Your commit not fit PaddlePaddle code style" 1>&2
echo "Please use pre-commit scripts to auto-format your code" 1>&2
echo "Install pre-commit following 2 steps:" 1>&2
echo "1> pip install pre-commit" 1>&2
echo "2> pre-commit install (under the Mobile repo)" 1>&2
echo "Your change doesn't follow PaddlePaddle's code style" 1>&2
echo "Please use pre-commit to auto-format your code." 1>&2
exit 1
}

Expand All @@ -14,6 +11,7 @@ cd `dirname $0`
cd ..
export PATH=/usr/bin:$PATH
pre-commit install
clang-format --version

if ! pre-commit run -a ; then
ls -lh
Expand Down
3 changes: 2 additions & 1 deletion Demo/iOS/AICamera/AICamera/AICamera-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
// Use this file to import your target's public headers that you would like to
// expose to Swift.
//

#import "ImageRecognizerPaddleWrapper.h"
Expand Down
1 change: 0 additions & 1 deletion Demo/iOS/AICamera/AICamera/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,3 @@ class AppDelegate: UIResponder, UIApplicationDelegate {


}

14 changes: 7 additions & 7 deletions Demo/iOS/AICamera/AICamera/ImageRecognizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ protocol ImageRecognizerDelegate {
}

class ImageRecognizer {

var imageRecognizer: ImageRecognizerPaddleWrapper?

init(model: SSDModel) {
imageRecognizer = ImageRecognizerPaddleWrapper(model: model.rawValue, withNormHeight: model.normDimension().0, withNormWidth: model.normDimension().1)
}

func inference(imageBuffer: UnsafeMutablePointer<UInt8>!, width: Int32, height: Int32, score: Float) -> NSMutableArray! {

return imageRecognizer?.inference(imageBuffer, withHeight: height, withWidth: width, withFilterScore: score)
}

func release() {
imageRecognizer?.destroy()
}
}

}
9 changes: 7 additions & 2 deletions Demo/iOS/AICamera/AICamera/ImageRecognizerPaddleWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@

@interface ImageRecognizerPaddleWrapper : NSObject

- (instancetype)initWithModel:(NSString*)modelFileName withNormHeight:(int)height withNormWidth:(int)width;
- (NSMutableArray*)inference:(unsigned char *)pixels withHeight:(int)height withWidth:(int)width withFilterScore:(float) filterScore;
- (instancetype)initWithModel:(NSString *)modelFileName
withNormHeight:(int)height
withNormWidth:(int)width;
- (NSMutableArray *)inference:(unsigned char *)pixels
withHeight:(int)height
withWidth:(int)width
withFilterScore:(float)filterScore;
- (void)destroy;

@end
Expand Down
16 changes: 8 additions & 8 deletions Demo/iOS/AICamera/AICamera/ImageRecognizerPaddleWrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ - (instancetype)initWithModel:(NSString*)modelFileName withNormHeight:(int)heigh
{
int channel = 3;
const std::vector<float> means({104, 117, 124});

NSBundle* bundle = [NSBundle mainBundle];
NSString* resourceDirectoryPath = [bundle bundlePath];
NSString* path = [[resourceDirectoryPath stringByAppendingString:@"/"] stringByAppendingString:modelFileName];

self->recognizer.init([path UTF8String], height, width, channel, means);

}
return self;
}
Expand All @@ -48,25 +48,25 @@ - (NSMutableArray*)inference:(unsigned char *)pixels withHeight:(int)height with
int channel = 4;
image::Config config(image::kBGR, image::CLOCKWISE_R90);
self->recognizer.infer(pixels, height, width, channel, config, result);

NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:result.height];
int w = result.width;

for (int i = 0; i < result.height; i++) {
float score = result.data[i * w + 2];
if (score < filterScore) continue;

SSDData *ssdData = [[SSDData alloc] init];
ssdData.label = kLabels[(int) result.data[i * w + 1]];
ssdData.accuracy = score;
ssdData.xmin = result.data[i * w + 3];
ssdData.ymin = result.data[i * w + 4];
ssdData.xmax = result.data[i * w + 5];
ssdData.ymax = result.data[i * w + 6];

[array addObject:ssdData];
}

return array;
}

Expand Down
14 changes: 7 additions & 7 deletions Demo/iOS/AICamera/AICamera/SSDData.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

@interface SSDData : NSObject

@property (nonatomic) NSString *label;
@property (nonatomic) float accuracy;
@property (nonatomic) float xmin;
@property (nonatomic) float ymin;
@property (nonatomic) float xmax;
@property (nonatomic) float ymax;
@property(nonatomic) NSString *label;
@property(nonatomic) float accuracy;
@property(nonatomic) float xmin;
@property(nonatomic) float ymin;
@property(nonatomic) float xmax;
@property(nonatomic) float ymax;

@end
@end
22 changes: 11 additions & 11 deletions Demo/iOS/AICamera/AICamera/SSDDrawLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,51 @@ import UIKit

class SSDDrawLayer: CAShapeLayer {
var labelLayer = CATextLayer()

required override init() {
super.init()
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func render(_ data: SSDData, model:SSDModel, isBackCamera:Bool) {

let screenWidth = UIScreen.main.bounds.size.width
let screenHeight = UIScreen.main.bounds.size.height

let x = CGFloat(isBackCamera ? data.xmin : 1 - data.xmax) * screenWidth
let y = CGFloat(data.ymin) * screenHeight
let width = CGFloat(data.xmax - data.xmin) * screenWidth
let height = CGFloat(data.ymax - data.ymin) * screenHeight

if (model == SSDModel.FaceMobileNet160 && data.label != "aeroplane") {
return;
}

//draw box
self.path = UIBezierPath(roundedRect: CGRect(x: x, y: y, width: width, height: height), cornerRadius: 10).cgPath
self.strokeColor = UIColor.cyan.cgColor
self.lineWidth = 4.0
self.fillColor = nil
self.lineJoin = kCALineJoinBevel

if (model == SSDModel.FaceMobileNet160) {
//do not draw label for face
return;
}

let text = String.init(format: "%@: %.02f", data.label, data.accuracy)
var displayString = NSAttributedString(string: text, attributes: [
NSStrokeColorAttributeName : UIColor.black,
NSForegroundColorAttributeName : UIColor.white,
NSStrokeWidthAttributeName : NSNumber(value: -6.0),
NSFontAttributeName : UIFont.systemFont(ofSize: 20, weight: 3)
])

//draw label

labelLayer.string = displayString
labelLayer.frame = CGRect.init(x: x + 4, y: y + height - 22, width: 1000, height: 30)
addSublayer(labelLayer)
Expand Down
3 changes: 1 addition & 2 deletions Demo/iOS/AICamera/AICamera/SSDModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum SSDModel : String {
case PascalMobileNet300 = "pascal_mobilenet_300_66.paddle"
case FaceMobileNet160 = "face_mobilenet_160_91.paddle"
case PascalVGG300 = "vgg_ssd_net.paddle"

func normDimension() -> (Int32, Int32)
{
switch self
Expand All @@ -26,4 +26,3 @@ enum SSDModel : String {
}
}
}

6 changes: 3 additions & 3 deletions Demo/iOS/AICamera/AICamera/SSDMultiboxLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
import UIKit

class SSDMultiboxLayer: CALayer {

func displayBoxs(with ssdDataList: NSMutableArray, model: SSDModel, isBackCamera: Bool){
self.sublayers?.forEach({ (layer) in
layer.removeFromSuperlayer()
})

for ssdData in ssdDataList {
let boxLayer = SSDDrawLayer.init()
boxLayer.render(ssdData as! SSDData, model: model, isBackCamera: isBackCamera)

self.addSublayer(boxLayer)
}
}
Expand Down
Loading