cy-xu / cosmic-conn

Cosmic-CoNN: A Cosmic Ray Detection Deep-Learning Framework, Dataset, and Toolkit
GNU General Public License v3.0
23 stars 3 forks source link

Error with calling Cosmic-conn from py script on Gemini GMOS 2D spec #12

Open Karuntg opened 1 year ago

Karuntg commented 1 year ago

Hi Chengyuan I tried Cosmic-conn from within a script based on the example you had given. I am running this on the same Gemini GMOS 2D spec, as in my earlier issue.I have copied the code below for ref. The script reads and loads the data now, but the error I get is:

[W NNPACK.cpp:51] Could not initialize NNPACK! Reason: Unsupported hardware.

I don't have GPU on this machine, but think Cosmic-conn automatically reverts to the slower CPU version?

pls let me know thx karun

Here is my simple script:

#

script to run cosmic-conn on command line

#

import numpy as np from astropy import * import astropy.io.fits as pyfits from astropy.stats import sigma_clipped_stats

read in the transf 2d spec

datadir = '/copiapo1/karun/Cosmic_COnn/cr_tst/' fits = 'tgsqgsS20221115S0065.fits' sci = 2 # extension number of science

read data into array

fits_path = datadir+fits data = pyfits.getdata(fits_path,ext=sci) head = pyfits.getheader(fits_path, ext=sci)

shap = data.shape print(shap) rows,cols = shap[0],shap[1] print('Size of 2D spec: ',rows,cols)

from cosmic_conn import init_model

initialize a Cosmic-CoNN model

cr_model = init_model("ground_imaging")

the model outputs a CR probability map in np.float32

data = data.astype(np.float32) cr_prob = cr_model.detect_cr(data)

convert the probability map to a boolean mask with a 0.5 threshold

cr_mask = cr_prob > 0.5

cy-xu commented 1 year ago

Hi Karun,

Your code looks good, and the "[W NNPACK.cpp:51] Could not initialize NNPACK! Reason: Unsupported hardware." message is not an error but more like a warning.

NNPACK is for hardware acceleration and if you were using an unsupported CPU like the ARM-based M1 Mac, you would see this message. It's just slower and I have double-checked that you will get identical results.

Similar discussion -- https://discuss.pytorch.org/t/bug-w-nnpack-cpp-80-could-not-initialize-nnpack-reason-unsupported-hardware/107518/13

So you don't have to worry about your hardware or this message if you are not processing thousands of files, i.e., if performance is not a concern. I hope this helps.

Best, CY

Karuntg commented 1 year ago

Hi CY, thanks much, good to know. With this initial testing, once i get more familiar with Cosmic-cnn, i plan to run it on multiple files on a cluster with GPU acceleration thx karun