yahoo / open_nsfw

Not Suitable for Work (NSFW) classification using deep neural network Caffe models.
BSD 2-Clause "Simplified" License
5.86k stars 1.05k forks source link

not preloading model when started from node with child process #84

Closed lxknvlk closed 5 years ago

lxknvlk commented 5 years ago

The script stops at this line

# Pre-load caffe model.
nsfw_net = caffe.Net(model_def, pretrained_model, caffe.TEST)

Everything else in python works fine. And the script run directly works fine too. Why it is not working when called from child-process?

When i run it from a node app like this

        const cp = require("child_process")
        const spawn = cp.spawn;
    const pythonProcess = spawn('python',['/home/ubuntu/classify.py']);

    pythonProcess.stdin.write(req.body.image, function(err){
        pythonProcess.stdin.end();
    });

    pythonProcess.stdout.on('data', (data) => {
            console.log("message from python:" + data)
        });

    pythonProcess.stdout.on("end", (data) => {
        console.log("end received data: " + data);
        res.status(200);
        res.end(); 
    });
lxknvlk commented 5 years ago

I have added pythonProcess.stderr.pipe(process.stderr); to my nodejs app and then i was able to see errors from python script, and fix it.