yeah.

parent 7cc4a5fe
......@@ -93,7 +93,7 @@ int main(int argc, char **argv) {
int res;
FILE* fX, *fL;
parse_args(argc,argv);
learn_model_setup(mi_algo,es_algo,du_algo,lm_algo,lmi_algo);
learn_model_setup(mi_algo,es_algo,du_algo,lm_algo,lmi_algo,0);
fX = fopen(Xname,"r");
set_grid_width(W);
if (!fX) return -1;
......
......@@ -11,13 +11,12 @@ size_t max_coef_weight = 0;
model_init_algorithm_t initialize_dictionary = initialize_dictionary_neighbor;
coeffs_update_algorithm_t coefficients_update = coefficients_update_omp;
//coeffs_update_algorithm_t coefficients_update = coefficients_update_mob;
dict_update_algorithm_t update_dictionary = update_dictionary;
model_learn_algorithm_t learn_model_outer = learn_model_traditional;
model_learn_algorithm_t learn_model_inner = learn_model_traditional;
preview_iter_t preview_iter = preview_none;
model_init_algorithm_t model_init_algorithm_catalog[] = {
static model_init_algorithm_t model_init_algorithm_catalog[] = {
initialize_dictionary_neighbor,
initialize_dictionary_partition,
initialize_dictionary_sdct,
......@@ -31,7 +30,7 @@ model_init_algorithm_t model_init_algorithm_catalog[] = {
0
};
const char* model_init_algorithm_names[] = {
static const char* model_init_algorithm_names[] = {
"Neighbor",
"Partition",
"sign of DCT",
......@@ -45,7 +44,7 @@ const char* model_init_algorithm_names[] = {
0
};
coeffs_update_algorithm_t coeffs_update_algorithm_catalog[] = {
static coeffs_update_algorithm_t coeffs_update_algorithm_catalog[] = {
coefficients_update_omp,
coefficients_update_basic,
coefficients_update_bmp,
......@@ -54,7 +53,7 @@ coeffs_update_algorithm_t coeffs_update_algorithm_catalog[] = {
0
};
const char* coeffs_update_algorithm_names[] = {
static const char* coeffs_update_algorithm_names[] = {
"Basic coefficients update (OpenMP)",
"Basic coefficients update",
"BMP coefficients update",
......@@ -63,20 +62,20 @@ const char* coeffs_update_algorithm_names[] = {
0
};
dict_update_algorithm_t dict_update_algorithm_catalog[] = {update_dictionary_mob,
static dict_update_algorithm_t dict_update_algorithm_catalog[] = {update_dictionary_mob,
update_dictionary_kprox,
update_dictionary_mob_omp,
update_dictionary_kprox_omp,
0
};
const char* dict_update_algorithm_names[] = {"MOB dictionary update",
static const char* dict_update_algorithm_names[] = {"MOB dictionary update",
"KPROX dictionary update",
"MOB dictionary update (OMP)",
"KPROX dictionary update (OMP)",0
};
model_learn_algorithm_t learn_model_algorithm_catalog[] = {learn_model_traditional,
static model_learn_algorithm_t learn_model_algorithm_catalog[] = {learn_model_traditional,
learn_model_alter1,
learn_model_alter2,
learn_model_alter3,
......@@ -85,7 +84,7 @@ model_learn_algorithm_t learn_model_algorithm_catalog[] = {learn_model_tradition
learn_model_mdl_full_search,
0
};
const char* lm_algorithm_names[] = {"Model learning by traditional alternate descent",
static const char* model_learn_algorithm_names[] = {"Model learning by traditional alternate descent",
"Role-switching learning 1: at each iteration, the role of A and D are switched",
"Role-switched learning 2: after convergence, the role of A and D are switched and traditional model is applied again",
"Role switched learning 3: like RS1 but only update_dictionary is applied (for use with Proximus",
......@@ -94,6 +93,12 @@ const char* lm_algorithm_names[] = {"Model learning by traditional alternate des
"MDL/full search"
};
static preview_iter_t preview_iter_catalog[] = {preview_none,
0
};
static const char* preview_iter_names[] = {"None"
};
static int count_options(const char* names[]) {
int n = 0;
while (names[n]) {
......@@ -103,7 +108,7 @@ static int count_options(const char* names[]) {
}
void learn_model_setup(int mi_algo, int es_algo, int du_algo, int lmo_algo, int lmi_algo) {
void learn_model_setup(int mi_algo, int es_algo, int du_algo, int lmo_algo, int lmi_algo, int pv_algo) {
int n;
n = count_options(model_init_algorithm_names);
if (mi_algo > n) {
......@@ -120,12 +125,12 @@ void learn_model_setup(int mi_algo, int es_algo, int du_algo, int lmo_algo, int
std::cerr << "Invalid dictionary update algorithm (0-" << n << ')' << std::endl;
exit(-1);
}
n = count_options(lm_algorithm_names);
n = count_options(model_learn_algorithm_names);
if (lmo_algo > n) {
std::cerr << "Invalid model learning algorithm (0-" << n << ')' << std::endl;
exit(-1);
}
n = count_options(lm_algorithm_names);
n = count_options(model_learn_algorithm_names);
if (lmi_algo > n) {
std::cerr << "Invalid inner model learning algorithm (0-" << n << ')' << std::endl;
exit(-1);
......@@ -138,14 +143,24 @@ void learn_model_setup(int mi_algo, int es_algo, int du_algo, int lmo_algo, int
std::cout << "Initialize dictionary from existing file." << std::endl;
initialize_dictionary = initialize_dictionary_dummy;
}
n = count_options(preview_iter_names);
if (pv_algo > n) {
std::cerr << "Invalid preview algorithm (0-" << n << ')' << std::endl;
exit(-1);
}
coefficients_update = coeffs_update_algorithm_catalog[es_algo];
std::cout << "Using " << coeffs_update_algorithm_names[es_algo] << " for coefficients update." << std::endl;
update_dictionary = dict_update_algorithm_catalog[du_algo];
std::cout << "Using " << dict_update_algorithm_names[du_algo] << " for dictionary update." << std::endl;
learn_model_outer = learn_model_algorithm_catalog[lmo_algo];
std::cout << "Using " << lm_algorithm_names[lmo_algo] << " for outer learning loop." << std::endl;
std::cout << "Using " << model_learn_algorithm_names[lmo_algo] << " for outer learning loop." << std::endl;
learn_model_inner = learn_model_algorithm_catalog[lmi_algo];
std::cout << "Using " << lm_algorithm_names[lmi_algo] << " for inner learning." << std::endl;
std::cout << "Using " << model_learn_algorithm_names[lmi_algo] << " for inner learning." << std::endl;
preview_iter = preview_iter_catalog[pv_algo];
std::cout << "Using " << preview_iter_names[pv_algo] << " for model initialization." << std::endl;
}
void set_max_err_weight(size_t _me) {
......@@ -161,3 +176,38 @@ size_t get_max_err_weight() {
size_t get_max_coef_weight() {
return max_coef_weight;
}
void list_choices(const char* prefix, const char* opts[]) {
size_t i = 0;
while (opts[i]) {
std::cout << prefix << i << " -> " << opts[i] << std::endl;
i++;
}
}
void show_help(const char* pname) {
std::cout << "USAGE: " << pname << " [options] <data_file> [mask file]" << std::endl;
std::cout << "where [options can be any combination of: " << std::endl;
std::cout << "\t-i initialization algorithm/matrix. A file name indicates a matrrix.\n\tA number indicates one of the following algorithms:" << std::endl;
list_choices("\t\t",model_init_algorithm_names);
std::cout << "\t-c coefficients update algorithm. Choices are:" << std::endl;
list_choices("\t\t",coeffs_update_algorithm_names);
std::cout << "\t-d dictionary update algorithm. Choices are:" << std::endl;
list_choices("\t\t",dict_update_algorithm_names);
std::cout << "\t-l model selection algorithm. Choices are:" << std::endl;
list_choices("\t\t",model_learn_algorithm_names);
std::cout << "\t-L model learning algorithm. Choices are:" << std::endl;
list_choices("\t\t",model_learn_algorithm_names);
std::cout << "\t-w patch width, for patch-based image analysis." << std::endl;
std::cout << "\t-s patch stride, for patch-based image analysis." << std::endl;
std::cout << "\t-k initial model size/rank" << std::endl;
std::cout << "\t-K max. model size/rank" << std::endl;
std::cout << "\t-r random number generator seed (int)" << std::endl;
std::cout << "\t-I model size/rank (bool)" << std::endl;
std::cout << "\t-m force generation of atom mosaic image (bool)." << std::endl;
std::cout << "\t-M force generation of residual samples mosaic image (bool)." << std::endl;
std::cout << "\t-v increase verbosity." << std::endl;
std::cout << "\t-V select preview algorithm." << std::endl;
std::cout << "\t-h show this message." << std::endl;
}
......@@ -44,14 +44,12 @@ extern model_learn_algorithm_t learn_model_outer;
extern model_learn_algorithm_t learn_model_inner;
extern preview_iter_t preview_iter;
extern const char* model_init_algorithm_names[];
extern const char* coeffs_update_algorithm_names[];
extern const char* dict_update_algorithm_names[];
extern const char* lm_algorithm_names[];
void learn_model_setup(int mi_algo, int es_algo, int du_algo, int lm_algo, int lmi_algo, int pv_algo);
void learn_model_setup(int mi_algo, int es_algo, int du_algo, int lm_algo, int lmi_algo);
void list_choices(const char* prefix, const char* opts[]);
void show_help(const char* pname);
void set_max_err_weight(size_t _me);
void set_max_coef_weight(size_t _ma);
......
......@@ -37,28 +37,11 @@ const char* dname = 0;
const char* oname = "denoised.pbm";
double error_probability = 0.1;
void list_choices(const char* prefix, const char* opts[]) {
size_t i = 0;
while (opts[i]) {
std::cout << prefix << i << " -> " << opts[i] << std::endl;
i++;
}
}
void show_help(const char* pname) {
void show_denoising_help(const char* pname) {
show_help(pname);
std::cout << "USAGE: " << pname << " [options] <data_file>" << std::endl;
std::cout << "where [options can be any combination of: " << std::endl;
std::cout << "\t-i initialization algorithm. Choices are:" << std::endl;
list_choices("\t\t",model_init_algorithm_names);
std::cout << "\t-c coefficients update algorithm. Choices are:" << std::endl;
list_choices("\t\t",coeffs_update_algorithm_names);
std::cout << "\t-d dictionary update algorithm. Choices are:" << std::endl;
list_choices("\t\t",dict_update_algorithm_names);
std::cout << "\t-l model selection algorithm. Choices are:" << std::endl;
list_choices("\t\t",lm_algorithm_names);
std::cout << "\t-L model learning algorithm. Choices are:" << std::endl;
list_choices("\t\t",lm_algorithm_names);
std::cout << "\t-w patch width, for image analysis." << std::endl;
std::cout << "\t-k model size/rank (bool" << std::endl;
std::cout << "\t-r random number generator seed (int)" << std::endl;
......@@ -136,7 +119,7 @@ int main(int argc, char **argv) {
idx_t rows,cols;
FILE* file;
parse_args(argc,argv);
learn_model_setup(mi_algo,es_algo,du_algo,lm_algo,lmi_algo);
learn_model_setup(mi_algo,es_algo,du_algo,lm_algo,lmi_algo,0);
file = fopen(iname,"r");
if (!file) return -1;
int res = read_pbm_header(file,rows,cols);
......
......@@ -93,7 +93,7 @@ void parse_args(int argc, char **argv) {
int main(int argc, char **argv) {
idx_t rows,cols;
parse_args(argc,argv);
learn_model_setup(mi_algo,es_algo,du_algo,lm_algo,lmi_algo);
learn_model_setup(mi_algo,es_algo,du_algo,lm_algo,lmi_algo,0);
FILE* file = fopen(iname,"r");
if (!file) return -1;
int res = read_pbm_header(file,rows,cols);
......
......@@ -19,6 +19,7 @@ int es_algo = 2; // default now is BMP
int du_algo = 0;
int lm_algo = 0;
int lmi_algo = 0;
int pv_algo = 0;
idx_t W = 16;
idx_t stride = 0;
......@@ -32,39 +33,6 @@ const char* iname = "";
const char* mname = "";
const char* dname = 0;
void list_choices(const char* prefix, const char* opts[]) {
size_t i = 0;
while (opts[i]) {
std::cout << prefix << i << " -> " << opts[i] << std::endl;
i++;
}
}
void show_help(const char* pname) {
std::cout << "USAGE: " << pname << " [options] <data_file> [mask file]" << std::endl;
std::cout << "where [options can be any combination of: " << std::endl;
std::cout << "\t-i initialization algorithm/matrix. A file name indicates a matrrix.\n\tA number indicates one of the following algorithms:" << std::endl;
list_choices("\t\t",model_init_algorithm_names);
std::cout << "\t-c coefficients update algorithm. Choices are:" << std::endl;
list_choices("\t\t",coeffs_update_algorithm_names);
std::cout << "\t-d dictionary update algorithm. Choices are:" << std::endl;
list_choices("\t\t",dict_update_algorithm_names);
std::cout << "\t-l model selection algorithm. Choices are:" << std::endl;
list_choices("\t\t",lm_algorithm_names);
std::cout << "\t-L model learning algorithm. Choices are:" << std::endl;
list_choices("\t\t",lm_algorithm_names);
std::cout << "\t-w patch width, for patch-based image analysis." << std::endl;
std::cout << "\t-s patch stride, for patch-based image analysis." << std::endl;
std::cout << "\t-k initial model size/rank" << std::endl;
std::cout << "\t-K max. model size/rank" << std::endl;
std::cout << "\t-r random number generator seed (int)" << std::endl;
std::cout << "\t-I model size/rank (bool)" << std::endl;
std::cout << "\t-m force generation of atom mosaic image (bool)." << std::endl;
std::cout << "\t-M force generation of residual samples mosaic image (bool)." << std::endl;
std::cout << "\t-v increase verbosity." << std::endl;
std::cout << "\t-h show this message." << std::endl;
}
void parse_args(int argc, char **argv) {
for (int i = 1; i < argc; ++i) {
......@@ -129,6 +97,9 @@ void parse_args(int argc, char **argv) {
case 'M':
force_residual_mosaic = (atoi(val) > 0);
break;
case 'V':
pv_algo = atoi(val);
break;
default:
std::cerr << "Invalid option " << argv[i] << std::endl;
exit(-1);
......@@ -245,7 +216,7 @@ int main(int argc, char **argv) {
// set up different aspects of learning algorithm
// the overall algorithm delegates parts to other algorithms.
//
learn_model_setup(mi_algo,es_algo,du_algo,lm_algo,lmi_algo);
learn_model_setup(mi_algo,es_algo,du_algo,lm_algo,lmi_algo,pv_algo);
//
// initialize model
//
......
......@@ -21,7 +21,7 @@ const char* oname = "res/einstein_patches.pbm";
void parse_args(int argc, char **argv) {
if (argc < 4) {
std::cerr << "USAGE: " << argv[0] << " image.pbm patch_width stride patches.pbm" << std::endl;
exit(-1);
exit(1);
}
iname = argv[1];
W = atoi(argv[2]);
......@@ -36,22 +36,33 @@ int main(int argc, char **argv) {
// input data
//
idx_t rows,cols;
int res;
int res= 0;
FILE* fimg;
fimg = fopen(iname,"r");
if (!fimg) return -1;
if (!fimg) {
std::cerr << "Error " << res << " while opening image " << iname << std::endl;
return -1;
}
res = read_pbm_header(fimg,rows,cols);
if (res !=PBM_OK) {
std::cerr << "Error " << res << " reading image header." << std::endl;
std::exit(1);
}
std::cout << "Input: " << iname << " rows=" << rows << " cols=" << cols << std::endl;
std::cout << "Parameters: width=" << W << " stride=" << s << std::endl;
binary_matrix I(rows,cols);
read_pbm_data(fimg,I);
res = read_pbm_data(fimg,I);
if (res !=PBM_OK) {
std::cerr << "Error " << res << " reading image." << std::endl;
std::cerr << "Error " << res << " reading image data." << std::endl;
std::exit(1);
}
fclose(fimg);
binary_matrix X;
if ((W > rows) || (W > cols)) {
std::cerr << "Error: patch size " << W << " does not fit in image " << std::endl;
exit(2);
}
const idx_t Ny = compute_grid_size(rows,W,s,EXTRACT_EXACT);
const idx_t Nx = compute_grid_size(cols,W,s,EXTRACT_EXACT);
const idx_t M = W*W;
......
......@@ -12,9 +12,11 @@ const char* ofname;
int main(int argc, char** argv) {
idx_t rows,cols;
int res;
FILE* fi, *fo;
if (argc < 2) {
std::cerr << "Wrong number of parameters.\n Usage: mosaic_tool <dict.pbm> [mosaic.pbm] [ncols]" << std::endl;
exit(1);
}
ifname = argv[1];
if (argc >= 3)
......@@ -27,11 +29,16 @@ int main(int argc, char** argv) {
fi = fopen(ifname,"r");
if (!fi) {
std::cerr << "Error opening " << ifname << " for reading." << std::endl;
return -1;
exit(1);
}
res = read_pbm_header(fi,rows,cols);
if (res != PBM_OK) {
std::cerr << "Error reading PBM header: " << res << std::endl;
exit(1);
}
read_pbm_header(fi,rows,cols);
std::cout << "rows=" << rows << " cols=" << cols << std::endl;
std::cout << "mosaic cols=" << gn << std::endl;
std::cout << "pepe" << std::endl;
binary_matrix D(rows,cols);
read_pbm_data(fi,D);
......@@ -39,4 +46,5 @@ int main(int argc, char** argv) {
render_mosaic(D,ofname,gm,gn);
D.destroy();
return 0;
}
/**
* \file stack_matrices.cpp
* \brief Reads a bunch of matrices and concatenates them together into a single output matrix
* with fixed name 'stacked.pbm'.
*
* Note that this may not be a valid PBM file if the final
* length is larger than the standard permits, but it will still be read by the tools in this
* package.
*/
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include "bmf_util.h"
#include "binmat.h"
#include "pbm.h"
#include "binimage.h"
idx_t W = 16;
idx_t s = 1;
const char* iname;
const char* oname = "stacked.pbm";
void parse_args(int argc, char **argv) {
if (argc < 2) {
std::cerr << "USAGE: " << argv[0] << " file1.pbm file2.pbm ..." << std::endl;
exit(1);
}
}
int main(int argc, char **argv) {
parse_args(argc,argv);
//
// scan matrices
//
idx_t total_rows = 0 ,total_cols = 0;
int res = 0;
FILE* fimg;
for (int i = 1; i < argc; i++) {
iname = argv[i];
fimg = fopen(iname,"r");
if (!fimg) {
std::cerr << "Error " << res << " while opening image " << iname << std::endl;
return -1;
}
idx_t rows,cols;
res = read_pbm_header(fimg,rows,cols);
if (res !=PBM_OK) {
std::cerr << "Error " << res << " reading image header." << std::endl;
std::exit(1);
}
fclose(fimg);
if (total_cols == 0) {
total_cols = cols;
} else if (cols != total_cols) {
std::cerr << "All matrices must have the same number of columns, but matrix " <<iname << " has " << cols << " != " << total_cols << std::endl;
std::exit(1);
}
total_rows += rows;
}
//
// allocate output
//
std::cout << "OUTPUT: " << oname << " rows=" << total_rows << " cols=" << total_cols << std::endl;
//
// fill in data
//
binary_matrix X;
X.allocate(total_rows,total_cols);
idx_t row_offset = 0;
for (int i = 1; i < argc; i++) {
binary_matrix Xi;
iname = argv[i];
fimg = fopen(iname,"r");
idx_t rows,cols;
res = read_pbm_header(fimg,rows,cols);
Xi.allocate(rows,cols);
res = read_pbm_data(fimg,Xi);
fclose(fimg);
if (res !=PBM_OK) {
std::cerr << "Error " << res << " reading image " << iname << " data." << std::endl;
std::exit(1);
}
X.set_submatrix(row_offset,0,Xi);
row_offset += rows;
Xi.destroy();
}
write_pbm(X,oname);
X.destroy();
return 0;
}
#!/bin/bash
# originally from http://www.hagsc.org/hgdp/
wget -c http://iie.fing.edu.uy/~nacho/data/vatican_pbm.7z
mkdir vatican
cd vatican
7zr x ../vatican_pbm.7z
cd ..
#!/bin/bash
make -C code -j 4
outdir="results/vatican-mob"
mkdir -p ${outdir}
time code/bmf_learn_tool -i 1 -l 4 -k 10 -m 1 $* data/vatican/word_patches_stacked.pbm | tee ${ouitdir}.log
mv *pbm ${outdir}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment