我训练了一个Caffe模型,该模型没有指定输入大小。然后,我使用OpenCV在Android上运行了它。代码如下。
import java.util.Random;
import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.stage.Stage;
public class Main extends Application{
private Point[] triangle;
private static int points = 1000000;
private static Point midPoint;
private int width = 600, height = 600;
@Override
public void start(Stage primaryStage) {
Canvas canvas = new Canvas(width,height);
GraphicsContext gc = canvas.getGraphicsContext2D();
Scene scene = new Scene(new Group(canvas));
primaryStage.setScene(scene);
primaryStage.show();
Random ran = new Random();
triangle = new Point[3];
triangle[1] = new Point(0d, 0d);
triangle[0] = new Point(width/2d, (double)height);
triangle[2] = new Point((double)width, 0d);
midPoint = Point.findMidTo(triangle[0], triangle[1], triangle[2]);
AnimationTimer timer = new AnimationTimer(){
@Override
public void handle(long now){
if(points-- > 0) {
int r = ran.nextInt(3);
midPoint = midPoint.findMidTo(triangle[r]);
gc.fillOval(midPoint.getX(), midPoint.getY(),1,1);
}
}
};
timer.start();
}
public static void main(String[] args) {
launch(args);
}
}
正如评论中所写,输入大小似乎存在某些内在或隐式限制。 private void runEntireImageTest(Mat inY) {
float scaleFactor = 1.0f / 255.0f;
Scalar mean = new Scalar(0);
Mat resized = new Mat();
// (550, 441) runs OK. (smaller sized runs also fine)
// (551, 441), (550, 442) crash.
// (441, 550) crashes
Imgproc.resize(inY, resized, new Size(550, 441));
Mat segBlob = Dnn.blobFromImage(resized, scaleFactor, resized.size(), mean, false, false);
mNet.setInput(segBlob);
// if input size is above some value, crash will happen here
Mat lastLayer = mNet.forward();
Mat outY = lastLayer.reshape(1, 1);
}
运行正常,但是(550, 441)
会导致(551, 441)
:
SIGSEGV
我认为这不是内存问题,因为A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x6d494bd744 in tid 19693 (myappname), pid 19661 (myappname)
运行正常,但是(550, 441)
会崩溃。是什么原因造成的?