External Email - Use Caution        

Hi Stefano and thanks for your response.

I have copied the output from my terminal window below, highlighting your instructed inputs.

When you say "SAMSEG requires Tensorflow", I am still trying to find out if Tensorflow was incorporated into "freesurfer_7.2.0_amd64.deb". (Installed 2/8/2022)
If not, do I have to import and install it from somewhere else? (if so, then where/how?)

A colleague suggested I check where "tensor" might be found

developer@developer-VirtualBox:~$ env | grep -i tensor
(... returned nothing)

developer@developer-VirtualBox:~$ grep -i tensor $FREESURFER_HOME/bin/*
(... returned several instances of the term "tensor", but really only in "trac-preproc" / "orientLAS" / "dt_recon" / dmri_tensoreig" / "dmri_ac.sh")
(these make a certain amount of sense for the diffusion MRI routines)


As far as running this on another host, I am using the Virtual Machine as directed to from the Freesurfer Wiki:
VM_67 - Free Surfer Wiki (harvard.edu)

I am running the VM on a Windows 10 Pro computer which is just a little over 2 years old, and since the standard Freesurfer segmentation and the basic SAMSEG cross-sectional routines both work just fine, I don't know if the age of this system is truly the issue here.  This "illegal instruction (core dumped)" issue only happens when I try to use the --lesion flag.


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Device secifications: (XXX's substituted for security reasons)

Device name DESKTOP-XXXXXX
Processor Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz   3.60 GHz
Installed RAM 32.0 GB (31.8 GB usable)
Device ID CA89F214-3517-4D16-8A5D-XXXXXX
Product ID 00330-53014-11941-AAOEM
System type 64-bit operating system, x64-based processor


Windows specifications

Edition Windows 10 Pro
Version 21H2
Installed on ‎11/‎12/‎2020
OS build 19044.1526
Experience Windows Feature Experience Pack 120.2212.4170.0

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Here is the output text-capture that I am seeing after I followed your instructions.  Yes, the error is replicated...


-------- freesurfer-linux-ubuntu18_x86_64-7.2.0-20210721-aa8f76b --------
Setting up environment for FreeSurfer/FS-FAST (and FSL)
FREESURFER_HOME   /usr/local/freesurfer/7.2.0
FSFAST_HOME       /usr/local/freesurfer/7.2.0/fsfast
FSF_OUTPUT_FORMAT nii.gz
SUBJECTS_DIR      /usr/local/freesurfer/7.2.0/subjects
MNI_DIR           /usr/local/freesurfer/7.2.0/mni
developer@developer-VirtualBox:~$ fspython
Python 3.6.8 (default, Apr 10 2020, 02:08:58) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Illegal instruction (core dumped)
developer@developer-VirtualBox:~$ 


Thanks in advance for any further insights/directions.

-Randy

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

-----Original Message-----
From: Cerri, Stefano <SCERRI@mgh.harvard.edu>
To: freesurfer@nmr.mgh.harvard.edu <freesurfer@nmr.mgh.harvard.edu>
Cc: daedalus39@aol.com <daedalus39@aol.com>
Sent: Sun, Feb 27, 2022 11:22 am
Subject: Re: [Freesurfer] SAMSEG "lesion" (Illegal instruction) ~ running VM_67

Hi Randy,

Your run_samseg syntax is correct and yes, the "lesion" version of SAMSEG requires Tensorflow.

The "illegal instruction" error is most probably related to an incompatible version of Tensorflow with your CPU instruction set. You should be able to replicate the error by typing:

  1. fspython
  1. import tensorflow

Would you be able to run SAMSEG lesion on another host machine (possibly a relatively new one) and let us know if the error persists?

Best,
Stefano

Dear R,
Yes, I have tried to run "samseg_run" from the command line (I've repeated my syntax below).? I have looked both under the directory where the command ran that produced the ?Illegal instruction? error.? No crash file (a logfile?) or a "core" file were written.? I also looked?/var/crash but that folder was empty too.

As I mentioned, I'm a LINUX novice.? I'm even more of a novice with regard to Python. However, I did take a quick at the code looking for any mention of tensorflow, and have copied the python script text as it exists below.? I have highlighted the only mention of tensorflow below.? Does this look like you expect it?
Has tensorflow actually been incorporated into the VM???
Note that I have been able to successfully run Samseg without the --lesion flag and the process works just fine (about 20min runtime, aseg looks just fine in Freeview)
Again, thanks for any guidance you can provide.
-Randy
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

#!/usr/bin/env python
import osimport sysimport jsonimport scipy.ioimport freesurfer as fsimport freesurfer.samseg as samseg

# ------ Parse Command Line Arguments ------
parser = fs.utils.ArgumentParser()
default_threads = int(os.environ.get('OMP_NUM_THREADS', 1))
# requiredparser.add_argument('-o', '--output', metavar='DIR', dest='outputDirectory', help='Output directory.', required=True)parser.add_argument('-i', '--input', nargs='+', action='extend', metavar='FILE', dest='inputFileNames', help='Input image(s).', required=True)# optional processing optionsparser.add_argument('-m', '--mode', nargs='+', help='Output basenames for the input image mode.')parser.add_argument('--threads', type=int, default=default_threads, help='Number of threads to use. Defaults to current OMP_NUM_THREADS or 1.')parser.add_argument('--reg-only', action='store_true', default=False, help='Only perform initial affine registration.')parser.add_argument('-r', '--reg', metavar='FILE', help='Skip initial affine registration and read transform from file.')parser.add_argument('--init-reg', metavar='FILE', help='Initial affine registration.')parser.add_argument('-a', '--atlas', metavar='DIR', help='Point to an alternative atlas directory.')parser.add_argument('--gmm', metav
 ar='FILE', help='Point to an alternative GMM file.')parser.add_argument('--ignore-unknown', action='store_true', help='Ignore final priors corresponding to unknown class.')parser.add_argument('--options', metavar='FILE', help='Override advanced options via a json file.')parser.add_argument('--pallidum-separate', action='store_true', default=False, help='Move pallidum outside of global white matter class. Use this flag when T2/flair is used.')# optional lesion optionsparser.add_argument('--lesion', action='store_true', default=False, help='Enable lesion segmentation (requires tensorflow).')parser.add_argument('--threshold', type=float, default=0.3, help='Lesion threshold for final segmentation. Lesion segmentation must be enabled.')parser.add_argument('--samples', type=int, default=50, help='Number of samples for lesion segmentation. Lesion segmentation must be enabled.')parser.add_argument('--burnin', type=int, default=50, help='Number of burn-in samples for lesion segmentation. Les
 ion segmentation must be enabled.')parser.ad!
 d_argume
nt('--lesion-pseudo-samples', nargs=2, type=float, default=[500, 500], help='Lesion pseudo samples mean and variance.')parser.add_argument('--lesion-rho', type=float, default=50, help='Lesion ratio.')parser.add_argument('--lesion-mask-structure', default='Cortex', help='Intensity mask brain structure. Lesion segmentation must be enabled.')parser.add_argument('--lesion-mask-pattern', type=int, nargs='+', help='Lesion mask list (set value for each input volume): -1 below lesion mask structure mean, +1 above, 0 no mask. Lesion segmentation must be enabled.')# optional debugging optionsparser.add_argument('--history', action='store_true', default=False, help='Save history.')parser.add_argument('--save-posteriors', nargs='*', help='Save posterior volumes to the "posteriors" subdirectory.')parser.add_argument('--save-probabilities', action='store_true', help='Save final modal class probabilities to "probabilities" subdirectory.')parser.add_argument('--showfigs', action='store_true', defaul
 t=False, help='Show figures during run.')parser.add_argument('--save-mesh', action='store_true', help='Save the final mesh in template space.')parser.add_argument('--save-warp', action='store_true', help='Save the image->template warp field.')parser.add_argument('--movie', action='store_true', default=False, help='Show history as arrow key controlled time sequence.')
args = parser.parse_args()
# ------ Initial Setup ------
# Make sure freesurfer has been sourcedif not fs.fshome():? ? fs.fatal('FREESURFER_HOME must be set')
# Start the process timertimer = fs.utils.Timer()
# Create the output folderos.makedirs(args.outputDirectory, exist_ok=True)
# Specify the maximum number of threads the GEMS code will usesamseg.setGlobalDefaultNumberOfThreads(args.threads)
# Remove previous cost logcostfile = os.path.join(args.outputDirectory, 'cost.txt')if os.path.exists( costfile ):? ? os.remove( costfile )?
# Get the atlas directoryatlasDir = os.environ.get('SAMSEG_DATA_DIR')if args.atlas:? ? atlasDir = args.atlasif not atlasDir:? ? # Altas defaults? ? if args.lesion:? ? ? ? defaultAtlas = '20Subjects_smoothing2_down2_smoothingForAffine2_lesion'? ? else:? ? ? ? defaultAtlas = '20Subjects_smoothing2_down2_smoothingForAffine2'? ? atlasDir = os.path.join(fs.fshome(), 'average', 'samseg', defaultAtlas)
# Setup the visualization toolvisualizer = samseg.initVisualizer(args.showfigs, args.movie)
# ------ Prepare Samseg Parameters ------
# Load user options from a JSON fileuserModelSpecifications = {}userOptimizationOptions = {}if args.options:? ? with open(args.options) as f:? ? ? ? userOptions = json.load(f)? ? if userOptions.get('modelSpecifications') is not None:?? ? ? ? userModelSpecifications = userOptions.get('modelSpecifications')? ? if userOptions.get('optimizationOptions') is not None:?? ? ? ? userOptimizationOptions = userOptions.get('optimizationOptions')
# Check if --save-posteriors was specified without any structure search stringif args.save_posteriors is not None and len(args.save_posteriors) == 0:? ? savePosteriors = Trueelse:? ? savePosteriors = args.save_posteriors
# ------ Run Samseg ------
samseg_kwargs = dict(? ? imageFileNames=args.inputFileNames,? ? atlasDir=atlasDir,? ? savePath=args.outputDirectory,? ? userModelSpecifications=userModelSpecifications,? ? userOptimizationOptions=userOptimizationOptions,? ? targetIntensity=110,? ? targetSearchStrings=[ 'Cerebral-White-Matter' ],? ? visualizer=visualizer,? ? saveHistory=args.history,? ? saveMesh=args.save_mesh,? ? savePosteriors=savePosteriors,? ? saveWarp=args.save_warp,? ? modeNames=args.mode,? ? pallidumAsWM=(not args.pallidum_separate),? ? saveModelProbabilities=args.save_probabilities,? ? gmmFileName=args.gmm,? ? ignoreUnknownPriors=args.ignore_unknown,)
if args.lesion:
? ? # If lesion mask pattern is not specified, assume inputs are T1-contrast? ? lesion_mask_pattern = args.lesion_mask_pattern? ? if lesion_mask_pattern is None:? ? ? ? lesion_mask_pattern = [0] * len(args.inputFileNames)? ? ? ? print('Defaulting lesion mask pattern to %s' % str(lesion_mask_pattern))
? ? # Delay import until here so that tensorflow doesn't get loaded unless needed? ? from freesurfer.samseg.SamsegLesion import SamsegLesion? ? samseg = SamsegLesion(**samseg_kwargs,? ? ? ? numberOfPseudoSamplesMean=args.lesion_pseudo_samples[0],? ? ? ? numberOfPseudoSamplesVariance=args.lesion_pseudo_samples[1],? ? ? ? rho=args.lesion_rho,? ? ? ? intensityMaskingSearchString=args.lesion_mask_structure,? ? ? ? intensityMaskingPattern=lesion_mask_pattern,? ? ? ? numberOfBurnInSteps=args.burnin,? ? ? ? numberOfSamplingSteps=args.samples,? ? ? ? threshold=args.threshold? ? )
else:? ? samseg = samseg.Samseg(**samseg_kwargs)
_, _, _, optimizationSummary = samseg.segment(? ? costfile=costfile,? ? timer=timer,? ? transformFile=args.reg,? ? initTransformFile=args.init_reg,? ? reg_only=args.reg_only)
# Save a summary of the optimization processwith open(costfile, 'a') as file:? ? for multiResolutionLevel, item in enumerate(optimizationSummary):? ? ? ? file.write('atlasRegistrationLevel%d %d %f\n' % (multiResolutionLevel, item['numberOfIterations'], item['perVoxelCost']))
timer.mark('run_samseg complete')
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PS. Repeating the syntax from below.
run_samseg --input /home/developer/subjects_new/o_ADNI_002_S_4654__MRI-m072__LMCI-LMCI__20180522__T30-acc_orig__S689126_I1001975.nii /home/developer/subjects_new/rT1_o_ADNI_002_S_4654__MRI-m072__LMCI-LMCI__20180522__T2-FLAIR__S689135_I1001984.nii --pallidum-separate --lesion --lesion-mask-pattern 0 1 --output /home/developer/subjects_new/Lesion-test/


-----Original Message-----
From: fsbuild <fsbuild@contbay.com>
To: freesurfer@nmr.mgh.harvard.edu
Cc: daedalus39@aol.com
Sent: Thu, Feb 24, 2022 5:15 pm
Subject: Re: [Freesurfer] SAMSEG "lesion" (Illegal instruction) ~ running VM_67

Hello Randy,
I think the expectation is for users to run ?samseg? from the command line. ?(The samseg script is a front-end you run with command line options, e.g., ?help, which calls samseg_run that in turn runs the samseg python scripts in the freesurfer python distribution which includes the tensorflow code).
I can?t speak to the validity of the command + options causing the crash, but I would look too see if a ?core? file was written in the directory where the command ran that produced the ?Illegal instruction? error and subsequent crash. ?The core file might also be under /var/crash. ?If you have the core file you could name it something unique and try uploading it to?https://secure-web.cisco.com/1_8ugcIT497YTUyY1vRRMjZbWfONaiAbR1P1Zg9-6zNbgUF_nqdNpH5IkjDRGIBnRgkeymgi17VUaKZZtvSteYJHtbAzdHwJ-ZFuNUEKFvUYllMIfuKFt_TYxmPnYvE0kZsxksjMWlCFeZ0BtBLLYdcPSgze4QZ_08HI5pmGrhOks3kznF06Y51NQkC-1is6UmZRsyIu9BdtoZrqWH6yB_tj0xHbOP9ZP2mxnhHC42-V0CdDffxKxsXQvIJ7N8gf75oN1anvwYhugReEzKkv2FVmdURFYOfKkwk5q4Ivr9iS2lKqdZe_QwPgWrnBUmbz8K3-CmecHut4ttLt-fwkNhQ/https%3A%2F%2Fgate.nmr.mgh.harvard.edu%2Ffiledrop2%2F?for someone to look at.
- R.


On Feb 24, 2022, at 11:58, daedalus39@aol.com wrote:
????????External Email - Use Caution????????
Following up on yesterday's email:
I looked up the help text for SAMSEG on the VM (?run_samseg ?help?).??The flag for --lesion indicates that Tensorflow is required.???? --lesion??????? Enable lesion segmentation (requires tensorflow).?I'm not sure is tensorflow is installed in VM_67, but "which tensorflow" returned nothing.? While my question only reported the ?core dump? and a request to check the syntax, I did ask if the ?lesion? flag was implemented in the VM.??
If it's not installed in VM_67, would you be able to offer some guidance as to where the safest download site is and some suggestions as to how to install it?

Sincerely,
-Randy

-----Original Message-----
From: daedalus39@aol.com
To: freesurfer@nmr.mgh.harvard.edu <freesurfer@nmr.mgh.harvard.edu>
Sent: Wed, Feb 23, 2022 1:19 pm
Subject: SAMSEG "lesion" (Illegal instruction) ~ running VM_67

Dear Experts,
I am trying to test SAMSEG "lesion" on VM_67 and after I entered:
run_samseg --input /home/developer/subjects_new/o_ADNI_002_S_4654__MRI-m072__LMCI-LMCI__20180522__T30-acc_orig__S689126_I1001975.nii /home/developer/subjects_new/rT1_o_ADNI_002_S_4654__MRI-m072__LMCI-LMCI__20180522__T2-FLAIR__S689135_I1001984.nii --pallidum-separate --lesion --lesion-mask-pattern 0 1 --output /home/developer/subjects_new/Lesion-test/

...I got the following error
Illegal instruction (core dumped)


Is there anything glaringly wrong in my instruction/input phrase?
Is SAMSEG "lesion" implemented in the new VM?? I was able to test the "basic" SAMSEG with a single T1 earlier this morning (it ran just fine)
Thanks in advance for any help.
-Randy_______________________________________________
Freesurfer mailing list
Freesurfer@nmr.mgh.harvard.edu
https://secure-web.cisco.com/1ajCHs20Ntg5vd9AD9I6GP72nyffMyNANWVvUGOngP_c0acAh69UqWUgMHsVdUJPPw6V-jdxSE8Bv3pMtpmpbmhckwOsjRl7kK7QTTXDWbDuug2iazQJmjobCOo4cDPKvES_4Y8bT_ZwpgRK3EbHwj9EUIrbcYkWgRsbyyEU946VLAqQy0xNaYqAsQ1gDrfHI8-keBDroWyejutKjeoZeeiPn9uVRuSPsO_o5FpyWBzxLwObGkKIL_iPx8gH4S9eY7_gxOZvEunVbngAs4wwLjv6RJQ4zqPEtV40rEciaRZdew3pFmA50yhfxWto37C-yWzjjscKvT_B_WLc7oHErXA/https%3A%2F%2Fmail.nmr.mgh.harvard.edu%2Fmailman%2Flistinfo%2Ffreesurfer

-------------- next part --------------
An HTML attachment was scrubbed...
URL: MailScanner has detected a possible fraud attempt from "secure-web.cisco.com" claiming to be http://mail.nmr.mgh.harvard.edu/pipermail/freesurfer/attachments/20220226/7826a479/attachment-0001.html

------------------------------

_______________________________________________
Freesurfer mailing list
Freesurfer@nmr.mgh.harvard.edu
MailScanner has detected a possible fraud attempt from "secure-web.cisco.com" claiming to be https://mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer

End of Freesurfer Digest, Vol 216, Issue 39
*******************************************
_______________________________________________
Freesurfer mailing list
Freesurfer@nmr.mgh.harvard.edu
MailScanner has detected a possible fraud attempt from "secure-web.cisco.com" claiming to be https://mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer