//----------------------------------------------------------------------------- bool test_image_io(const std::string filename, const main_params& mp, const cropper_params& rp, const resizer_params& sp, const augmenter_params& ap) { int transform_idx = 0; int mean_extractor_idx = -1; unsigned int num_bytes = mp.m_num_bytes; // size of image in bytes lbann::cv_process pp; { // Initialize the image processor if (rp.m_is_set) { // If cropper parameters are given // Setup a cropper std::unique_ptr<lbann::cv_cropper> cropper(new(lbann::cv_cropper)); cropper->set(rp.m_crop_sz.first, rp.m_crop_sz.second, rp.m_rand_center, rp.m_roi_sz, rp.m_adaptive_interpolation); pp.add_transform(std::move(cropper)); num_bytes = rp.m_crop_sz.first * rp.m_crop_sz.second * 3; transform_idx ++; } if (sp.m_is_set) { // If resizer parameters are given // Setup a cropper std::unique_ptr<lbann::cv_resizer> resizer(new(lbann::cv_resizer)); resizer->set(sp.m_width, sp.m_height, rp.m_adaptive_interpolation); pp.add_transform(std::move(resizer)); num_bytes = sp.m_width * sp.m_height * 3; transform_idx ++; } if (ap.m_is_set) { // Set up an augmenter std::unique_ptr<lbann::cv_augmenter> augmenter(new(lbann::cv_augmenter)); augmenter->set(ap.m_hflip, ap.m_vflip, ap.m_rot, ap.m_hshift, ap.m_vshift, ap.m_shear); pp.add_transform(std::move(augmenter)); transform_idx ++; } if (mp.m_enable_colorizer) { // Set up a colorizer std::unique_ptr<lbann::cv_colorizer> colorizer(new(lbann::cv_colorizer)); pp.add_transform(std::move(colorizer)); transform_idx ++; } if (mp.m_enable_decolorizer) { // Set up a colorizer std::unique_ptr<lbann::cv_decolorizer> decolorizer(new(lbann::cv_decolorizer)); pp.add_transform(std::move(decolorizer)); transform_idx ++; } if (mp.m_enable_mean_extractor) { // set up a mean extractor mean_extractor_idx = transform_idx; std::unique_ptr<lbann::cv_mean_extractor> mean_extractor(new(lbann::cv_mean_extractor)); if (rp.m_is_set) mean_extractor->set(rp.m_crop_sz.first, rp.m_crop_sz.second, 3, mp.m_mean_batch_size); else mean_extractor->set(mp.m_mean_batch_size); pp.add_transform(std::move(mean_extractor)); transform_idx ++; } if (!mp.is_normalizer_off()) { // Set up a normalizer if (mp.is_channel_wise_normalizer()) { std::unique_ptr<lbann::cv_normalizer> normalizer(new(lbann::cv_normalizer)); normalizer->z_score(true); pp.add_normalizer(std::move(normalizer)); } else { std::unique_ptr<lbann::cv_subtractor> normalizer(new(lbann::cv_subtractor)); #if 0 cv::Mat img_to_sub = cv::imread(mp.m_mean_image_name); if (img_to_sub.empty()) { std::cout << mp.m_mean_image_name << " does not exist" << std::endl; return false; } normalizer->set_mean(img_to_sub); #else std::vector<lbann::DataType> mean = {0.40625, 0.45703, 0.48047}; normalizer->set_mean(mean); std::vector<lbann::DataType> stddev = {0.3, 0.5, 0.3}; normalizer->set_stddev(stddev); #endif pp.add_normalizer(std::move(normalizer)); } transform_idx ++; } } // Load an image bytestream into memory std::vector<unsigned char> buf; bool ok = lbann::load_file(filename, buf); if (!ok) { std::cout << "Failed to load" << std::endl; return false; } int width = 0; int height = 0; int type = 0; ::Mat Images; ::Mat Image_v; // matrix view Images.Resize(((num_bytes==0)? 1: num_bytes), 2); // minibatch size_t img_begin = 0; size_t img_end = buf.size(); for (unsigned int i=0; i < mp.m_num_iter; ++i) { // This has nothing to do with the image type but only to create view on a block of bytes using InputBuf_T = lbann::cv_image_type<uint8_t>; // Construct a zero copying view to a portion of a preloaded data buffer const cv::Mat inbuf(1, (img_end - img_begin), InputBuf_T::T(1), &(buf[img_begin])); if (num_bytes == 0) { ok = lbann::image_utils::import_image(inbuf, width, height, type, pp, Images); num_bytes = Images.Height(); El::View(Image_v, Images, El::IR(0, num_bytes), El::IR(0, 1)); } else { El::View(Image_v, Images, El::IR(0, num_bytes), El::IR(0, 1)); //ok = lbann::image_utils::import_image(buf, width, height, type, pp, Image_v); ok = lbann::image_utils::import_image(inbuf, width, height, type, pp, Image_v); } if (!ok) { std::cout << "Failed to import" << std::endl; return false; } //if ((i%3 == 0u) && (mp.m_enable_mean_extractor)) { // dynamic_cast<lbann::cv_mean_extractor*>(pp.get_transform(mean_extractor_idx))->reset(); //} } // Print out transforms const unsigned int num_transforms = pp.get_num_transforms(); const std::vector<std::unique_ptr<lbann::cv_transform> >& transforms = pp.get_transforms(); for(unsigned int i=0u; i < num_transforms; ++i) { std::cout << std::endl << "------------ transform " << i << "-------------" << std::endl; std::cout << *transforms[i] << std::endl; } if (mp.m_enable_mean_extractor) { // Extract the mean of images cv::Mat mean_image; mean_image = dynamic_cast<lbann::cv_mean_extractor*>(pp.get_transform(mean_extractor_idx))->extract<uint16_t>(); cv::imwrite("mean.png", mean_image); } // Export the unnormalized image const std::string ext = lbann::get_ext_name(filename); std::vector<unsigned char> outbuf; ok = lbann::image_utils::export_image(ext, outbuf, width, height, type, pp, Image_v); write_file("copy." + ext, outbuf); return ok; }
function main(in mode, io ledgercode, in newaccno0, in newaccount, in sortorder, in params0, out msg) { //y2k //chartmv.fns must be changed in all places in ABP and ABP2 var interactive = not SYSTEM.a(33); var newaccno = newaccno0.a(1, 1, 1); //if newaccno<1,1,2>='' then newaccno<1,1,2>=newaccno<1,1,1> var newaccname = newaccount.a(1); var params=params0; var update = mode == "ADD"; msg = ""; //check does not already exist in any ledger if (fin.account.read(fin.accounts, "." ^ newaccno)) { return 0; } // msg='' //preexist: // msg=quote(newaccno):msg:' ACCOUNT NUMBER ALREADY EXISTS' // return 0 // end if (fin.account.read(fin.accounts, newaccno)) { return 0; } // msg=' ORIGINAL' // goto preexist // end //make the ledger code var origledgercode = ledgercode; var origparams = params; gosub expandledgercodeparams(ledgercode, params); //if chart doesnt exist then walk back through the years //zzz should walk back through quarters or periods too but isnt implemented //if by period or quarter will work if all periods/quarters exist in one year var tt; if (not(tt.read(fin.charts, ledgercode))) { var targetledgercode = ledgercode; //contruct prior year ledgercode getprevledgercode: params.r(1, (addcent(params.a(1)) - 1).substr(-2, 2)); ledgercode = origledgercode; gosub expandledgercodeparams(ledgercode, params); //just quit if back to original code after searching backwards through 07-06 if (ledgercode == targetledgercode) { ledgercode = targetledgercode; }else{ //if prior year chart doesnt exist go back to look for another var chart; if (not(chart.read(fin.charts, ledgercode))) { goto getprevledgercode; } //found previous chart so create new chart //change previous year if in chart name var tt = chart.a(1); tt.swapper(addcent(params.a(1)), addcent(origparams.a(1))); tt.swapper(params.a(1), origparams.a(1)); chart.r(1, tt); ledgercode = targetledgercode; //zzz should really lock to prevent create unless exclusive //but will not really cause a problem probs gosub createchart(chart, ledgercode); } } //find the highest numbered ledger within that group var chart = ""; var ledgerno = -1; origledgercode = ledgercode; var newaccnumber = newaccno; if (newaccnumber.match("\"JOB\"0N")) { newaccnumber.splicer(1, 3, ""); } if (newaccnumber.match("\"SCH\"0N")) { newaccnumber.splicer(1, 3, ""); } nextledgerno: ledgerno += 1; var newledgercode = origledgercode ^ ledgerno.oconv("MD00Z"); var nextledgerno = ledgerno + 1; if (nextledgerno < 2) { nextledgerno = 2; } var nextledgercode = origledgercode ^ nextledgerno; if (chart.read(fin.charts, newledgercode)) { /*; //if numeric account numbers and any account is gt the new account number // then this is the ledger if num(newaccnumber) then; naccs=count(chart<3>,vm)+1; for accn=naccs to 1 step -1; accno=chart<10,accn>; if accno matches '"JOB"0N' then accno[1,3]=''; if accno matches '"SCH"0N' then accno[1,3]=''; if accno then; if num(accno) and accno>newaccnumber then; ledgercode=newledgercode; goto foundledger; end; end; next accn; end; */ ledgercode = newledgercode; goto nextledgerno; } //allow for number :1 missing and jump to :2 if (ledgerno < 2) { //ledgerno+=1 goto nextledgerno; } //foundledger: //check that the ledger exists and get the chart if (not chart) { msg = "Cannot create Account " ^ (DQ ^ (newaccno ^ DQ)) ^ " automatically because|"; msg ^= "ledger " ^ (DQ ^ (ledgercode ^ DQ)) ^ " must be created first"; goto exit; } lockit: //lock and reread the chart for update if (not(lockrecord("CHARTS", fin.charts, ledgercode, 60))) { msg = "Cannot create account " ^ (DQ ^ (newaccno ^ DQ)) ^ " automatically because|"; msg ^= "somebody is updating |" ^ (DQ ^ (chart.a(1) ^ DQ)); goto exit; } if (not(chart.read(fin.charts, ledgercode))) { chart = ""; } //add new chart if existing is too big //if interactive and len(chart)>32000 and newledgercode then if (chart.length() > 32000 and newledgercode) { //unlock the old chart because we are going to create a new one var xx = unlockrecord("CHARTS", fin.charts, ledgercode); //switch to the new ledger code ledgercode = newledgercode; newledgercode = ""; gosub createchart(chart, ledgercode); goto lockit; } //prevent chartsize exceeding 32KB //NB "TOO BIG" is a trigger phrase hard coded in IMPORTX so dont change it msg = "THE|" ^ chart.a(1) ^ " (" ^ ledgercode ^ ")|LEDGER IS GETTING TOO BIG"; msg ^= "||!!! PLEASE OPEN A NEW LEDGER|WITH LEDGER CODE " ^ (DQ ^ (newledgercode ^ DQ)) ^ "|"; if (chart.length() > 36000) { msg.splicer(1, 0, "!CANNOT OPEN NEW ACCOUNT " ^ (DQ ^ (newaccno ^ DQ)) ^ " BECAUSE "); msg.swapper("GETTING ", ""); goto exit; } //warning if chartsize nearing 32KB if (chart.length() > 32000) { //if mode='VALIDATE' then call note(msg) if (mode == "VALIDATE") { goto exit; } } msg = ""; /// if (mode == "VALIDATE") { goto exit; } /// //determine the sort key if (sortorder == "NAME") { sortkey = newaccname; }else{ sortkey = newaccname; } //calc the number of lines accs = chart.a(4); naccs = accs.count(VM) + (accs ne ""); naccs2 = (chart.a(3)).count(VM) + (chart.a(3) ne ""); if (naccs2 > naccs) { naccs = naccs2; } //default to the end of the ledger vn = naccs + 1; //find value number to insert at if (sortorder) { //insert before the first larger account number or name for (var accn = 1; accn <= naccs; ++accn) { if (sortorder == "NAME") { value = chart.a(3, accn); }else{ value = chart.a(10, accn); } if (value) { if (value.trimf() > sortkey) { vn = accn; accn = naccs; //insert a blank line var nn = fin.chartmvfns.dcount(VM); for (var ii = 1; ii <= nn; ++ii) { var tt = fin.chartmvfns.a(1, ii); if (tt) { chart.inserter(tt, vn, ""); } };//ii; } } };//accn; } //update the chart of accounts if (vn == 1) { indent = ""; }else{ //indent like previous line var temp = chart.a(3, vn - 1); indent = (temp.length() - (temp.trimf()).length()).space(); //if no account number on previous line then indent by one more if (chart.a(4, vn - 1) == "") { indent ^= " "; } } chart.r(3, vn, indent ^ newaccname); chart.r(4, vn, newaccno); chart.r(10, vn, newaccno); //terms //main currency //tax code if (newaccount.a(33)) { chart.r(33, vn, newaccount.a(33)); } if (newaccount.a(4)) { chart.r(7, vn, newaccount.a(4)); } if (newaccount.a(14)) { chart.r(14, vn, newaccount.a(14)); } if (update) { call cropper(chart); chart.write(fin.charts, ledgercode); } //create the account record fin.account = newaccount; fin.account.r(2, ledgercode); fin.account.r(5, chart.a(6)); fin.account.r(6, chart.a(2, 1, 2)); fin.account.r(8, chart.a(9)); fin.account.r(10, newaccno); fin.account.r(23, chart.a(5)); //account<26>= if (update) { fin.account.write(fin.accounts, newaccno); } //create the other account record fin.account.r(10, newaccno); if (update) { fin.account.write(fin.accounts, "." ^ newaccno); } exit: ///// var xx = unlockrecord("CHARTS", fin.charts, ledgercode); return 0; }
QRect CCBuilder::crop() { Cropper cropper(this); return cropper.crop(); }