작성
·
348
·
수정됨
0
1.앞에 고민올리신 분대로 코드를 바꿔보니 train부분은 돌아가더라고요,5/2000번 이라서 왜그런지는 모르겟으나 너무 느리고 반쯤가다가 멈추더라고요.
2.2000번 다안되서 50번으로 바꿔서 돌려보니 되더라고요(loss 값은 강의만큼 떨어지지는 않지만.. 돌아가긴하네요.) 그리고 앞에 커뮤니티 올리신 분도 비슷한 문제가 있어 https://gist.github.com/solaris33/771639041b8a4500b6d81951d4a2b814
여기있는대로 evaluate구현해보니 Traceback (most recent call last):
File "evaluate_isbi_2012.py", line 89, in <module>
app.run(main)
File "D:\anaconda\envs\tfunet\lib\site-packages\absl\app.py", line 308, in run
runmain(main, args)
File "D:\anaconda\envs\tfunet\lib\site-packages\absl\app.py", line 254, in runmain
sys.exit(main(argv))
File "evaluate_isbi_2012.py", line 66, in main
unet_model.load_weights(FLAGS.checkpoint_path)
File "D:\anaconda\envs\tfunet\lib\site-packages\keras\utils\traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "D:\anaconda\envs\tfunet\lib\site-packages\tensorflow\python\training\py_checkpoint_reader.py", line 31, in error_translator
raise errors_impl.NotFoundError(None, None, error_message)
tensorflow.python.framework.errors_impl.NotFoundError: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for saved_model_isbi_2012/unet_model.ckpt 이런문제가 뜨더라고요..
3.제가 쓰는 파이썬은 3.7.9이고 tensorflow 2.11 을 쓰고 있어요 예전버전쓰니까 이상한 문제가 있다고 train도 구현이 되질않아서요.. 가능하시면 2.11버전에 맞게 코드 변경 부탁드려요.. 몇일을 실랑이 하다가 어떻게 해야될지 몰라 올려보네요..아니면 requirement라도 넣어주시면 감사하겠습니다.
답변 3
0
안녕하세요 답변감사합니다 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 np
import skimage.io as io
from keras.preprocessing.image import ImageDataGenerator
from model import UNET_ISBI_2012
from absl import flags
from absl import app
import os
flags.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 value
batch_size = 1
total_test_image_num = 30
# normalize ISBI-2012 data
def normalize_isbi_2012(input_images):
# 0~255 -> 0.0~1.0
input_images = input_images / 255
return input_images
# make prediction mask
def create_mask(pred_mask):
pred_mask = np.where(pred_mask > 0.5, 1, 0)
return pred_mask[0]
# make test data generator
def make_test_generator(batch_size):
image_gen = ImageDataGenerator()
# set image and mask same augmentation using same seed
image_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_images
def main(_):
# check if checkpoint path exists
# if not os.path.exists(FLAGS.checkpoint_path):
# print('checkpoint file is not exists!')
# exit()
# create UNET model
unet_model = UNET_ISBI_2012(FLAGS.num_classes)
# restore latest checkpoint
status = unet_model.load_weights(FLAGS.checkpoint_path)
status.expect_partial() # Ignore warnings about incomplete restoration
print(f'{FLAGS.checkpoint_path} checkpoint is restored!')
# make generator
test_generator = make_test_generator(batch_size)
# check total image num
print('total test image :', total_test_image_num)
# save test prediction result to png file
if 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:
break
pred_mask = unet_model.predict(test_image)
# Ensure the mask has three channels
output_image = create_mask(pred_mask)
output_image = np.stack((output_image,) * 3, axis=-1)
# Convert to uint8
output_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
(위사진 저장된 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/step
evaluate_isbi_2012.py:85: UserWarning: C:\Users\Administrator\Desktop\UNET-tf2-main\isbi_2012_test_result\0_result.png is a low contrast image
io.imsave(output_image_path, create_mask(pred_mask))
Traceback (most recent call last):
File "evaluate_isbi_2012.py", line 89, in <module>
app.run(main)
File "D:\anaconda\envs\tfunet\lib\site-packages\absl\app.py", line 308, in run
runmain(main, args)
File "D:\anaconda\envs\tfunet\lib\site-packages\absl\app.py", line 254, in runmain
sys.exit(main(argv))
File "evaluate_isbi_2012.py", line 85, in main
io.imsave(output_image_path, create_mask(pred_mask))
File "D:\anaconda\envs\tfunet\lib\site-packages\skimage\io\_io.py", line 143, in imsave
return 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_plugin
return func(*args, **kwargs)
File "D:\anaconda\envs\tfunet\lib\site-packages\imageio\v2.py", line 397, in imwrite
return file.write(im, **kwargs)
File "D:\anaconda\envs\tfunet\lib\site-packages\imageio\plugins\pillow.py", line 405, in write
raise 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._iterations
W0510 18:14:50.952654 15764 checkpoint.py:214] Value in checkpoint could not be found in the restored object: (root).optimizer._iterations
WARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).optimizer._learning_rate
W0510 18:14:50.953642 15764 checkpoint.py:214] Value in checkpoint could not be found in the restored object: (root).optimizer._learning_rate
WARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).optimizer._variables.1
W0510 18:14:50.954640 15764 checkpoint.py:214] Value in checkpoint could not be found in the restored object: (root).optimizer._variables.1
WARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).optimizer._variables.2
W0510 18:14:50.955644 15764 checkpoint.py:214] Value in checkpoint could not be found in the restored object: (root).optimizer._variables.2
WARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).optimizer._variables.3
W0510 18:14:50.955644 15764 checkpoint.py:214] Value in checkpoint could not be found in the restored object: (root).optimizer._variables.3
WARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).optimizer._variables.4
W0510 18:14:50.956632 15764 checkpoint.py:214] Value in checkpoint could not be found in the restored object: (root).optimizer._variables.4
WARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).optimizer._variables.5
W0510 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
안녕하세요~. 반갑습니다.
먼저 수강에 불편을 드려서 죄송합니다ㅠ.
해당 부분 관련해서 예전에 답변을 드렸던 내용이 있는데요.
https://www.inflearn.com/questions/687532/evaluate-isbi-2012-py-%EC%8B%A4%ED%96%89%EA%B4%80%EB%A0%A8-%EB%AC%B8%EC%9D%98%EB%93%9C%EB%A6%BD%EB%8B%88%EB%8B%A4
위에 내용을 정리하면 train_isbi_2012.py 파일과 evaluate_isbi_2012.py 파일들을 아래 파일들로 교체해서 실행해보시겠어요?
https://gist.github.com/solaris33/64feceb48079a2b339ef9f18a6544a74
https://gist.github.com/solaris33/771639041b8a4500b6d81951d4a2b814
첨부해주신 에러내용으로 추론해보면 현재 .pb 파일로 저장하도록 train_isbi_2012.py 파일을 수정했는데 evaluate_isbi_2012.py 파일에서는 .ckpt 파일을 불러오도록 수정해서 문제가 발생한것 같습니다.
위에 gist 파일들로 교체하시면 train_isbi_2012.py과 evaluate_isbi_2012.py 파일에서 모두 .ckpt 파일을 사용하게 됩니다.
해보시고 혹시 문제 있으면 다시 질문 주세요.
좋은하루 되세요.
감사합니다.
안녕하세요 답변 감사합니다 train eval 부분바꿔서 실행하니
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.
이런문제가 처음 뜨면서 2000번 시작하기는 하더라고요.
그리고 강의 동영상 처럼 2000번이 빨리 안되는데 무슨 문제 인지는 잘모르겠네요..그래서 2000번 실행하면 사진이 3개 나오다가 컴퓨터가 알아서 멈춰버리더다고요(제 컴퓨터 cpu i9 에 4090이라서 그문제는 아닌거같아서요..)
안녕하세요~.
코드 실행 이후에 코드 실행 이외에 별도의 터미널을 하나더 띄우고 해당 터미널에서 GPU 사용량을 체크하는
nvidia-smi
위 명령어를 입력해서 코드가 CPU가 아니라 GPU를 이용해서 잘 실행되고 있는지 체크해보시면 좋을 것 같습니다.
좋은 하루되세요.
감사합니다.
안녕하세요~. 반갑습니다.
train부분 에러 train_isbi_2012.py:177: UserWarning:
Model.fit_generator
is deprecated and will be removed in a future version. Please useModel.fit
, which supports generators. 이거를Model.fit로 바꿔야하나요?
-> warning 메세지이므로 무시하고 fit_generator로 그대로 사용하셔도 문제없습니다.
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를 따로쓰는방법이있나요?
-> 로컬환경에서 tensorflow gpu를 사용하려면 CUDA 및 cuDNN 설치와 설정이 필요합니다.
https://www.tensorflow.org/install/gpu?hl=ko
OS별로 CUDA 및 cuDNN 설치와 설정은 위 문서를 참조하세요.
안녕하세요 말하신데로 train evaluate 다바꿔서 5장 저장다하고 ckpt 로 교체해서 evaluate_isbi_2012.py 실행하니 이런문제가 뜨네요.
-> scikit-image 라이브러리가 버전이 바뀌면서 바이너리 이미지를 저장하는 부분에 대한 지원방식이 바뀐것 같습니다.
바이너리 이미지 저장방식을 최신 scikit-image 버전에 맞게 새로 작성한 아래 evaluate_isbi_2012.py 파일로 변경해서 실행부탁드립니다.
https://gist.github.com/solaris33/c5fcce56903a6c6fcf3080285c864210
좋은 하루되세요.
감사합니다.