게시글
질문&답변
2024.07.09
안녕하세요 train evaluate부분 질문드립니다
(사진)안녕하세요 답변감사합니다 eval문제가 또발생한거같네요 WARNING:tensorflow:Detecting that an object or model or tf.train.Checkpoint is being deleted with unrestored values. See the following logs for the specific values in question. To silence these warnings, use status.expect_partial(). See https://www.tensorflow.org/api_docs/python/tf/train/Checkpoint#restorefor details about the status object returned by the restore function.이런 문제가 떠서import numpy as npimport skimage.io as iofrom keras.preprocessing.image import ImageDataGeneratorfrom model import UNET_ISBI_2012from absl import flagsfrom absl import appimport osflags.DEFINE_string('checkpoint_path', default='saved_model_isbi_2012/unet_model.ckpt',help='path to a directory to restore checkpoint file')flags.DEFINE_string('test_dir', default='isbi_2012_test_result', help='directory which test prediction result saved')flags.DEFINE_integer('num_classes', default=1, help='number of prediction classes')FLAGS = flags.FLAGS# set configuration valuebatch_size = 1total_test_image_num = 30# normalize ISBI-2012 datadef normalize_isbi_2012(input_images):# 0~255 -> 0.0~1.0input_images = input_images / 255return input_images# make prediction maskdef create_mask(pred_mask):pred_mask = np.where(pred_mask > 0.5, 1, 0)return pred_mask[0]# make test data generatordef make_test_generator(batch_size):image_gen = ImageDataGenerator()# set image and mask same augmentation using same seedimage_generator = image_gen.flow_from_directory(directory='./isbi_2012/preprocessed',classes=['test_imgs'],class_mode=None,target_size=(512, 512),batch_size=batch_size,color_mode='grayscale',seed=1)for batch_images in image_generator:batch_images = normalize_isbi_2012(batch_images)yield batch_imagesdef main(_):# check if checkpoint path exists# if not os.path.exists(FLAGS.checkpoint_path):# print('checkpoint file is not exists!')# exit()# create UNET modelunet_model = UNET_ISBI_2012(FLAGS.num_classes)# restore latest checkpointstatus = unet_model.load_weights(FLAGS.checkpoint_path)status.expect_partial() # Ignore warnings about incomplete restorationprint(f'{FLAGS.checkpoint_path} checkpoint is restored!')# make generatortest_generator = make_test_generator(batch_size)# check total image numprint('total test image :', total_test_image_num)# save test prediction result to png fileif not os.path.exists(os.path.join(os.getcwd(), FLAGS.test_dir)):os.mkdir(os.path.join(os.getcwd(), FLAGS.test_dir))for image_num, test_image in enumerate(test_generator):if image_num >= total_test_image_num:breakpred_mask = unet_model.predict(test_image)# Ensure the mask has three channelsoutput_image = create_mask(pred_mask)output_image = np.stack((output_image,) * 3, axis=-1) # Convert to uint8output_image = (output_image * 255).astype(np.uint8)output_image_path = os.path.join(os.getcwd(), FLAGS.test_dir, f'{image_num}_result.png')io.imsave(output_image_path, output_image)print(output_image_path + ' saved!')if __name__ == '__main__':app.run(main) 이렇게바꿧더니 결과사진이 이상하게 나오네요 ㅠ 맨위에 직선같은게 사진 결과입니다
- 0
- 3
- 348
질문&답변
2024.05.10
안녕하세요 train evaluate부분 질문드립니다
(사진)(위사진 저장된 save file)train부분 에러 train_isbi_2012.py:177: UserWarning: Model.fit_generator is deprecated and will be removed in a future version. Please use Model.fit, which supports generators. 이거를 Model.fit로 바꿔야하나요? I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX cpu로 돌아가고있는 뜻같은데 gpu를 따로쓰는방법이있나요? evaluate 부분 에러 Found 30 images belonging to 1 classes.1/1 [==============================] - 1s 955ms/stepevaluate_isbi_2012.py:85: UserWarning: C:\Users\Administrator\Desktop\UNET-tf2-main\isbi_2012_test_result\0_result.png is a low contrast imageio.imsave(output_image_path, create_mask(pred_mask))Traceback (most recent call last):File "evaluate_isbi_2012.py", line 89, in app.run(main)File "D:\anaconda\envs\tfunet\lib\site-packages\absl\app.py", line 308, in runrunmain(main, args)File "D:\anaconda\envs\tfunet\lib\site-packages\absl\app.py", line 254, in runmainsys.exit(main(argv))File "evaluate_isbi_2012.py", line 85, in mainio.imsave(output_image_path, create_mask(pred_mask))File "D:\anaconda\envs\tfunet\lib\site-packages\skimage\io\_io.py", line 143, in imsavereturn call_plugin('imsave', fname, arr, plugin=plugin, **plugin_args)File "D:\anaconda\envs\tfunet\lib\site-packages\skimage\io\manage_plugins.py", line 207, in call_pluginreturn func(*args, **kwargs)File "D:\anaconda\envs\tfunet\lib\site-packages\imageio\v2.py", line 397, in imwritereturn file.write(im, **kwargs)File "D:\anaconda\envs\tfunet\lib\site-packages\imageio\plugins\pillow.py", line 405, in writeraise ValueError("Can't write images with one color channel.")ValueError: Can't write images with one color channel.WARNING:tensorflow:Detecting that an object or model or tf.train.Checkpoint is being deleted with unrestored values. See the following logs for the specific values in question. To silence these warnings, use status.expect_partial(). See https://www.tensorflow.org/api_docs/python/tf/train/Checkpoint#restorefor details about the status object returned by the restore function.W0510 18:14:50.947670 15764 checkpoint.py:205] Detecting that an object or model or tf.train.Checkpoint is being deleted with unrestored values. See the following logs for the specific values in question. To silence these warnings, use status.expect_partial(). See https://www.tensorflow.org/api_docs/python/tf/train/Checkpoint#restorefor details about the status object returned by the restore function.WARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).optimizer._iterationsW0510 18:14:50.952654 15764 checkpoint.py:214] Value in checkpoint could not be found in the restored object: (root).optimizer._iterationsWARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).optimizer._learning_rateW0510 18:14:50.953642 15764 checkpoint.py:214] Value in checkpoint could not be found in the restored object: (root).optimizer._learning_rateWARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).optimizer._variables.1W0510 18:14:50.954640 15764 checkpoint.py:214] Value in checkpoint could not be found in the restored object: (root).optimizer._variables.1WARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).optimizer._variables.2W0510 18:14:50.955644 15764 checkpoint.py:214] Value in checkpoint could not be found in the restored object: (root).optimizer._variables.2WARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).optimizer._variables.3W0510 18:14:50.955644 15764 checkpoint.py:214] Value in checkpoint could not be found in the restored object: (root).optimizer._variables.3WARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).optimizer._variables.4W0510 18:14:50.956632 15764 checkpoint.py:214] Value in checkpoint could not be found in the restored object: (root).optimizer._variables.4WARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).optimizer._variables.5W0510 18:14:50.957636 15764 checkpoint.py:214] Value in checkpoint could not be found in the restored object: (root).optimizer._variables.5(optimizer._variables.96까지 에러,글자수 제한 있어 이렇게 씁니다) 안녕하세요 말하신데로 train evaluate 다바꿔서 5장 저장다하고 ckpt 로 교체해서 evaluate_isbi_2012.py 실행하니 이런문제가 뜨네요.감사합니다
- 0
- 3
- 348