luannd/MinutiaeNet

Error when training CoarseNet_train.py

Closed this issue · 10 comments

when I training CoarseNet_train.py, (the image size is 512*512 ,batchsize=2 ),The following error occurred:tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape[2,64,512,512] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
GPU :NVIDIA GeForce GTX TITAN X

This error is the result of not having enough GPU memory. What is your GPU memory size? I suggest you use small image size to train or set batchsize to 1 if you prefer big size input.

Does training make sense when set batchsize to 1?

It depends on your goal. You can reduce input size (and increase batch size) by cropping your images.

I can't open the link for the pretrained models for CoarseNet and FineNet ?

what the image size is , you used when you were training

As specified in the code, input size is 400 but you can use any size which is suitable for your machine.
I already created model links in Dropbox besides Google drive:
CoarseNet: https://www.dropbox.com/s/gppil4wybdjcihy/CoarseNet.h5?dl=0
FineNet: https://www.dropbox.com/s/k7q2vs9255jf2dh/FineNet.h5?dl=0

I have cropped image to 400*400,but when training,and running tolabel2mnt in evaluate_trainingThe following error occurred:
File "d:\wu\MinutiaeNet\CoarseNet\CoarseNet_utils.py", line 289, in label2mnt
mnt_list = np.array(zip(mnt_sparse.row, mnt_sparse.col), dtype=np.int32)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'zip'

That would be a Python 3 error as the code is for python 2. zip function returns generators.
You will need to change to code to the following:
mnt_list = np.array([*map(tuple,zip(mnt_sparse.row, mnt_sparse.col))])

You can also check my fork for Python3 version of the code.

I am running the demo_CoarseNet notebook on pyhton 3 by incorporating changes as the uploaded code was for python 2. i am getting following error:


IndexError Traceback (most recent call last)
Cell In[3], line 15
10 mkdir(output_dir + '/' + set_name + '/OF_results/')
12 logging.info("Predicting "%s":" % (set_name))
---> 15 main_net_model = CoarseNetmodel((None, None, 1), CoarseNet_path, mode='deploy')
17 # ====== Load FineNet to verify
18 if isHavingFineNet == True:

File ~/FingerprintImageQuality-main/MiDeCon/CoarseNet/CoarseNet_model.py:168, in CoarseNetmodel(input_shape, weights_path, mode)
161 filter_img_real = Conv2D(filters_cos.shape[3],(filters_cos.shape[0],filters_cos.shape[1]),
162 weights=[filters_cos, np.zeros([filters_cos.shape[3]])], padding='same',
163 name='enh_img_real_1')(img_input)
164 filter_img_imag = Conv2D(filters_sin.shape[3],(filters_sin.shape[0],filters_sin.shape[1]),
165 weights=[filters_sin, np.zeros([filters_sin.shape[3]])], padding='same',
166 name='enh_img_imag_1')(img_input)
--> 168 ori_peak = Lambda(ori_highest_peak)(ori_out_1)
169 ori_peak = Lambda(select_max)(ori_peak) # select max ori and set it to 1
171 # Use this function to upsample image

File ~/anaconda3/envs/tenserflow_env/lib/python3.11/site-packages/keras/utils/traceback_utils.py:70, in filter_traceback..error_handler(*args, **kwargs)
67 filtered_tb = _process_traceback_frames(e.traceback)
68 # To get the full stack trace, call:
69 # tf.debugging.disable_traceback_filtering()
---> 70 raise e.with_traceback(filtered_tb) from None
71 finally:
72 del filtered_tb

File ~/FingerprintImageQuality-main/MiDeCon/CoarseNet/CoarseNet_utils.py:224, in ori_highest_peak(y_pred, length)
223 def ori_highest_peak(y_pred, length=180):
--> 224 glabel = gausslabel(length=length,stride=2).astype(np.float32)
225 y_pred = tf.convert_to_tensor(y_pred, np.float32)
226 ori_gau = K.conv2d(y_pred,glabel,padding='same')

File ~/FingerprintImageQuality-main/MiDeCon/CoarseNet/MinutiaeNet_utils.py:132, in gausslabel(length, stride)
130 delta = np.array(np.abs(label - y), dtype=int)
131 delta = np.minimum(delta, length-delta)+length/2
--> 132 return gaussian_pdf[delta]

IndexError: Exception encountered when calling layer "lambda_3" (type Lambda).

arrays used as indices must be of integer (or boolean) type

Call arguments received by layer "lambda_3" (type Lambda):
• inputs=tf.Tensor(shape=(None, None, None, 90), dtype=float32)
• mask=None
• training=None