convert imageset.bin is missing - lmdb

I build caffe on windows.it ended succesfuly. Now in my caffe/build/tools there is no convert imagetset.bin.
Where can I find or build(I already build caffe on windows with opencv installed and etc.) convert imageset.bin?
This is my code:
TOOLS=C:/projectcaffe/caffe/tools
DATA=D:/DATASET/aligned/
DEF_FILES=D:/DATASET/adel/Folds/train_val_txt_files_per_fold/test_fold_is_0
OUT=D:/DATASET/lmdb/Test_fold_is_0
# Set RESIZE=true to resize the images to 256x256. Leave as false if images have
# already been resized using another tool.
RESIZE=true
if $RESIZE; then
RESIZE_HEIGHT=256
RESIZE_WIDTH=256
else
RESIZE_HEIGHT=0
RESIZE_WIDTH=0
fi
echo "Creating train leveldb..."
GLOG_logtostderr=1 $TOOLS/convert_imageset.bin--resize_height=$RESIZE_HEIGHT --resize_width=$RESIZE_WIDTH --shuffle $DATA $DEF_FILES/age_train.txt $OUT/age_train_lmdb
echo "Creating train subset leveldb..."
GLOG_logtostderr=1 $TOOLS/convert_imageset.bin--resize_height --resize_height=$RESIZE_HEIGHT --resize_width=$RESIZE_WIDTH --shuffle $DATA $DEF_FILES/age_test.txt $OUT/age_test_lmdb
echo "Creating val leveldb..."
GLOG_logtostderr=1 $TOOLS/convert_imageset.bin --resize_height=$RESIZE_HEIGHT --resize_width=$RESIZE_WIDTH --shuffle $DATA $DEF_FILES/age_val.txt $OUT/age_val_lmdb
echo "Creating train leveldb..."
GLOG_logtostderr=1 $TOOLS/convert_imageset.bin --resize_height=$RESIZE_HEIGHT --resize_width=$RESIZE_WIDTH --shuffle $DATA $DEF_FILES/gender_train.txt $OUT/gender_train_lmdb
echo "Creating train subset leveldb..."
GLOG_logtostderr=1 $TOOLS/convert_imageset.bin--resize_height=$RESIZE_HEIGHT --resize_width=$RESIZE_WIDTH --shuffle $DATA $DEF_FILES/gender_test.txt $OUT/gender_test_lmdb
echo "Creating val leveldb..."
GLOG_logtostderr=1 $TOOLS/convert_imageset.bin --resize_height=$RESIZE_HEIGHT --resize_width=$RESIZE_WIDTH --shuffle $DATA $DEF_FILES/gender_val.txt $OUT/gender_val_lmdb

You can find it in the following path if you compiled the caffe correctly.
/path_to_caffe-rc5/distribute/bin

Related

Shell: Pass function with arguments as function argument

