OBJECT
- Type of object being annotatedANNOTATION
- Type of annotationFEATURE
- Type of feature produced by extractorpublic class KNNAnnotator<OBJECT,ANNOTATION,FEATURE> extends IncrementalAnnotator<OBJECT,ANNOTATION>
ObjectNearestNeighboursExact
to perform the kNN search, so is
applicable to any objects that can be compared with a
DistanceComparator
.Modifier and Type | Field and Description |
---|---|
protected List<Collection<ANNOTATION>> |
annotations |
protected Set<ANNOTATION> |
annotationsSet |
protected DistanceComparator<? super FEATURE> |
comparator |
protected FeatureExtractor<FEATURE,OBJECT> |
extractor |
protected List<FEATURE> |
features |
protected int |
k |
protected ObjectNearestNeighbours<FEATURE> |
nn |
protected float |
threshold |
Constructor and Description |
---|
KNNAnnotator(FeatureExtractor<FEATURE,OBJECT> extractor,
DistanceComparator<? super FEATURE> comparator)
Construct with the given extractor and comparator.
|
KNNAnnotator(FeatureExtractor<FEATURE,OBJECT> extractor,
DistanceComparator<? super FEATURE> comparator,
float threshold)
Construct with the given extractor, comparator and threshold.
|
KNNAnnotator(FeatureExtractor<FEATURE,OBJECT> extractor,
DistanceComparator<? super FEATURE> comparator,
int k)
Construct with the given extractor, comparator and number of neighbours.
|
KNNAnnotator(FeatureExtractor<FEATURE,OBJECT> extractor,
DistanceComparator<? super FEATURE> comparator,
int k,
float threshold)
Construct with the given extractor, comparator, number of neighbours and
threshold.
|
Modifier and Type | Method and Description |
---|---|
List<ScoredAnnotation<ANNOTATION>> |
annotate(OBJECT object)
Generate annotations for the given object.
|
static <OBJECT,ANNOTATION,EXTRACTOR extends FeatureExtractor<FEATURE,OBJECT>,FEATURE> |
create(EXTRACTOR extractor,
DistanceComparator<FEATURE> comparator)
Create a new
KNNAnnotator with the given extractor and
comparator. |
static <OBJECT,ANNOTATION,EXTRACTOR extends FeatureExtractor<FEATURE,OBJECT>,FEATURE> |
create(EXTRACTOR extractor,
DistanceComparator<FEATURE> comparator,
float threshold)
Create a new
KNNAnnotator with the given extractor, comparator
and threshold. |
static <OBJECT,ANNOTATION,EXTRACTOR extends FeatureExtractor<FEATURE,OBJECT>,FEATURE> |
create(EXTRACTOR extractor,
DistanceComparator<FEATURE> comparator,
int k)
Create a new
KNNAnnotator with the given extractor, comparator
and number of neighbours. |
static <OBJECT,ANNOTATION,EXTRACTOR extends FeatureExtractor<FEATURE,OBJECT>,FEATURE> |
create(EXTRACTOR extractor,
DistanceComparator<FEATURE> comparator,
int k,
float threshold)
Create a new
KNNAnnotator with the given extractor, comparator,
number of neighbours and threshold. |
Set<ANNOTATION> |
getAnnotations() |
int |
getK() |
void |
reset()
Reset the object to its initial condition, as if
it hasn't seen any training data.
|
void |
setK(int k)
Set the number of neighbours
|
void |
train(Annotated<OBJECT,ANNOTATION> annotated)
Train/update object using a new instance.
|
train, train, trainMultiClass
classify
protected int k
protected final List<Collection<ANNOTATION>> annotations
protected final Set<ANNOTATION> annotationsSet
protected ObjectNearestNeighbours<FEATURE> nn
protected DistanceComparator<? super FEATURE> comparator
protected final float threshold
protected FeatureExtractor<FEATURE,OBJECT> extractor
public KNNAnnotator(FeatureExtractor<FEATURE,OBJECT> extractor, DistanceComparator<? super FEATURE> comparator, float threshold)
If the comparator defines a distance, then only scores below the distance will be accepted. If the threshold defines a similarity, then only scores above the threshold will be accepted.
extractor
- the extractorcomparator
- the comparatorthreshold
- the threshold for successful matchespublic KNNAnnotator(FeatureExtractor<FEATURE,OBJECT> extractor, DistanceComparator<? super FEATURE> comparator)
extractor
- the extractorcomparator
- the comparatorpublic KNNAnnotator(FeatureExtractor<FEATURE,OBJECT> extractor, DistanceComparator<? super FEATURE> comparator, int k)
extractor
- the extractorcomparator
- the comparatork
- the number of neighbourspublic KNNAnnotator(FeatureExtractor<FEATURE,OBJECT> extractor, DistanceComparator<? super FEATURE> comparator, int k, float threshold)
If the comparator defines a distance, then only scores below the distance will be accepted. If the threshold defines a similarity, then only scores above the threshold will be accepted.
extractor
- the extractorcomparator
- the comparatork
- the number of neighboursthreshold
- the threshold on distance for successful matchespublic static <OBJECT,ANNOTATION,EXTRACTOR extends FeatureExtractor<FEATURE,OBJECT>,FEATURE> KNNAnnotator<OBJECT,ANNOTATION,FEATURE> create(EXTRACTOR extractor, DistanceComparator<FEATURE> comparator, float threshold)
KNNAnnotator
with the given extractor, comparator
and threshold. The number of neighbours is set to 1.
If the comparator defines a distance, then only scores below the distance will be accepted. If the threshold defines a similarity, then only scores above the threshold will be accepted.
OBJECT
- Type of object being annotatedANNOTATION
- Type of annotationEXTRACTOR
- Type of feature extractorFEATURE
- Type of feature produced by extractorextractor
- the extractorcomparator
- the comparatorthreshold
- the threshold for successful matchesKNNAnnotator
public static <OBJECT,ANNOTATION,EXTRACTOR extends FeatureExtractor<FEATURE,OBJECT>,FEATURE> KNNAnnotator<OBJECT,ANNOTATION,FEATURE> create(EXTRACTOR extractor, DistanceComparator<FEATURE> comparator)
KNNAnnotator
with the given extractor and
comparator. The number of neighbours is set to 1. The threshold test is
disabled.OBJECT
- Type of object being annotatedANNOTATION
- Type of annotationEXTRACTOR
- Type of feature extractorFEATURE
- Type of feature produced by extractorextractor
- the extractorcomparator
- the comparatorKNNAnnotator
public static <OBJECT,ANNOTATION,EXTRACTOR extends FeatureExtractor<FEATURE,OBJECT>,FEATURE> KNNAnnotator<OBJECT,ANNOTATION,FEATURE> create(EXTRACTOR extractor, DistanceComparator<FEATURE> comparator, int k)
KNNAnnotator
with the given extractor, comparator
and number of neighbours. The distance threshold is disabled.OBJECT
- Type of object being annotatedANNOTATION
- Type of annotationEXTRACTOR
- Type of feature extractorFEATURE
- Type of feature produced by extractorextractor
- the extractorcomparator
- the comparatork
- the number of neighboursKNNAnnotator
public static <OBJECT,ANNOTATION,EXTRACTOR extends FeatureExtractor<FEATURE,OBJECT>,FEATURE> KNNAnnotator<OBJECT,ANNOTATION,FEATURE> create(EXTRACTOR extractor, DistanceComparator<FEATURE> comparator, int k, float threshold)
KNNAnnotator
with the given extractor, comparator,
number of neighbours and threshold.
If the comparator defines a distance, then only scores below the distance will be accepted. If the threshold defines a similarity, then only scores above the threshold will be accepted.
OBJECT
- Type of object being annotatedANNOTATION
- Type of annotationEXTRACTOR
- Type of feature extractorFEATURE
- Type of feature produced by extractorextractor
- the extractorcomparator
- the comparatork
- the number of neighboursthreshold
- the threshold on distance for successful matchesKNNAnnotator
public void train(Annotated<OBJECT,ANNOTATION> annotated)
IncrementalTrainer
annotated
- instance to train withpublic void reset()
IncrementalTrainer
public Set<ANNOTATION> getAnnotations()
public List<ScoredAnnotation<ANNOTATION>> annotate(OBJECT object)
Annotator
object
- the imagepublic int getK()
public void setK(int k)
k
- the number of neighbours