0

I have created Tensorflow image classifier and image classifier should be called using another python script.

I tried os.system() but I cant just call Tensorflow scripts coz it's depends on the multiple files in the Tensorflow script location. so I have to include all the files with classifier script in the main script(2nd python script).

What is the best way to do this?

when script is running :

enter image description here

script error when running from another location :

enter image description here

Narendra Jadhav
  • 10,052
  • 15
  • 33
  • 44

2 Answers2

0

Do you have tried Python Subprocess instead of os.system?

From How do you use subprocess.check_output() in Python? you can see this simple demo:

py2.py:

import sys
print sys.argv

py3.py:

import subprocess
py2output = subprocess.check_output(['python', 'py2.py', '-i', 'test.txt'])
print('py2 said:', py2output)

Running it:

$ python3 py3.py
py2 said: b"['py2.py', '-i', 'test.txt']\n"

UPDATE:

I think your problem it that you need to specify/set the correct folder path before running your python script. For example:

Consider you have the following folder structure:

/root/project/script.py
/root/project/data/file.txt

If in your python script you load a file using a relative path like ./data/file.txt, you need to run your script inside the project folder. If you run it in the root folder, like this:

/root$ python project/script.py

the script fails, because it tries to find the data/file.txt inside the root folder. You can use the cd command to change the current directory before running your python script. You can do it while calling the os.system, like this:

os.system("cd project && python script.py") # for my example case
0

whereever you call your python script from, all relative paths in your script will be based on. i.e. you called the script from its project folder in the first image, so the links to project_folder/tf_files/... were working, whereas you lateron called it from elsewhere, so that the symbolic links were messed up. your script tried to find elsewhere/tf_files/... but that subfolder does not exist.

you could edit the script so all paths are always abolute (starting with /home/...), then there is no way of confusing the

FloMei
  • 66
  • 4