I'm working on a shell program to automatise my Arch (mandatory btw) installation. To make it more interactive, I've built the following function:
# READYN
# ARGS:
# - Yes/no question
# - Command to run if yes
# - Command to run if no
#
# Prompts the user with a yes/no question (with precedence for yes) and
# run an order if the answer is yes or another if it's no.
readyn () {
while :
do
local yn;
printf "%s? [Y/n]: " "$1";
read yn;
if [[ "$yn" =~ ^([yY][eE][sS]|[yY])?$ ]]; then
$2;
break;
elif [[ "$yn" =~ ^([nN][oO]|[nN])+$ ]]; then
$3;
break;
fi
done
}
I've succeeded in passing an "echo Hello World!" as an argument and having it run. I've also been able to pass another function. For example:
yayprompt () {
printf "yay is required to install %s.\n" "$1"
readyn "Install yay, the AUR manager" "yayinstall" ""
}
This calls yayinstall if yes and does nothing if no.
My problem comes with more complex functions, which are passed as arguments but are either not recognised or run when they're not supposed to. The problem comes with the following function:
# MANAGEPGK
# ARGS:
# - Package name
# - Package variable
# - Yay required
#
# Checks if the package is added to the pkglist to either add or remove it.
# If yay is required to install it, it prompts the user whether they wish
# to install yay or don't install the package (if yay is not installed).
# This functions DOES NOT prompt any installation options on the user. To
# do this, use PROMPTPKG.
managepkg () {
local pkgvar=$2
if [ $pkgvar == 0 ]; then
if [ $3 == 1 ] && [ $yay == 0 ]; then
yayprompt;
fi
if [ $3 == 0 ] || [ $yay == 1 ]; then
addpkg "$1";
pkgvar=1;
fi
else
rmpkg "$1";
pkgvar=0;
fi
echo "$pkgvar";
}
For it to work properly, it has to (or at least I've had to) be called like this:
dewm_cinnamon=$(managepkg cinnamon $dewm_cinnamon 0)
Now, I'm trying to pass it as an argument to readyn, but I'm having these outputs depending on the format (I'm always answering yes as empty string:
Simple quotes:
readyn "Install gaps" \
'dewm_i3gaps=$(managepkg i3-gaps $dewm_i3gaps 0)' \
'dewm_i3=$(managepkg i3-wm $dewm_i3 0)';
Install gaps? [Y/n]:
./architup.sh: line 341: dewm_i3gaps=$(managepkg: command not found
Double quotes:
readyn "Install gaps" \
"dewm_i3gaps=$(managepkg i3-gaps $dewm_i3gaps 0)" \
"dewm_i3=$(managepkg i3-wm $dewm_i3 0)";
Install gaps? [Y/n]:
./architup.sh: line 341: dewm_i3gaps=1: command not found
Dollar enclosed: (This one runs both commands as seen in cat pkglist)
readyn "Install gaps" \
$(dewm_i3gaps=$(managepkg i3-gaps $dewm_i3gaps 0)) \
$(dewm_i3=$(managepkg i3-wm $dewm_i3 0));
Install gaps? [Y/n]:
Install compton? [Y/n]: ^C
Documents/Repositories/architup took 5s
➜ cat pkglist
i3-gaps
i3-wm
What syntax should I use to have readyn run only one command based on the user input?
Thank you!
Function arguments are just strings. A better design IMHO is to simply have readyn return true (zero) for "yes" and false otherwise, and have the calling code implement any conditional logic based on that.
readyn () {
read -p "$#"
case $REPLY in
[Yy] | [Yy][Ee][Ss]) return 0;;
esac
return 1
}
readyn "Are you ready San Antonio?" &&
rock and roll
if readyn "Let me hear you say yeah"; then
echo "Let's go!"
else
echo "If you feel mellow, get outta here"
fi
(With apologies to rock concerts everywhere,)

gnuplot: load datafile 1:1 into datablock

How can I read a datafile as-is (or 1:1) into a datablock?
And how could I do this platform independently?
My attempt so far:
### load datafile "as is" into datablock for different platforms
FILE = 'Test.dat'
if (GPVAL_SYSNAME[:7] eq "Windows") { # "Windows_NT-6.1" is shown on a Win7 system
load "< echo $Data ^<^<EOD & type ".FILE
}
if (GPVAL_SYSNAME eq "Linux") { # that's shown on a Raspberry
load '< echo "\$Data << EOD" & cat '.FILE
}
if (GPVAL_SYSNAME eq "Darwin") { # this was shown on a MacOS Sierra 10.12.6
# how to load a datafile into datablock under MacOS?
}
print $Data
### end of code
What is the value of GPVAL_SYSNAME on a Win10, other Linux, and other MacOS systems?
How many if statements would I need to cover all common systems?
At least under Windows the console window is flashing. How could I possibly surpress this?
My thoughts behind reading data into a dataset are the following:
if you have data on a very(!) slow server path
if you have relatively large datafiles
if you fit and plot multiple curves from several files
For example something like:
FILE1 = '\\SlowServer\blah\BigDataFile.dat'
FILE2 = '\\SlowerServer\blah\BiggerDataFile.dat'
FILE3 = '\\SlowestServer\blah\BiggestDataFile.dat'
fit f(x) FILE1 u 1:2 via a,c,d,e
fit g(x) FILE2 u 2:3 via f,g,h,i
fit h(x) FILE3 u 2:3 via j,k,l,m
plot FILE1 u 1:2:3 w l, \
'' u (function($1)):(function($2)):3 with <whatever>, \
FILE2 u 4:5:6 w l, \
'' u 1:2:3 w l, \
FILE3 u 7:8:9 w l, \
'' u 1:2:3 w l , \
<and more...>
My questions:
Everytime you plot or fit FILE and '', will the content of FILE be loaded again and again or will it be kept in memory?
If you zoom in, e.g. in an interactive wxt terminal, it looks to me as if the files need to be loaded again. Is this true?
If the files are loaded again and again, wouldn't it be best practice to load files once into datablocks once at the beginning and then work with these datablocks?
Any explanations, limitations, pros & cons and comments are appreciated.
Addition:
(partial answer, but with new issue):
For the systems Windows,Linux and MacOS the following seems to work fine. Linux and MacOS are apparently identical.
if (GPVAL_SYSNAME[:7] eq "Windows") { load '< echo $Data ^<^<EOD & type "Test.dat"' }
if (GPVAL_SYSNAME eq "Linux" ) { load '< echo "\$Data << EOD" & cat "Test.dat"' }
if (GPVAL_SYSNAME eq "Darwin") { load '< echo "\$Data << EOD" & cat "Test.dat"' }
However, if I want to call this construct from an external gnuplot procedure "FileToDatablock.gpp" it reproduceably crashes gnuplot under Win7/64 (haven't had a chance to test Linux or MacOS).
"FileToDatablock.gpp"
### Load datafile "as is" 1:1 into datablock for different platforms
# ARG1 = input filename
# ARG2 = output datablock
# usage example: call "FileToDatablock.gpp" "Test.dat" "$Data"
if (ARGC<1) { ARG1 = "Test.dat" }
if (ARGC<2) { ARG2 = "$Data" }
if (GPVAL_SYSNAME[:7] eq "Windows") { load '< echo '.ARG2.' ^<^<EOD & type "'.ARG1.'"' }
if (GPVAL_SYSNAME eq "Linux" ) { load '< echo "\'.ARG2.' << EOD" & cat "'.ARG1.'"' }
if (GPVAL_SYSNAME eq "Darwin") { load '< echo "\'.ARG2.' << EOD" & cat "'.ARG1.'"' }
### end of code
And the file which calls this procedure:
### load datafile 1:1 into datablock
reset session
# this works fine under Win7/64
FILE = "Test.dat"
DATA = "$Data"
load '< echo '.DATA.' ^<^<EOD & type "'.FILE.'"'
print $Data
# this crashes gnuplot under Win7/64
call "tbFileToDatablock.gpp" "Test.dat" "$Data"
print $Data
### end of code
What's wrong with this? Can anybody explain why and how to solve this issue?
It is possible to read a file into a datablock, provided you know the input data format. For example, you have a file MyFile1 with numbers in 3 columns which you want to read into datablock MyBlock1, then plot in 3 ways:
set table $MyBlock1
plot "MyFile1" using 1:2:3 with table
unset table
plot $MyBlock1 using 1:2 with points
plot $MyBlock1 using 2:3 with points
plot $MyBlock1 using 1:3 with lines
This avoids reading the file several times, and should presumably work on any platform. Rather than doing this, I imagine it would be simpler to just copy your files from your slow filesystem to a local filesystem.
The idea is to get a datafile as is (1:1) into a datablock, including commented lines or empty lines, etc.
As far as I know, there seems to be no simple and direct platform-"independent" gnuplot command for this.
In some cases it might be advantageous to have data in datablocks (which are availabe since gnuplot 5.0), because you can simply address lines by index (only since gnuplot 5.2), e.g. $Data[7], or loop data forward and backwards, which you cannot do easily with data from a file.
Here is finally a solution which is acceptable for me and it seems to work on Windows and Linux (tested Windows 7 and 10 and Ubuntu 18.04.4). I couldn't test on MacOS, but I assume the command will be identical with Linux and it will work for MacOS as well. I don't know about other operating systems (feedback appreciated).
Code:
### load data file as is 1:1 into datablock
reset session
FileToDatablock(f,d) = GPVAL_SYSNAME[1:7] eq "Windows" ? \
sprintf('< echo %s ^<^<EOD & type "%s"',d,f) : \
sprintf('< echo "\%s <<EOD" & cat "%s"',d,f) # Linux/MacOS
FILE = 'Test.dat'
load FileToDatablock(FILE,'$Data')
print $Data
### end of code
Data file: (Test.dat)
# This is a test file
1.1 1.2
2.1 2.2
3.1 3.2
# another commented line
4.1 4.2
5.1 5.2
# some empty lines will follow
6.1 6.2 # some spaces at the beginning
7.1 7.3
# end of datafile
Result: (as expected $Data is 1:1 equal to Test.dat)
# This is a test file
1.1 1.2
2.1 2.2
3.1 3.2
# another commented line
4.1 4.2
5.1 5.2
# some empty lines will follow
6.1 6.2 # some spaces at the beginning
7.1 7.3
# end of datafile

How can I “fill in the blanks” for a command in a script from user input?

I’m trying to build a script that asks for a time clock number and a DC number from the user running the script, which I’m intending to fill in the Xs for
/u/applic/tna/shell/tc_software_update.sh tmcxx.s0xxxx.us REFURBISHED
However, I am stumped as to how to have the user’s input fill in those Xs on that command within the script. This script is in its earliest stages so it’s very rough right now lol. Thank you for responding. Here’s the scripts skeleton I’m working on:
#!/bin/bash
#This server is intended to speed up the process to setup timeclocks from DC tickets
#Defines time clock numbers
timeclocks="01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35"
#Defines DC number
echo “What is the DC number?”
read dc
#Defines TMC number
echo "What is the Time Clock number?"
read number
if $number == $timeclocks && $dc == ???; then
/u/applic/tna/shell/tc_software_update.sh tmcxx.s0xxxx.us REFURBISHED
Do you mean invoking $ /u/applic/tna/shell/tc_software_update.sh tmc${number}.s0${dc}.us REFURBISHED?
Consider the following snippet:
[test.sh]
read x
read y
echo "x=${x}, y=${y}"
$ sh test.sh
5
4
x=5, y=4
Further on, you can use command line arguments ($1, $2 etc.) instead of the user input.
Modelling this on your script:
timeclocks=( {1..35} )
printf '%s' "DC number: "; read dc
printf '%s' "Time Clock number: "; read tmc
tmc=$( printf '%02d' "$tmc" )
dc=$( printf '%04d' "$dc" )
tmc_valid=$( for t in ${timeclocks[#]}; do \
[[ $tmc -eq $t ]] && echo true && break; \
done )
[[ "$tmc_valid" = "true" && "$dc" = "???" ]] && \
/u/applic/tna/shell/tc_software_update.sh tmc${tmc}.s0${dc}.us REFURBISHED

Why i am getting IO::Uncompress::Unzip::unzip: input filename is undef or null string message?

I am having a folder with many zip files. I need to get any of these zip file, extract it and get a particular file from the ziped file. I am using IO::Uncompress::Unzip module for this.
I have my perl script as below:
#!usr/bin/perl
use IO::Uncompress::Unzip qw(unzip $UnzipError);
use strict;
my $propath ="/home/test/prroot/Projects/";
my $proj = "/home/Ras/projectroot/projects.txt";
my #projlist = `cat $proj`;
foreach my $pr(#projlist){
chomp($pr);
my $projname = $pr;
my $projtemp = $pr;
$projname =~ s/ /\_/g;
my $replace1 = "%28"; #escaping special characters from project name
my $replace2 = "%29";
my $replace3 = "%26";
my $replace4 = "%2C";
$projname =~ tr/ /_/;
$projname =~ s/\(/$replace1/g;
$projname =~ s/\)/$replace2/g;
$projname =~ s/\&/$replace3/g;
$projname =~ s/\,/$replace4/g;
chomp($projname);
my $dir = $propath.$projname;
chomp($dir);
my #res = glob "$dir/*.zip";
my #res1 = split '/',$res[$#res];
my $out = chdir $dir;
my $input = "$res1[$#res1]";
my $output = "/home/Ras/projectroot/xmlres/result$projname.xml";
my $status = unzip $input => $output, Name => "data";
}
The file /home/Ras/projectroot/projects.txt includes more than 100 project names. For each project name there is a folder under the path /home/test/prroot/Projects/. Inside the projectname folder there are zip files. I need to read particular file named data from the zip file. I am able to read the output for 13 files as /home/Ras/projectroot/xmlres/result$projname.xml. But after that no result. Please help me on this.
'As I don't know how your data look like, I provide a - slightly - improved version of your script here (adding the error handling).
#!usr/bin/perl
use IO::Uncompress::Unzip qw(unzip $UnzipError);
use File::Find;
use strict;use warnings;
my $propath ="/home/test/prroot/Projects/";
my $proj = "/home/Ras/projectroot/projects.txt";
my $output_dir = "/home/Ras/projectroot/xmlres/";
my #projlist = `cat $proj`;
my $projname;
foreach my $pr (#projlist){
chomp($pr);
$projname = $pr;
$projname =~ s/ /\_/g;
$projname =~ tr/ /_/;
$projname =~ s/\(/%28/g;
$projname =~ s/\)/%29/g;
$projname =~ s/\&/%26/g;
$projname =~ s/\,/%2C/g;
print "$dir\n";
find({ wanted => \&find_zip}, $dir);
}
sub find_zip {
my $filename = $File::Find::name;
print "$filename\n";
if ($filename =~ /zip$/ ) {
unless( unzip $filename => $output_dir.'result'.$projname.'.xml', Name => "data" ) {
warn "$filename: $UnzipError";
}
}
}
First thing to check is that the script is attempting to unzip all the files you expect.
Then see if unzip is complaining.
Try this
print "About to unzip '$input' to '$output'\n" ;
my $status = unzip $input => $output, Name => "data"
or die "unzip from '$input' to '$output' failed: $UnzipError\n";
Unzip was giving data error. I did a modification in my script and it helped.
my $status = `unzip -p $input "data" > $output`
By adding above line replacing unzip $input => $output, Name => "data" helped in solving the issue.
Without going for extraction of zip file, it is just reading the data content and i am able to meet the requirement. Thanks for all your help

how to reassign page number in DJVU file?

Is there a simple way to renumber pages in a DJVU file?
Example:
I've got a book, and page 1 is actually the cover, and so on, such that the actual page 1 of the book is at, say, 10 in the document; what I'd like to do is call them something like C,i,ii,..., and then 1,2,...
I know it can be done, since I've got other books in this format with this numbering, and I'd like to do it on Linux, better if via terminal.
Thanks,
N
to renumber
for (( i=11; i<=823; i++ ))
do
djvused new.djvu -e "select $i; set-page-title $((i-10)); save"
done
to rename
djvused new.djvu -e 'select 2; set-page-title ii; save'
It's slightly offtopic. Just in case someone needs to do the same thing on Windows using PowerShell:
for($i=11; $i -le 823; $i++){
$j=($i-10)
$args = "new.djvu -e ""select $i; set-page-title $j; save"""
write-host "djvused $args"
start-process djvused $args -NoNewWindow -wait
}

Resources