mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-06 05:16:40 +08:00
Add input data shape test to avoid out of memory Jacobians
This commit is contained in:
@@ -3,6 +3,11 @@ import numpy as np
|
||||
from scipy import optimize
|
||||
|
||||
|
||||
def _check_data_dim(data, dim):
|
||||
if data.ndim != 2 or data.shape[1] != dim:
|
||||
raise ValueError('Input data must have shape (N, %d).' % dim)
|
||||
|
||||
|
||||
class BaseModel(object):
|
||||
|
||||
def __init__(self):
|
||||
@@ -42,6 +47,8 @@ class LineModel(BaseModel):
|
||||
|
||||
'''
|
||||
|
||||
_check_data_dim(data, dim=2)
|
||||
|
||||
X0 = data.mean(axis=0)
|
||||
|
||||
if data.shape[0] == 2: # well determined
|
||||
@@ -78,6 +85,8 @@ class LineModel(BaseModel):
|
||||
|
||||
'''
|
||||
|
||||
_check_data_dim(data, dim=2)
|
||||
|
||||
dist, theta = self._params
|
||||
|
||||
x = data[:, 0]
|
||||
@@ -179,6 +188,8 @@ class CircleModel(BaseModel):
|
||||
|
||||
'''
|
||||
|
||||
_check_data_dim(data, dim=2)
|
||||
|
||||
x = data[:, 0]
|
||||
y = data[:, 1]
|
||||
# pre-allocate jacobian for all iterations
|
||||
@@ -226,6 +237,8 @@ class CircleModel(BaseModel):
|
||||
|
||||
'''
|
||||
|
||||
_check_data_dim(data, dim=2)
|
||||
|
||||
xc, yc, r = self._params
|
||||
|
||||
x = data[:, 0]
|
||||
@@ -319,6 +332,8 @@ class EllipseModel(BaseModel):
|
||||
|
||||
'''
|
||||
|
||||
_check_data_dim(data, dim=2)
|
||||
|
||||
x = data[:, 0]
|
||||
y = data[:, 1]
|
||||
|
||||
@@ -392,6 +407,8 @@ class EllipseModel(BaseModel):
|
||||
|
||||
'''
|
||||
|
||||
_check_data_dim(data, dim=2)
|
||||
|
||||
xc, yc, a, b, theta = self._params
|
||||
|
||||
ctheta = math.cos(theta)
|
||||
|
||||
Reference in New Issue
Block a user