pascal_dataset<Tdata>::pascal_dataset(const char *name_, const char *inroot_, bool ignore_diff, bool ignore_trunc, bool ignore_occl, const char *annotations, const char *ignore_path, bool ignore_bb) : dataset<Tdata>(name_, inroot_), min_aspect_ratio(-1), max_aspect_ratio(-1), minborders(), max_jitter_match(1.0) { // initialize pascal-specific members // if (inroot_) { // annroot = inroot; // annroot += "/Annotations/"; // look for xml files in annotations // imgroot = inroot; // imgroot += "JPEGImages/"; // image directory // } imgroot = inroot; if (annotations && strcmp(annotations, "")) annroot = annotations; else eblerror("expected annotations folder, please specify with -annotations"); if (ignore_path && strcmp(ignore_path, "")) ignore_root = ignore_path; ignore_difficult = ignore_diff; ignore_bbox = ignore_bb; ignore_truncated = ignore_trunc; ignore_occluded = ignore_occl; #ifndef __XML__ // return error if xml not enabled eblerror("XML libraries not available, install libxml++ and recompile"); #endif /* __XML__ */ extension = XML_PATTERN; std::cout << "Image search extension pattern: " << extension << std::endl; }
bool pascal_dataset<Tdata>::extract() { #ifdef __BOOST__ #ifdef __XML__ if (!allocated && !strcmp(save_mode.c_str(), DATASET_SAVE)) return false; std::cout << "Extracting samples from PASCAL files into dataset..." << std::endl; // adding data to dataset using all xml files in annroot boost::filesystem::path p(annroot); if (!exists(p)) eblerror("Annotation path " << annroot << " does not exist."); xtimer.start(); processed_cnt = 0; // find all xml files recursively std::list<std::string> *files = find_fullfiles(annroot, XML_PATTERN, NULL, true, true); if (!files || files->size() == 0) eblerror("no xml files found in " << annroot << " using file pattern " << XML_PATTERN); std::cout << "Found " << files->size() << " xml files." << std::endl; for (std::list<std::string>::iterator i = files->begin(); i != files->end(); ++i) { this->process_xml(*i); processed_cnt++; if (full()) break; } std::cout << "Extracted " << data_cnt << " elements into dataset." << std::endl; std::cout << "Extraction time: " << xtimer.elapsed() << std::endl; print_stats(); if (files) delete files; #endif /* __XML__ */ #endif /* __BOOST__ */ return true; }
camera_directory<Tdata>::camera_directory(const char *dir, int height_, int width_, bool randomize_, uint npasses_, std::ostream &o, std::ostream &e, const char *pattern, const std::list<std::string> *files) : camera<Tdata>(height_, width_, o, e), indir(dir), randomize(randomize_), npasses(npasses_), file_pattern(pattern) { if (npasses == 0) eblerror("number of passes must be >= 1"); out << "Initializing directory camera from: " << dir << std::endl; fl = NULL; if (files && files->size() > 0) // file names specified by hand { // build list and check each file exists fl = new files_list; for (std::list<std::string>::const_iterator i = files->begin(); i != files->end(); ++i) { std::string fullname; fullname << dir << "/" << *i; if (file_exists(fullname)) { fl->push_back(stringpair(std::string(dir), *i)); } else e << "warning: file not found: " << fullname << std::endl; } if (fl->size() == 0) { err << "warning: No images in image list were found: " << *files << std::endl; err << "Looking for other images..." << std::endl; if (!read_directory(dir)) eblerror("No images found in " << dir); } } else // search all files matching pattern { if (!read_directory(dir)) eblerror("No images found in " << dir); } std::cout << "Found " << fl->size() << " images in " << indir << std::endl; if (randomize) out << "Image list is randomized." << std::endl; if (npasses > 1) out << "Image list will be used " << npasses << " times." << std::endl; flsize = fl->size() * npasses; fli = fl->begin(); // initialize iterator to beginning }
void camera_directory<Tdata>::next() { if (empty()) eblerror("cannot grab images on empty list"); fdir = fli->first; // directory fname = fli->second; // file name frame_name_ = fname; if (fdir.size() > indir.size()) { subdir = fdir.substr(indir.size()); frame_name_ = ""; frame_name_ << subdir << "/" << fname; } //std::cout << "fname: " << fname << " fdir: " << fdir << " subdir: " // << subdir << std::endl; // ostringstream fn(""); if (fdir[fdir.length() - 1] != '/') fdir += "/"; // if (strcmp(fdir.c_str(), "")) // fn << fdir; // fn << fname; // << "_" << frame_id_; // frame_name_ = fn.str(); // if (strcmp(fdir.c_str(), "")) { // size_t npos = frame_name_.length() - fdir.length(); // frame_name_ = frame_name_.substr(fdir.length(), npos); // } // for (size_t i = 0; i < frame_name_.length(); ++i) // if (frame_name_[i] == '/') // frame_name_[i] = '_'; fli++; // move to next element frame_id_++; }
forget_param_linear::forget_param_linear(double v, double e) { value = v; exponent = e; if (e == 0) eblerror("Cannot use an exponent of 0 in forget param"); }
IplImage* idx_to_iplptr(idx<ubyte> &im) { idx_check_contiguous1(im); // im must be contiguous idx_checkorder1(im, 3); // im must have order 3 if (im.dim(2) != 1 && im.dim(2) != 3) { cerr << "idx dimensions are: " << im << endl; eblerror("expecting an image with 1 or 3 channels"); } IplImage *ipl = new IplImage(); ipl->nSize = sizeof(IplImage); ipl->ID = 0; ipl->nChannels = im.dim(2); ipl->alphaChannel = 0; ipl->depth = IPL_DEPTH_8U; // ipl->colorModel = "GRAY"; // ipl->channelSeq = "GRAY"; ipl->dataOrder = 0; // 0: interleaved color ipl->origin = 0; // 0: top-left origin ipl->align = 4; ipl->width = im.dim(1); ipl->height = im.dim(0); ipl->roi = NULL; ipl->maskROI = NULL; ipl->imageId = NULL; ipl->tileInfo = NULL; ipl->imageSize = im.nelements(); ipl->imageData = (char *) im.idx_ptr(); ipl->widthStep = im.dim(1) * im.dim(2); ipl->imageDataOrigin = NULL; return ipl; }
cuda_tanh_module<T,Tstate>::cuda_tanh_module(const char *name_, int gpu_id_) : tanh_module<T,Tstate>(name_), gpu_id(gpu_id_) { this->_name << "_cuda"; // check precision to decide if we use CUDA or not fstate_idx<float> *cont = dynamic_cast<fstate_idx<float>*>(&temp); if (!cont) eblerror("cuda_tanh_module needs float precision"); }
idx<T> image_region_to_rect(idx<T> &im, const rect<int> &r, uint oheight, uint owidth, rect<int> *cropped, uint dh, uint dw) { // TODO: check that rectangle is within image if (im.order() != 2 && im.order() != 3) eblerror("expected a 2d or 3d input but got " << im); idxdim d(im); d.setdim(dh, oheight); d.setdim(dw, owidth); idx<T> res(d); float hcenter = r.h0 + (float)r.height / 2; // input height center float wcenter = r.w0 + (float)r.width / 2; // input width center // // limit centers to half the width/height away from borders // // to handle incorrect regions // hcenter = MIN((float)im.dim(dh) - (float)r.height/2, // std::max((float)r.height/2, hcenter)); // wcenter = MIN((float)im.dim(dw) - (float)r.width/2, // std::max((float)r.width/2, wcenter)); float h0 = hcenter - (float)oheight / 2; // out height offset in input float w0 = wcenter - (float)owidth / 2; // out width offset in input float h1 = hcenter + (float)oheight / 2; float w1 = wcenter + (float)owidth / 2; int gh0 = (int)std::max(0, (int)MIN(im.dim(dh), h0)); // input h offset int gw0 = (int)std::max(0, (int)MIN(im.dim(dw), w0)); // input w offset int gh1 = (int)std::max(0, (int)MIN(im.dim(dh), h1)); int gw1 = (int)std::max(0, (int)MIN(im.dim(dw), w1)); int h = gh1 - gh0 + std::max(0, -r.h0); // out height narrow int w = gw1 - gw0 + std::max(0, -r.w0); // out width narrow int fh0 = (int)std::max(0, (int)(gh0 - h0)); // out height offset narrow int fw0 = (int)std::max(0, (int)(gw0 - w0)); // out width offset narrow // narrow original image int hmin = std::max(0, std::min((int)res.dim(dh) - fh0, std::min((int)im.dim(dh) - gh0, h))); int wmin = std::max(0, std::min((int)res.dim(dw) - fw0, std::min((int)im.dim(dw) - gw0, w))); // clear result image idx_clear(res); if (hmin != 0 && wmin != 0) // only copy if overlap with image { idx<T> tmpim = im.narrow(dh, hmin, gh0); tmpim = tmpim.narrow(dw, wmin, gw0); // narrow target image idx<T> tmpres = res.narrow(dh, hmin, fh0); tmpres = tmpres.narrow(dw, wmin, fw0); // copy original to target idx_copy(tmpim, tmpres); } // set cropped rectangle to region in the output image containing input if (cropped) { cropped->h0 = fh0; cropped->w0 = fw0; cropped->height = hmin; cropped->width = wmin; } return res; }
void load_dataset1(string &ds_name, string &data_fname) { string labels_fname; build_fname(ds_name, LABELS_NAME, labels_fname); // determine label type switch (get_matrix_type(labels_fname.c_str())) { case MAGIC_BYTE_MATRIX: case MAGIC_UBYTE_VINCENT: load_dataset2<Tdata, ubyte>(ds_name, data_fname, labels_fname); break ; case MAGIC_INTEGER_MATRIX: case MAGIC_INT_VINCENT: load_dataset2<Tdata, int>(ds_name, data_fname, labels_fname); break ; case MAGIC_FLOAT_MATRIX: case MAGIC_FLOAT_VINCENT: load_dataset2<Tdata, float>(ds_name, data_fname, labels_fname); break ; case MAGIC_DOUBLE_MATRIX: case MAGIC_DOUBLE_VINCENT: load_dataset2<Tdata, double>(ds_name, data_fname, labels_fname); break ; case MAGIC_LONG_MATRIX: load_dataset2<Tdata, long>(ds_name, data_fname, labels_fname); break ; case MAGIC_UINT_MATRIX: load_dataset2<Tdata, uint>(ds_name, data_fname, labels_fname); break ; default: eblerror("unknown magic number in label matrix"); } }
T limits<T>::min() { #ifdef __NOSTL__ eblerror("limits::min not implemented for this type"); #else return (std::numeric_limits<T>::min)(); #endif }
uint mpijob_manager::world_size() { #ifdef __MPI__ return world.size(); #else eblerror("not implemented"); return 0; #endif }
void camera_v4l2<Tdata>::print_controls() { cout << "__V4l2 camera controls___________________________________" << endl; struct v4l2_queryctrl queryctrl; struct v4l2_querymenu querymenu; memset (&queryctrl, 0, sizeof (queryctrl)); for (queryctrl.id = V4L2_CID_BASE; queryctrl.id < V4L2_CID_LASTP1; queryctrl.id++) { if (0 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) { if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) continue; cout << queryctrl.name << " (" << queryctrl.id << "): " << get_control(queryctrl.id) << endl; if (queryctrl.type == V4L2_CTRL_TYPE_MENU) enumerate_menu (fd, queryctrl, querymenu); } else { if (errno == EINVAL) continue; eblerror ("VIDIOC_QUERYCTRL"); } } for (queryctrl.id = V4L2_CID_PRIVATE_BASE;; queryctrl.id++) { if (0 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) { if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) continue; printf ("Control %s\n", queryctrl.name); if (queryctrl.type == V4L2_CTRL_TYPE_MENU) enumerate_menu (fd, queryctrl, querymenu); } else { if (errno == EINVAL) break; eblerror ("VIDIOC_QUERYCTRL"); } } cout << "_________________________________________________________" << endl; }
camera_directory<Tdata>::camera_directory(int height_, int width_, bool randomize_, uint npasses_, std::ostream &o, std::ostream &e, const char *pattern) : camera<Tdata>(height_, width_, o, e), randomize(randomize_), npasses(npasses_), file_pattern(pattern) { if (npasses == 0) eblerror("number of passes must be >= 1"); }
: camera<Tdata>(height_, width_) { #ifdef __WINDOWS__ bmpData = '\0'; pbmi = NULL; BitmapSize = 0; cap.Initialize(); #else eblerror("cannot use camera_windows when not under Windows"); #endif }
idxlooper<T>::idxlooper(idx<T> &m, int ld) : idx<T>((dummyt*)0) { if (m.order() == 0) // TODO: allow looping once on 0-order idx eblerror("cannot loop on idx with order 0. idx is: " << m); i = 0; dimd = m.spec.dim[ld]; modd = m.spec.mod[ld]; m.spec.select_into(&(this->spec), ld, i); this->storage = m.storage; this->storage->lock(); }
line3d::line3d(float x_, float y_, float z_, float x1_, float y1_, float z1_, int r, int g, int b, int a) : x(x_), y(y_), z(z_), x1(x1_), y1(y1_), z1(z1_), node(NULL), col(r, g, b, a) { QGLBuilder builder; builder.addPane(1); node = builder.finalizedSceneNode(); node->setDrawingMode(QGL::Lines); //EDEBUG("win3d added: " << describe()); eblerror("not implemented"); }
void mpijob::run() { #ifndef __WINDOWS__ // no forking, call child serially directly _started = true; _alive = true; declare_started(); run_child(); //t.stop(); #else eblerror("not implemented"); #endif }
void image_paste_center(idx<T> &in, idx<T> &out) { if (in.order() != 3 || out.order() != 3) eblerror("expected 3d idx but got " << in << " and " << out); int d0 = 1; int d1 = d0 + 1; intg ci = in.dim(d0) - out.dim(d0); intg cj = in.dim(d1) - out.dim(d1); intg xci = (int) (ci / 2); intg xcj = (int) (cj / 2); idx<T> i = in.narrow(d0, out.dim(d0), xci); i = i.narrow(d1, out.dim(d1), xcj); idx_copy(i, out); }
void camera_v4l2<Tdata>::set_boolean_control(int id, bool val) { struct v4l2_control control; memset (&control, 0, sizeof (control)); control.id = id; if (0 == ioctl (fd, VIDIOC_G_CTRL, &control)) { control.value += 1; /* The driver may clamp the value or return ERANGE, ignored here */ if (-1 == ioctl (fd, VIDIOC_S_CTRL, &control) && errno != ERANGE) { eblerror ("VIDIOC_S_CTRL"); } /* Ignore if V4L2_CID_CONTRAST is unsupported */ } else if (errno != EINVAL) { eblerror ("VIDIOC_G_CTRL"); exit (EXIT_FAILURE); } control.id = id; control.value = val; /* Errors ignored */ ioctl (fd, VIDIOC_S_CTRL, &control); }
mpijob_manager::mpijob_manager(int argc, char **argv) #ifdef __MPI__ : env(argc, argv) #endif { #ifndef __MPI__ eblerror("MPI was not found during compilation, install and recompile"); #else rank = world.rank(); jslots = world.size() - 1; // number of available cpus, excluding master id_running = -1; // no job running intially #endif }
void camera_v4l2<Tdata>::set_integer_control(int id, int val) { struct v4l2_queryctrl queryctrl; struct v4l2_control control; memset (&queryctrl, 0, sizeof (queryctrl)); queryctrl.id = id; if (-1 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) { if (errno != EINVAL) { eblerror("VIDIOC_QUERYCTRL"); } else { printf ("V4L2_CID_BRIGHTNESS is not supported\n"); } } else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) { printf ("V4L2_CID_BRIGHTNESS is not supported\n"); } else { memset (&control, 0, sizeof (control)); control.id = id; control.value = val; if (-1 == ioctl (fd, VIDIOC_S_CTRL, &control)) { eblerror ("VIDIOC_S_CTRL"); } } }
static void enumerate_menu(int fd, struct v4l2_queryctrl &queryctrl, struct v4l2_querymenu &querymenu) { printf (" Menu items:\n"); memset (&querymenu, 0, sizeof (querymenu)); querymenu.id = queryctrl.id; for (querymenu.index = queryctrl.minimum; (int) querymenu.index <= queryctrl.maximum; querymenu.index++) { if (0 == ioctl (fd, VIDIOC_QUERYMENU, &querymenu)) { printf (" %s\n", querymenu.name); } else { eblerror ("VIDIOC_QUERYMENU"); } } }
bool load_table(configuration &conf, const std::string &module_name, idx<intg>& table, intg thickness, intg noutputs) { std::string name = module_name; name << "_table"; // table name std::string name_in = name; name_in << "_in"; // table max input std::string name_out = name; name_out << "_out"; // table max output if (conf.exists(name)) // request to load table from file { std::string filename = conf.get_string(name.c_str()); if (!file_exists(filename)) eblerror("cannot find table file declared in variable " << name << ": " << filename); table = load_matrix<intg>(filename); eblprint("Loaded " << name << " (" << table << ") from " << filename << endl); return true; } else if (conf.exists(name_in) && conf.exists(name_out)) { intg in, out; // special case, if in == "thickness", use current thickness std::string val_in = conf.get_string(name_in); if (!val_in.compare("thickness")) in = thickness; else // regular case, use string as int in = conf.get_int(name_in.c_str()); // special case, if out == "noutputs", use current thickness std::string val_out = conf.get_string(name_out); if (!val_out.compare("noutputs")) out = noutputs; else // regular case, use string as int out = conf.get_int(name_out.c_str()); // create table table = full_table(in, out); eblprint("Using a full table for " << name << ": " << in << " -> " << out << " (" << table << ")" << std::endl); return true; } eblwarn("Failed to load table " << name << std::endl); return false; }
bool camera_directory<Tdata>::empty() { if (!fl) eblerror("directory not initialized"); if (fli == fl->end()) { if (npasses > 0) { npasses--; if (npasses > 0) fli = fl->begin(); // reset to begining. } if (npasses == 0) // we did all passes, stop. return true; } return false; }
void camera_directory<Tdata>::previous() { if (empty()) eblerror("cannot grab images on empty list"); // move to previous element fli--; frame_id_--; // set names fdir = fli->first; // directory fname = fli->second; // file name frame_name_ = fname; if (fdir.size() > indir.size()) { subdir = fdir.substr(indir.size()); frame_name_ = ""; frame_name_ << subdir << "/" << fname; } if (fdir[fdir.length() - 1] != '/') fdir += "/"; }
bool mpijob_manager::assign(uint jobid, uint slave_id) { #ifdef __MPI__ if (slave_id == 0) { // master if (id_running != -1) eblerror("already running job " << id_running); id_running = jobid; jobs[jobid]->run(); return true; } else { // slaves // ask slave string confname = jobs[jobid]->name(); bool resumed = jobs[jobid]->resumed(); world.send(slave_id, CMD_RUN, jobid); world.send(slave_id, CMD_CONF, confname); world.send(slave_id, CMD_RESUME, resumed); // remember in master that this job has been started jobs[jobid]->force_started(); return true; } #endif return false; }
bool pascal_dataset<Tdata>::process_xml(const std::string &xmlfile) { std::string image_filename, image_fullname, folder; int height = -1, width = -1, depth = -1; rect<int> *cropr = NULL; // get image's properties if (!pascal_xml::get_properties(imgroot, xmlfile, image_filename, image_fullname, folder, height, width, depth, objects, &cropr, false)) return false; // get ignored boxes if present if (!ignore_root.empty()) { std::string bname = ebl::basename(xmlfile.c_str()); std::string dname = ebl::dirname(image_filename.c_str()); std::string xml, filename, fullname, folder; int h = -1, w = -1, d = -1; xml << ignore_root << "/" << dname << "/" << bname; if (file_exists(xml)) { if (!pascal_xml::get_properties(imgroot, xml, filename, fullname, folder, h, w, d, objects, &cropr, true)) return false; // check that ignored properties matches original properties if (fullname.compare(image_fullname) || (height != h) || (width != w)) eblerror("mistmatch between orignal image (" << image_fullname << ", " << height << "x" << width << ") and ignored infos (" << fullname << ", " << h << "x" << w << ")"); } else // ignore file doesnt exist std::cerr << "warning: ignore xml not found: " << xml << std::endl; } // process objects process_objects(objects, height, width, image_fullname, image_filename, cropr); // delete all objects for (uint i = 0; i < objects.size(); ++i) delete objects[i]; objects.clear(); if (cropr) delete cropr; return true; }
int display_net(list<string>::iterator &ifname, bool signd, bool load, list<string> *mats) { // create network idx<ubyte> classes(1,1); load_matrix<ubyte>(classes, conf->get_cstring("classes")); answer_module<T,T,T> *answer = create_answer<T,T,T>(*conf, classes.dim(0)); if (!answer) eblerror("no answer module found"); uint noutputs = answer->get_nfeatures(); parameter<T> theparam; intg thick; module_1_1<T> *net = create_network<T>(theparam, *conf, thick, noutputs); cout << "Network parameters: " << theparam << endl; vector<string> weights = string_to_stringvector(conf->get_string("weights_file")); // loading weights theparam.load_x(weights); // displaying internals uint h0 = 0, w0 = 0; #ifdef __GUI__ disable_window_updates(); clear_window(); if (show_filename) { gui << at(h0, w0) << black_on_white() << ifname->c_str(); h0 += 16; } if (autorange) // automatic range lg.display_internals(*net, h0, w0, zoom, (T) 0, (T) 0, maxwidth); else // fixed range lg.display_internals(*net, h0, w0, zoom, (T) range[0], (T) range[1], maxwidth); // update title string title; title << "matshow: " << ebl::basename(ifname->c_str()); set_window_title(title.c_str()); enable_window_updates(); #endif return 1; }
//! Retrieve type so that we know if we can look //! for negative values when estimating range. int load_display(list<string>::iterator &ifname, bool load, list<string> *mats) { try { switch (get_matrix_type((*ifname).c_str())) { case MAGIC_BYTE_MATRIX: case MAGIC_UBYTE_VINCENT: return display<ubyte>(ifname, false, load, mats); break ; case MAGIC_INTEGER_MATRIX: case MAGIC_INT_VINCENT: return display<int>(ifname, true, load, mats); break ; case MAGIC_FLOAT_MATRIX: case MAGIC_FLOAT_VINCENT: return display<float>(ifname, true, load, mats); break ; case MAGIC_DOUBLE_MATRIX: case MAGIC_DOUBLE_VINCENT: return display<double>(ifname, true, load, mats); break ; case MAGIC_LONG_MATRIX: return display<long>(ifname, true, load, mats); break ; case MAGIC_UINT_MATRIX: #ifndef __WINDOWS__ return display<uint>(ifname, false, load, mats); #else eblerror("matshow for UINT disabled in Windows"); #endif break ; default: // not a matrix, try as regular float image return display<float>(ifname, true, load, mats); } } eblcatcherror(); return 0; }
bool camera_directory<Tdata>::read_directory(const char *dir) { out << "Image search pattern: " << file_pattern << " in " << dir << std::endl; std::string directory = dir; if (directory[directory.length() - 1] != '/') directory += '/'; indir = directory; // // first count number of images, to allocate list and speed up // uint n = count_files(directory, file_pattern); // if (fl) delete fl; // fl = new files_list(n); // get all file names if (fl) delete fl; fl = find_files(directory, file_pattern, NULL, randomize ? false : true, true, randomize); if (!fl) { err << "invalid directory: " << dir << std::endl; eblerror("invalid directory"); return false; } return true; }