Shortcuts

TextSnakeModuleLoss

class mmocr.models.textdet.TextSnakeModuleLoss(ohem_ratio=3.0, downsample_ratio=1.0, orientation_thr=2.0, resample_step=4.0, center_region_shrink_ratio=0.3, loss_text={'eps': 1e-05, 'fallback_negative_num': 100, 'type': 'MaskedBalancedBCEWithLogitsLoss'}, loss_center={'type': 'MaskedBCEWithLogitsLoss'}, loss_radius={'type': 'MaskedSmoothL1Loss'}, loss_sin={'type': 'MaskedSmoothL1Loss'}, loss_cos={'type': 'MaskedSmoothL1Loss'})[源代码]

The class for implementing TextSnake loss. This is partially adapted from https://github.com/princewang1994/TextSnake.pytorch.

TextSnake: A Flexible Representation for Detecting Text of Arbitrary Shapes.

参数
  • ohem_ratio (float) – The negative/positive ratio in ohem.

  • downsample_ratio (float) – Downsample ratio. Defaults to 1.0. TODO: remove it.

  • orientation_thr (float) – The threshold for distinguishing between head edge and tail edge among the horizontal and vertical edges of a quadrangle.

  • resample_step (float) – The step of resampling.

  • center_region_shrink_ratio (float) – The shrink ratio of text center.

  • loss_text (dict) – The loss config used to calculate the text loss.

  • loss_center (dict) – The loss config used to calculate the center loss.

  • loss_radius (dict) – The loss config used to calculate the radius loss.

  • loss_sin (dict) – The loss config used to calculate the sin loss.

  • loss_cos (dict) – The loss config used to calculate the cos loss.

返回类型

None

forward(preds, data_samples)[源代码]
参数
  • preds (Tensor) – The prediction map of shape \((N, 5, H, W)\), where each dimension is the map of “text_region”, “center_region”, “sin_map”, “cos_map”, and “radius_map” respectively.

  • data_samples (list[TextDetDataSample]) – The data samples.

返回

A loss dict with loss_text, loss_center, loss_radius, loss_sin and loss_cos.

返回类型

dict

get_targets(data_samples)[源代码]

Generate loss targets from data samples.

参数

data_samples (list(TextDetDataSample)) – Ground truth data samples.

返回

tuple(gt_text_masks, gt_masks, gt_center_region_masks, gt_radius_maps, gt_sin_maps, gt_cos_maps): A tuple of six lists of ndarrays as the targets.

返回类型

Tuple

vector_angle(vec1, vec2)[源代码]

Compute the angle between two vectors.

参数
返回类型

numpy.ndarray

vector_cos(vec)[源代码]

Compute the cos of the angle between vector and x-axis.

参数

vec (numpy.ndarray) –

返回类型

float

vector_sin(vec)[源代码]

Compute the sin of the angle between vector and x-axis.

参数

vec (numpy.ndarray) –

返回类型

float

vector_slope(vec)[源代码]

Compute the slope of a vector.

参数

vec (numpy.ndarray) –

返回类型

float

Read the Docs v: dev-1.x
Versions
latest
stable
0.x
dev-1.x
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.