-3

The command I am currently using to test my set is

python eval.py --test_data_path=PATH_TO_IMAGES --gpu_list=0 --checkpoint_path=/tmp/east_icdar2015_resnet_v1_50_rbox/ \
--output_dir=PATH_TO_END_LOCATION

However what I currently want to do, is to give them a file as input that file has the path of all the images instead of what I did before, supplying a folder with all the images inside.

The file's content will look a bit like this

data/processed/10/blueprint-0.png
data/processed/10/blueprint-15.png
data/processed/10/blueprint-16.png
data/processed/10/blueprint-17.png
data/processed/10/blueprint-18.png

How can I adjust my command to do that task or even write a python code that will put all of them in a destination folder that I can reuse my first method on.

Edit : I figured out how to manage it but i need a regex that would take in the 2 numeric values, for example in the first line data/processed/10/blueprint-0.png i need a regex that will assign 10 to a variable a and 0 to a variable b.

  • To me, that you asked a question and, until other people answered, continued to (partially) solve your own question, thereby invalidating their answers, indicates that you shouldn't have asked (yet). – nnnmmm Jan 25 '18 at 09:02
  • Actually the fact that i was still trying myself instead of sitting back waiting for answers should be taken as a positive sign not the other way around. – user9266246 Jan 25 '18 at 09:08

2 Answers2

1

What you do:

  • Create an input file that contains the paths, e.g., infiles.txt
  • Read the input file locations from this file
  • use shutil.copy to copy your files to that location

Here's a sample code:

import os, shutil
from argparse import ArgumentParser as argpars
parser = argpars(description='')
parser.add_argument('--test_data_file', nargs=1, type=str)
parser.add_argument('--dest_loc', nargs=1, type=str)
args = parser.parse_args()

with open(args.test_data_file[0], 'r') as f:
    file_locations = [ff.strip() for ff in f.readlines()]


for loc in file_locations:
    print(os.path.join(args.dest_loc[0], loc.split('/')[-1]))
#   shutil.copy(loc, os.path.join(args.dest_loc[0], loc.split('/')[-1]))

The command is something like

python your_script.py --test_data_file infiles.txt --dest_loc some_folder

Edit For the regex question:

import re
re.findall(r'\d+', 'data/processed/10/blueprint-0.png')
# or in the example above
re.findall(r'\d+', loc)
Floyd4K
  • 96
  • 4
  • Hello thanks for answering that but meanwhile i typed my own code, however i need help with the regex part which is in the edit, kindly check and supply a helpful answer in that aspect if possible then i'll accept. – user9266246 Jan 25 '18 at 08:58
  • try: re.findall(r'\d+', 'data/processed/10/blueprint-0.png') or re.findall(r'\d+', loc) in the example above – Floyd4K Jan 25 '18 at 09:01
  • Thank you i'll check 1 moment. – user9266246 Jan 25 '18 at 09:04
  • a more detailed answer to the regex question can be found here: https://stackoverflow.com/a/4289348/5172579 – Floyd4K Jan 25 '18 at 09:09
0

What exactly you need to change depends on how test_data_path is used in your program. If some part of your program later expects a list of files instead of a directory, it's trivial: open the file that is passed as an argument, call list() on it to get the names of the files, optionally validate that they exist, and pass the names on.

nnnmmm
  • 7,964
  • 4
  • 22
  • 41