Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VisionCW3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ik1g19
VisionCW3
Commits
aa2a4985
Commit
aa2a4985
authored
3 years ago
by
ik1g19
Browse files
Options
Downloads
Patches
Plain Diff
fixed classification
parent
5fd8ed48
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
visioncw3/src/main/java/uk/ac/soton/ecs/ik1g19/App.java
+45
-46
45 additions, 46 deletions
visioncw3/src/main/java/uk/ac/soton/ecs/ik1g19/App.java
visioncw3/src/main/java/uk/ac/soton/ecs/ik1g19/PatchFeature.java
+62
-0
62 additions, 0 deletions
...w3/src/main/java/uk/ac/soton/ecs/ik1g19/PatchFeature.java
with
107 additions
and
46 deletions
visioncw3/src/main/java/uk/ac/soton/ecs/ik1g19/App.java
+
45
−
46
View file @
aa2a4985
...
@@ -12,29 +12,20 @@ import org.openimaj.experiment.evaluation.classification.ClassificationEvaluator
...
@@ -12,29 +12,20 @@ import org.openimaj.experiment.evaluation.classification.ClassificationEvaluator
import
org.openimaj.experiment.evaluation.classification.ClassificationResult
;
import
org.openimaj.experiment.evaluation.classification.ClassificationResult
;
import
org.openimaj.experiment.evaluation.classification.analysers.confusionmatrix.CMAnalyser
;
import
org.openimaj.experiment.evaluation.classification.analysers.confusionmatrix.CMAnalyser
;
import
org.openimaj.experiment.evaluation.classification.analysers.confusionmatrix.CMResult
;
import
org.openimaj.experiment.evaluation.classification.analysers.confusionmatrix.CMResult
;
import
org.openimaj.feature.DoubleFV
;
import
org.openimaj.feature.FeatureExtractor
;
import
org.openimaj.feature.FeatureExtractor
;
import
org.openimaj.feature.FloatFV
;
import
org.openimaj.feature.SparseIntFV
;
import
org.openimaj.feature.SparseIntFV
;
import
org.openimaj.feature.local.LocalFeatureImpl
;
import
org.openimaj.feature.local.Location
;
import
org.openimaj.feature.local.data.LocalFeatureListDataSource
;
import
org.openimaj.feature.local.data.LocalFeatureListDataSource
;
import
org.openimaj.feature.local.list.LocalFeatureList
;
import
org.openimaj.feature.local.list.LocalFeatureList
;
import
org.openimaj.image.DisplayUtilities
;
import
org.openimaj.image.FImage
;
import
org.openimaj.image.FImage
;
import
org.openimaj.image.ImageUtilities
;
import
org.openimaj.image.ImageUtilities
;
import
org.openimaj.image.MBFImage
;
import
org.openimaj.image.annotation.evaluation.datasets.Caltech101
;
import
org.openimaj.image.colour.ColourSpace
;
import
org.openimaj.image.colour.RGBColour
;
import
org.openimaj.image.feature.dense.gradient.dsift.ByteDSIFTKeypoint
;
import
org.openimaj.image.feature.dense.gradient.dsift.DenseSIFT
;
import
org.openimaj.image.feature.dense.gradient.dsift.PyramidDenseSIFT
;
import
org.openimaj.image.feature.local.aggregate.BagOfVisualWords
;
import
org.openimaj.image.feature.local.aggregate.BagOfVisualWords
;
import
org.openimaj.image.feature.local.aggregate.BlockSpatialAggregator
;
import
org.openimaj.image.processing.convolution.FGaussianConvolve
;
import
org.openimaj.image.typography.hershey.HersheyFont
;
import
org.openimaj.ml.annotation.linear.LiblinearAnnotator
;
import
org.openimaj.ml.annotation.linear.LiblinearAnnotator
;
import
org.openimaj.ml.clustering.
Byte
CentroidsResult
;
import
org.openimaj.ml.clustering.
Float
CentroidsResult
;
import
org.openimaj.ml.clustering.assignment.HardAssigner
;
import
org.openimaj.ml.clustering.assignment.HardAssigner
;
import
org.openimaj.ml.clustering.kmeans.
Byte
KMeans
;
import
org.openimaj.ml.clustering.kmeans.
Float
KMeans
;
import
org.openimaj.util.pair.IntFloatPair
;
import
org.openimaj.util.pair.IntFloatPair
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -42,37 +33,45 @@ import java.util.List;
...
@@ -42,37 +33,45 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map
;
/**
/**
* OpenIMAJ Hello world!
* Run #2
*
* Image classification using 15 one-vs-all classifiers
* Trained using densely sampled patches with k-means clustering and visual words
*/
*/
public
class
App
{
public
class
App
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
//creating datasets
GroupedDataset
<
String
,
VFSListDataset
<
FImage
>,
FImage
>
trainingData
;
GroupedDataset
<
String
,
VFSListDataset
<
FImage
>,
FImage
>
trainingData
;
GroupedDataset
<
String
,
VFSListDataset
<
FImage
>
,
FImage
>
testingData
;
VFSListDataset
<
FImage
>
testingData
;
try
{
try
{
trainingData
=
new
VFSGroupDataset
<
FImage
>(
trainingData
=
new
VFSGroupDataset
<
FImage
>(
"zip:C:
\\
Users
\\
isaac
\\
Documents
\\r
epos
\\
visioncw3
\\
visioncw3
\\
data
\\
training"
,
ImageUtilities
.
FIMAGE_READER
);
"zip:C:
/
Users
/
isaac
/
Documents
/GitHub R
epos
/
visioncw3
/
visioncw3
/
data
/
training
.zip
"
,
ImageUtilities
.
FIMAGE_READER
);
testingData
=
new
VFS
Group
Dataset
<
FImage
>(
testingData
=
new
VFS
List
Dataset
<
FImage
>(
"zip:C:
\\
Users
\\
isaac
\\
Documents
\\r
epos
\\
visioncw3
\\
visioncw3
\\
data
\\
testing.zip"
,
ImageUtilities
.
FIMAGE_READER
);
"zip:C:
/
Users
/
isaac
/
Documents
/GitHub R
epos
/
visioncw3
/
visioncw3
/
data
/
testing.zip"
,
ImageUtilities
.
FIMAGE_READER
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
System
.
err
.
println
(
"Training & testing data failed to load"
);
System
.
err
.
println
(
"Training & testing data failed to load"
);
System
.
err
.
println
(
e
);
System
.
err
.
println
(
e
);
return
;
return
;
}
}
trainingData
.
remove
(
"training"
);
GroupedRandomSplitter
<
String
,
FImage
>
splits
=
GroupedRandomSplitter
<
String
,
FImage
>
splits
=
new
GroupedRandomSplitter
<
String
,
FImage
>(
trainingData
,
15
,
0
,
15
);
new
GroupedRandomSplitter
<
String
,
FImage
>(
trainingData
,
80
,
0
,
20
);
DenseSIFT
dsift
=
new
DenseSIFT
(
5
,
7
);
//analyse patches of 8x8 sizes
P
yramidDenseSIFT
<
FImage
>
pdsift
=
new
PyramidDenseSIFT
<
FImage
>(
dsift
,
6
f
,
7
);
P
atchFeature
patch
=
new
PatchFeature
(
8
);
HardAssigner
<
byte
[],
float
[],
IntFloatPair
>
assigner
=
//train quantiser on a sample of the data set
trainQuantiser
(
GroupedUniformRandomisedSampler
.
sample
(
splits
.
getTrainingDataset
(),
30
),
pdsift
);
HardAssigner
<
float
[],
float
[],
IntFloatPair
>
assigner
=
trainQuantiser
(
GroupedUniformRandomisedSampler
.
sample
(
splits
.
getTrainingDataset
(),
30
),
patch
);
FeatureExtractor
<
DoubleFV
,
FImage
>
extractor
=
new
PHOWExtractor
(
pdsift
,
assigner
);
//create a feature extractor to densely sample patches
FeatureExtractor
<
SparseIntFV
,
FImage
>
extractor
=
new
PatchExtractor
(
patch
,
assigner
);
LiblinearAnnotator
<
FImage
,
String
>
ann
=
new
LiblinearAnnotator
<
FImage
,
String
>(
LiblinearAnnotator
<
FImage
,
String
>
ann
=
new
LiblinearAnnotator
<
FImage
,
String
>(
...
@@ -86,50 +85,50 @@ public class App {
...
@@ -86,50 +85,50 @@ public class App {
Map
<
FImage
,
ClassificationResult
<
String
>>
guesses
=
eval
.
evaluate
();
Map
<
FImage
,
ClassificationResult
<
String
>>
guesses
=
eval
.
evaluate
();
CMResult
<
String
>
result
=
eval
.
analyse
(
guesses
);
CMResult
<
String
>
result
=
eval
.
analyse
(
guesses
);
System
.
out
.
println
(
result
.
getDetailReport
());
}
}
static
HardAssigner
<
byte
[],
float
[],
IntFloatPair
>
trainQuantiser
(
Dataset
<
FImage
>
sample
,
PyramidDenseSIFT
<
FImage
>
pdsift
)
static
HardAssigner
<
float
[],
float
[],
IntFloatPair
>
trainQuantiser
(
Dataset
<
FImage
>
sample
,
PatchFeature
<
FImage
>
patch
)
{
{
List
<
LocalFeatureList
<
ByteDSIFTKeypoint
>>
allkeys
=
new
ArrayList
<
LocalFeatureList
<
ByteDSIFTKeypoint
>
>();
List
<
LocalFeatureList
<
LocalFeatureImpl
<
Location
,
FloatFV
>>>
allkeys
=
new
ArrayList
<
>();
for
(
FImage
rec
:
sample
)
{
for
(
FImage
rec
:
sample
)
{
FImage
img
=
rec
;
FImage
img
=
rec
;
p
dsift
.
analyseImage
(
img
);
p
atch
.
analyseImage
(
img
);
allkeys
.
add
(
p
dsift
.
getByte
Keypoints
(
0.005f
));
allkeys
.
add
(
p
atch
.
getPatch
Keypoints
());
}
}
if
(
allkeys
.
size
()
>
10000
)
if
(
allkeys
.
size
()
>
10000
)
allkeys
=
allkeys
.
subList
(
0
,
10000
);
allkeys
=
allkeys
.
subList
(
0
,
10000
);
Byte
KMeans
km
=
Byte
KMeans
.
create
KDTreeEnsemble
(
3
00
);
Float
KMeans
km
=
Float
KMeans
.
create
Exact
(
5
00
);
DataSource
<
byte
[]>
datasource
=
new
LocalFeatureListDataSource
<
ByteDSIFTKeypoint
,
byte
[]>(
allkeys
);
DataSource
<
float
[]>
datasource
=
new
LocalFeatureListDataSource
<
LocalFeatureImpl
<
Location
,
FloatFV
>,
float
[]>(
allkeys
);
Byte
CentroidsResult
result
=
km
.
cluster
(
datasource
);
Float
CentroidsResult
result
=
km
.
cluster
(
datasource
);
return
result
.
defaultHardAssigner
();
return
result
.
defaultHardAssigner
();
}
}
}
}
class
P
HOW
Extractor
implements
FeatureExtractor
<
Double
FV
,
FImage
>
{
class
P
atch
Extractor
implements
FeatureExtractor
<
SparseInt
FV
,
FImage
>
{
P
yramidDenseSIFT
<
FImage
>
p
dsift
;
P
atchFeature
<
FImage
>
p
atch
;
HardAssigner
<
byte
[],
float
[],
IntFloatPair
>
assigner
;
HardAssigner
<
float
[],
float
[],
IntFloatPair
>
assigner
;
public
P
HOW
Extractor
(
P
yramidDenseSIFT
<
FImage
>
p
dsift
,
HardAssigner
<
byte
[],
float
[],
IntFloatPair
>
assigner
)
public
P
atch
Extractor
(
P
atchFeature
<
FImage
>
p
atch
,
HardAssigner
<
float
[],
float
[],
IntFloatPair
>
assigner
)
{
{
this
.
p
dsift
=
pdsift
;
this
.
p
atch
=
patch
;
this
.
assigner
=
assigner
;
this
.
assigner
=
assigner
;
}
}
public
Double
FV
extractFeature
(
FImage
object
)
{
public
SparseInt
FV
extractFeature
(
FImage
object
)
{
FImage
image
=
object
.
getImage
();
FImage
image
=
object
.
getImage
();
pdsift
.
analyseImage
(
image
);
patch
.
analyseImage
(
image
);
BagOfVisualWords
<
byte
[]>
bovw
=
new
BagOfVisualWords
<
byte
[]>(
assigner
);
BlockSpatialAggregator
<
byte
[],
SparseIntFV
>
spatial
=
new
BlockSpatialAggregator
<
byte
[],
SparseIntFV
>(
BagOfVisualWords
<
float
[]>
bovw
=
new
BagOfVisualWords
<>(
assigner
);
bovw
,
2
,
2
);
return
spatial
.
aggregate
(
p
dsift
.
getByteKeypoints
(
0.015f
),
image
.
getBounds
()).
normaliseFV
(
);
return
bovw
.
aggregate
(
p
atch
.
getPatchKeypoints
()
);
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
visioncw3/src/main/java/uk/ac/soton/ecs/ik1g19/PatchFeature.java
0 → 100644
+
62
−
0
View file @
aa2a4985
package
uk.ac.soton.ecs.ik1g19
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Iterator
;
import
java.util.List
;
import
org.openimaj.feature.DoubleFV
;
import
org.openimaj.feature.FloatFV
;
import
org.openimaj.feature.local.LocalFeatureImpl
;
import
org.openimaj.feature.local.Location
;
import
org.openimaj.feature.local.SpatialLocation
;
import
org.openimaj.feature.local.list.LocalFeatureList
;
import
org.openimaj.feature.local.list.MemoryLocalFeatureList
;
import
org.openimaj.image.FImage
;
import
org.openimaj.image.Image
;
import
org.openimaj.image.analyser.ImageAnalyser
;
import
org.openimaj.image.feature.local.keypoints.Keypoint
;
import
org.openimaj.image.pixel.sampling.RectangleSampler
;
import
org.openimaj.image.processing.convolution.FGaussianConvolve
;
import
org.openimaj.image.processor.SinglebandImageProcessor.Processable
;
import
org.openimaj.math.geometry.shape.Rectangle
;
import
org.openimaj.util.array.ArrayUtils
;
import
org.openimaj.util.pair.IntObjectPair
;
public
class
PatchFeature
<
IMAGE
extends
Image
<
Float
,
IMAGE
>
&
Processable
<
Float
,
FImage
,
IMAGE
>>
implements
ImageAnalyser
<
IMAGE
>
{
float
size
;
private
LocalFeatureList
<
LocalFeatureImpl
<
Location
,
FloatFV
>>
patchList
;
public
PatchFeature
(
float
size
)
{
this
.
size
=
size
;
patchList
=
new
MemoryLocalFeatureList
<>();
}
public
void
analyseImage
(
IMAGE
image
)
{
patchList
.
clear
();
RectangleSampler
sampler
=
new
RectangleSampler
(
image
,
4
f
,
4
f
,
size
,
size
);
Iterator
<
Rectangle
>
rects
=
sampler
.
allRectangles
().
iterator
();
while
(
rects
.
hasNext
())
{
Rectangle
rect
=
rects
.
next
();
IMAGE
rImg
=
image
.
extractROI
(
rect
).
normalise
();
Float
[]
pvF
=
new
Float
[
rImg
.
getWidth
()*
rImg
.
getHeight
()];
rImg
.
getPixelVector
(
pvF
);
float
[]
pvf
=
new
float
[
rImg
.
getWidth
()*
rImg
.
getHeight
()];
for
(
int
i
=
0
;
i
<
pvF
.
length
;
i
++)
{
pvf
[
i
]
=
pvF
[
i
].
floatValue
();
}
FloatFV
fv
=
new
FloatFV
(
pvf
);
patchList
.
add
(
new
LocalFeatureImpl
<
Location
,
FloatFV
>(
new
SpatialLocation
(
rect
.
x
,
rect
.
y
),
fv
));
}
}
public
LocalFeatureList
<
LocalFeatureImpl
<
Location
,
FloatFV
>>
getPatchKeypoints
()
{
return
patchList
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment