Problem with command line magic

I have a code that runs under windows command line. The code is part of a ML algorithm that trains a network and then generates test images sequentially. However when I try to run the exact same code in IPython kernel it always hang after a while (hang after some test images are generated). When I force the kernel to shut down somehow the remaining images got generated.

in command line:

    python --model_name SRGAN --data_dir Registered_2D_slices\N6-N12 --sample_set APX134M2 --num_epochs 10 --scale_factor 2 --save_dir Models\test_model 


in ipython kernel:

! python --model_name SRGAN --data_dir Registered_2D_slices\N6-N12 --sample_set APX134M2 --num_epochs 10 --scale_factor 2 --save_dir Models\test_model

---------> hangs

This really confuses me because aren’t these two supposed to be the same thing?

Here is the link to the code:

Any help is appreciated.

It sounds like it is running but you aren’t getting the experience you expect.

In place of !python, using the %run IPython magic command documented here will result in a richer experience in the IPython kernel and Jupyter notebooks. In particular stderr is handled much better. Maybe you’ll get better completion notification handling, too?

Minor points:
Those two aren’t necessarily the same thing. Stackoverflow is littered with situations resulting from various installation approaches where which python on the command line and !which python in your IPython would produce different results.

Two minor points:
I was first going to suggest removing the space between ! and the python, but I tested in a few places and it didn’t seem to matter. However, I’d be careful because the shell commands can be overly sensitive to spaces in some versions. And the handling can differ slightly with the shell and IPython. Case in point, a format I was using to save files stopped working in IPython/Jupyter recently and the difference is a space. You now have to use %store foo >a.txt as documented here; with a space after the redirect, it now fails.