This repository has been archived by the owner on Dec 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API/ENH: rm main, add time distance scaling
Add tools to read image file's timestamp: Read EXIF tags if possible. Add new dependency piexif. Add `fmt` kwd to tests.ImagedirCtx__init__() -> test png and jpg images. Read EXIF timestamps. Add module exceptions.py, io.py, examples/inria_holiday.sh. Replace most of main's logic (check for existing db files) by io.get_image_data(). Move other IO-related things to io.py. Use timestamps to add time-distance scaling.
- Loading branch information
Showing
13 changed files
with
416 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,42 @@ | ||
#!/usr/bin/python3 | ||
|
||
from imagecluster import calc as ic | ||
from imagecluster import io as icio | ||
from imagecluster import postproc as pp | ||
|
||
# Create image database in memory. This helps to feed images to the NN model | ||
# quickly. | ||
ias = ic.image_arrays('pics/', size=(224,224)) | ||
|
||
# Create Keras NN model. | ||
model = ic.get_model() | ||
|
||
# Feed images through the model and extract fingerprints (feature vectors). | ||
fps = ic.fingerprints(ias, model) | ||
# # Create image database in memory. This helps to feed images to the NN model | ||
# # quickly. | ||
# image_arrays = icio.read_image_arrays('pics/', size=(224,224)) | ||
# | ||
# # Create Keras NN model. | ||
# model = ic.get_model() | ||
# | ||
# # Feed images through the model and extract fingerprints (feature vectors). | ||
# fingerprints = ic.fingerprints(image_arrays, model) | ||
# | ||
# # Optionally run a PCA on the fingerprints to compress the dimensions. Use a | ||
# # cumulative explained variance ratio of 0.95. | ||
# fingerprints = ic.pca(fingerprints, n_components=0.95) | ||
# | ||
# # Read image timestamps. Need that to calculate the time distance, can be used | ||
# # in clustering. | ||
# timestamps = icio.read_timestamps('pics/') | ||
|
||
# Optionally run a PCA on the fingerprints to compress the dimensions. Use a | ||
# cumulative explained variance ratio of 0.95. | ||
fps = ic.pca(fps, n_components=0.95) | ||
# XXX where on disk? add to README | ||
# Convenience function to perform the steps above. Check for existing | ||
# `image_arrays` and `fingerprints` database files on disk and load them if | ||
# present. Running this again only loads data from disk, which is fast. | ||
image_arrays,fingerprints,timestamps = icio.get_image_data( | ||
'pics/', | ||
pca_kwds=dict(n_components=0.95)) | ||
|
||
# Run clustering on the fingerprints. Select clusters with similarity index | ||
# sim=0.5 | ||
clusters = ic.cluster(fps, sim=0.5) | ||
# Run clustering on the fingerprints. Select clusters with similarity index | ||
# sim=0.5. Mix 80% content distance with 20% timestamp distance (alpha=0.2). | ||
clusters = ic.cluster(fingerprints, sim=0.5, timestamps=timestamps, alpha=0.2) | ||
|
||
# Create dirs with links to images. Dirs represent the clusters the images | ||
# belong to. | ||
pp.make_links(clusters, 'pics/imagecluster/clusters') | ||
|
||
# Plot images arranged in clusters. | ||
pp.visualize(clusters, ias) | ||
pp.visualize(clusters, image_arrays) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/sh | ||
|
||
# select 25 images | ||
# ./this.sh jpg/100* | ||
# | ||
# select 274 images | ||
# ./this.sh jpg/10* | ||
|
||
if ! [ -d jpg ]; then | ||
for name in jpg1 jpg2; do | ||
wget ftp://ftp.inrialpes.fr/pub/lear/douze/data/${name}.tar.gz | ||
tar -xzf ${name}.tar.gz | ||
done | ||
fi | ||
|
||
mkdir -p pics | ||
rm -rf pics/* | ||
for x in $@; do | ||
f=$(echo "$x" | sed -re 's|jpg/||') | ||
ln -s $(readlink -f jpg/$f) pics/$f | ||
done | ||
|
||
echo "#images: $(ls pics | wc -l)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.