tensorflow-yolov4-tflite icon indicating copy to clipboard operation
tensorflow-yolov4-tflite copied to clipboard

train issue RuntimeError: Physical devices cannot be modified after being initialized

Open MC1016 opened this issue 4 years ago • 6 comments

when i run python train.py RuntimeError: Physical devices cannot be modified after being initialized

MC1016 avatar Jul 28 '20 00:07 MC1016

I had the same issue and it could be solved by importing the yolov4 after the set_memory_growth method of tensorflow.

from absl import app, flags, logging
from absl.flags import FLAGS
import os
import shutil
import tensorflow as tf
#from core.yolov4 import YOLO, decode, compute_loss, decode_train    #exclude this code
from core.dataset import Dataset
from core.config import cfg
import numpy as np
from core import utils
from core.utils import freeze_all, unfreeze_all

and this at line 19 to 21

    if len(physical_devices) > 0:
        tf.config.experimental.set_memory_growth(physical_devices[0], True)
    from core.yolov4 import YOLO, decode, compute_loss, decode_train  #inset this code here

Or alternatively, comment out the set_memory_growth method at line 20.

ryuzou avatar Jul 31 '20 18:07 ryuzou

I had the same issue and it could be solved by importing the yolov4 after the set_memory_growth method of tensorflow.

from absl import app, flags, logging
from absl.flags import FLAGS
import os
import shutil
import tensorflow as tf
#from core.yolov4 import YOLO, decode, compute_loss, decode_train    #exclude this code
from core.dataset import Dataset
from core.config import cfg
import numpy as np
from core import utils
from core.utils import freeze_all, unfreeze_all

and this at line 19 to 21

    if len(physical_devices) > 0:
        tf.config.experimental.set_memory_growth(physical_devices[0], True)
    from core.yolov4 import YOLO, decode, compute_loss, decode_train  #inset this code here

Or alternatively, comment out the set_memory_growth method at line 20.

The first way worked for me. Thanks 👍

Manoj-M-97 avatar Aug 18 '20 17:08 Manoj-M-97

I had the same issue and it could be solved by importing the yolov4 after the set_memory_growth method of tensorflow.

from absl import app, flags, logging
from absl.flags import FLAGS
import os
import shutil
import tensorflow as tf
#from core.yolov4 import YOLO, decode, compute_loss, decode_train    #exclude this code
from core.dataset import Dataset
from core.config import cfg
import numpy as np
from core import utils
from core.utils import freeze_all, unfreeze_all

and this at line 19 to 21

    if len(physical_devices) > 0:
        tf.config.experimental.set_memory_growth(physical_devices[0], True)
    from core.yolov4 import YOLO, decode, compute_loss, decode_train  #inset this code here

Or alternatively, comment out the set_memory_growth method at line 20.

Hi, I didn't have this error in the first place, but all of a sudden this error occurred. Why was that?

LeamonLee avatar Apr 15 '21 14:04 LeamonLee

I got the same issue, does anyone found the solution?

Nafees-060 avatar Apr 23 '21 07:04 Nafees-060

@Nafees-060 i use his method ,solve this problems ,but dont know why .who can tell me

Tracy-git avatar Jul 16 '21 15:07 Tracy-git

@Nafees-060 Got the same issue and @Manoj-M-97 method solve my problem. Thank you

maryamxasghari avatar Oct 26 '21 03:10 maryamxasghari