Search code examples
pythonunity-game-enginetensorflow2.0object-detection

Object detection .exe can't find any file in the saved_model folder


I've trained a model from the object detection zoo, and I now want to run the script in exe form in Unity. I've imported the exe file made with auto-py-to-exe (onefile + windowed) with no folder or file added, the labelmap and the model folder (with some parsing errors but it looks like all the files are there), but when I try to actually run the exe file i get this error

enter image description here

The error is

OSError: SavedModel file does not exist at: .\model\saved_model\\{saved_model.pbtxt|saved_model.pb}

The function use to load the model

def load_model(model_path):
    model = tf.saved_model.load(model_path)
    return model

And the path to the model and labelmap being

model = ".\\130k_model\\saved_model"
labelmap = ".\\labelmap.pbtxt"

All the files and the model folder are at the same level, that's why I'm using .\ at the start of the relative path. This problem also doen't arise when I run the py script directly. All the solutions I found online don't seem to work or are about training via python script. Do you have any idea what am I doing wrong here?


Solution

  • I solved the problem by giving the process the paths to the folders and files directly in Unity like this

    proc = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = "Assets/Plugins/objectdetectorExecutable.exe",
                    Arguments = path + " Assets/Plugins/model/saved_model Assets/Plugins/labelmap.pbtxt",
                    UseShellExecute = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow = true
                }
            };
    

    Obviously the exe now takes 3 arguments instead of only one