Running headless Ilastik from Windows

Hi,

I’m trying to run ilastik in headless mode from Windows command window, but got python missing DLL errors. For simplicity I tried with simple Pixel classifier, but my goal is to run it for boundary based segmentation (MultiCut) which cannot run through Fiji.

run-ilastik.bat --headless --project="E:\Test\PixelClassifier_v1.ilp" --export_source="Probabilities" E:\Test\G3New40.h5

  File "<frozen importlib._bootstrap>", line 983 in _find_and_load
  ...
WARNING 2020-10-13 12:37:21,531 opDetectMissingData 14988 26052 Could not import dependency 'sklearn' for SVMs
INFO ilastik_main: Starting ilastik from "C:\Program Files\ilastik-1.3.3post1".
Starting ilastik from "C:\Program Files\ilastik-1.3.3post1".
INFO ilastik_main: Resetting lazyflow thread pool with 20 threads.
INFO ilastik_main: Configuring lazyflow RAM limit to 146.5GiB
INFO lazyflow.utility.memory: Available memory set to 146.5GiB
Windows fatal exception: code 0xc0000139
....
....
ImportError: DLL load failed: The specified procedure could not be found.

(I tried it with versions 1.3.3post1, 1.3.3post3, 1.04b7)

Any hint would be appreciated.
Also, does anyone have example WINDOWS script that runs ilastik in headless mode ?

Thanks
Ofra

Hi @Ofra_Golani,

good to see you back on ilastik! Just one point to maybe consider, the run_ilastik.bat short-circuits the ilastik.exe, so using this instead might already do the trick. My theory is that ilastik is picking up some other version of a library due to insufficient path setup (that is supposed to happen in ilastik.exe). I understand that it is very user-unfriendly to keep it there - we haven’t cleaned that up yet.

1 Like

Thanks @k-dominik

Indeed switching to ilastik.exe solved the problem.

So the following lines run ilastik pixel classifier and Multicut headless on a single file in Windows bat file:

call "C:\Program Files\ilastik-1.3.3post3\ilastik.exe" --headless --project="E:\Test\PixelClassifier_v1.ilp" --export_source="Probabilities" --output_format=hdf5 --output_filename_format={dataset_dir}/{nickname}_{result_type}.h5 E:\Test\G3New40.h5

call "C:\Program Files\ilastik-1.3.3post3\ilastik.exe" --headless --project="E:\Test\Multicut_v1post1.ilp" --raw_data="E:\Test\G3New40.h5" --probabilities="E:\Test\G3New40_Probabilities.h5" --export_source="Multicut Segmentation" --output_format=hdf5 --output_filename_format={dataset_dir}/{nickname}_{result_type}.h5

and the full bat file that process all files in a given folder is:

:: RunIlastikHeadless.bat
:: 
:: Run Ilastik Pixel Classifier followed by Ilastik boundary based segmentation on all files in a given folder
:: 
:: Usage:  RunIlastikHeadless INPUT_PATH
::

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS

:: Setting parameters
set PATH_TO_ILASTIK="C:\Program Files\ilastik-1.3.3post3\ilastik.exe"
set PIXEL_CLASSIFIER="E:\Test\PixelClassifier_v1.ilp"
set MULTICUT_CLASSIFIER="E:\Test\Multicut_v1.ilp"
set OUTPUT_FILENAME_FORMAT="{dataset_dir}/results/{nickname}_{result_type}.h5"
set DEFAULT_FILE_EXTENSION="*.h5"

set me=%~n0
set INPUT_PATH=%~1
set FILE_EXTENSION=%~2

IF "%INPUT_PATH%"=="" (
	ECHO Usage: %me% InputFolder [Extension]
	EXIT /B 1
)
IF NOT EXIST "%INPUT_PATH%" (
    ECHO %me%: file not found - %INPUT_PATH% >&2
    EXIT /B 1
)

IF NOT EXIST "%INPUT_PATH%\results" ( mkdir %INPUT_PATH%\results )

IF "%FILE_EXTENSION%"=="" (	set FILE_EXTENSION=%DEFAULT_FILE_EXTENSION% )

FOR %%I IN (%INPUT_PATH%\%FILE_EXTENSION%) DO (
	@ECHO Processing %%I 
	
	call %PATH_TO_ILASTIK% --headless --project="%PIXEL_CLASSIFIER%" --export_source="Probabilities" --output_format=hdf5 --output_filename_format=%OUTPUT_FILENAME_FORMAT% "%%I"
	call %PATH_TO_ILASTIK% --headless --project=%MULTICUT_CLASSIFIER% --raw_data="%%I" --probabilities=%INPUT_PATH%\results\\"%%~nI"_Probabilities.h5 --export_source="Multicut Segmentation" --output_format=hdf5 --output_filename_format=%OUTPUT_FILENAME_FORMAT%
)

@ECHO ON
1 Like

Hi @Ofra_Golani,

cool that it works now, and thank you very much for sharing your awesome batch script! This looks incredibly useful and I don’t know if posting it here is visible enough. I have started a discussion on github to find the right place/format for such contributions. Do you have any thoughts on this?

Cheers
Dominik