작성
·
437
0
for i, img in enumerate(imgs):
length = valid_len[i]
img = inference.visualize_image(
img,
boxes[i].numpy()[:length],
classes[i].numpy().astype(np.int)[:length],
scores[i].numpy()[:length],
label_map=config.label_map,
min_score_thresh=config.nms_configs.score_thresh,
max_boxes_to_draw=config.nms_configs.max_output_size)
output_image_path = os.path.join('/content/data_output', str(i) + '.jpg')
Image.fromarray(img).save(output_image_path)
print('writing annotated image to %s' % output_image_path)
AutoML Efficientdet Inference수행 결과 분석 및 시각화 강의입니다. (8분 48초)
여기에서 Image.fromarray(img).save(output_image_path) 부분에서 TypeError: function takes at most 14 arguments (17 given) 이라고 뜹니다. (강의에서는 정상적으로 작동하네요...)
뭐가 문제일까요?
답변 2
0
PIL 현재 버전 라이브러리가 뭔가 문제가 있는것 같습니다.
현재 코랩에서 9.4인 것 같은데, 이게 오류가 발생합니다.
실습 코드의 맨 위에서 아래와 같이 10.1 로 upgrade 한 뒤
!pip install Pillow==10.1
메뉴의 런타임-> 세션 다시 시작을 하고
import PIL
print(PIL.__version__) 으로 10.1 로 upgrade 된 것 확인하고 다시 실습 코드를 수행해 주십시요.
이것도 PIL 에서 오류가 발생하는 것 같습니다. 이전 방법대로 PIL을 Upgrade 해보시겠습니까?
그리고 댓글이 너무 많아져서 제가 올리신 글을 찾기가 힘들군요. 다음번 오류가 발생하면 별도 Q&A를 올려 주시겠습니까?
0
안녕하십니까,
음, 저도 에러가 나는군요. PIL Image 라이브러리의 문제인지, 아님 다른 문제인지 찾고 있는데, 시간이 좀 걸리는 군요. 확인하는 대로 다시 업데이트 드리겠습니다.
감사합니다.
오류나는 코드가 더 있어서 문의드립니다.
AutoML EfAutoML EfficientDet으로 Pascal VOC Train 실습 - Train을 위한 Config 설정
11분 42초
tfmot이 안된다고 에러 뜹니다.
감사합니다.
# 강의영상에는 from keras import anchors 이지만 efficientdet 패키지의 keras 모듈이 tf2 로 변경됨.
from tf2.train import setup_model
import hparams_config
import utils
from tf2 import tfmot
from tf2 import train_lib
from tf2 import util_keras
config = hparams_config.get_detection_config(TRAIN_CFG.model_name)
config.override(TRAIN_CFG.hparams)
steps_per_epoch = TRAIN_CFG.num_examples_per_epoch // TRAIN_CFG.batch_size
if tf.config.list_physical_devices('GPU'):
ds_strategy = tf.distribute.OneDeviceStrategy('device:GPU:0')
else:
ds_strategy = tf.distribute.OneDeviceStrategy('device:CPU:0')
print(ds_strategy)
#steps_per_execution은 ModelCheckpoint의 save_freq를 숫자로 설정할 시 적용. num_epochs, steps_per_epoch는 추후에 model.fit()에서 설정되지만, 여기서는 일단 값을 설정해야함.
params = dict(
profile=TRAIN_CFG.profile,
mode = TRAIN_CFG.mode,
model_name=TRAIN_CFG.model_name,
steps_per_execution=TRAIN_CFG.steps_per_execution,
num_epochs = TRAIN_CFG.num_epochs,
model_dir=TRAIN_CFG.model_dir,
steps_per_epoch=steps_per_epoch,
strategy=TRAIN_CFG.strategy,
batch_size=TRAIN_CFG.batch_size,
tf_random_seed=TRAIN_CFG.tf_random_seed,
debug=TRAIN_CFG.debug,
val_json_file=TRAIN_CFG.val_json_file,
eval_samples=TRAIN_CFG.eval_samples,
num_shards=ds_strategy.num_replicas_in_sync
)
config.override(params, True)
# image size를 tuple 형태로 변환. 512는 (512, 512)로 '1920x880' 은 (1920, 880) 으로 변환.
config.image_size = utils.parse_image_size(config.image_size)
print(config)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-13-f09c58e55edb> in <cell line: 6>()
4
5 import utils
----> 6 from tf2 import tfmot
7 from tf2 import train_lib
8 from tf2 import util_keras
/content/automl/efficientdet/tf2/tfmot.py in <module>
16 import functools
17
---> 18 import tensorflow_model_optimization as tfmot
19 from tensorflow_model_optimization.python.core.quantization.keras import quantize_wrapper
20 from tensorflow_model_optimization.python.core.quantization.keras.default_8bit import default_8bit_quantize_configs
ModuleNotFoundError: No module named 'tensorflow_model_optimization'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
모듈을 찾을 수 없다네요.
아, from tf2 import tfmot 건 주석 처리가 되어야 합니다.
# from tf2 import tfmot
이게 실습 코드에서 update가 안되어 있었나 보군요. 제가 가지고 있는 실습 코드만 update이 되었나 봅니다. 사과 드리겠습니다.
좋은 정보 감사합니다.
죄송합니다. 실습하다 보니 또 에러 나네요 ㅠㅠ
AutoML EfficientDet으로 Esri Object Detection Challenge 실습 - Esri 데이터를 TFRecord로 만들기 23분 39초입니다.
## xml 파일을 data dic로 변경 결과: {'folder': 'training_data', 'filename': '000000000.jpg', 'width': 224, 'height': 224, 'object': [{'name': '1', 'pose': 'Unspecified', 'truncated': 0, 'difficult': 0, 'occluded': 0, 'bndbox': {'xmin': 59, 'ymin': 153, 'xmax': 70, 'ymax': 164}}, {'name': '1', 'pose': 'Unspecified', 'truncated': 0, 'difficult': 0, 'occluded': 0, 'bndbox': {'xmin': 11, 'ymin': 206, 'xmax': 22, 'ymax': 217}}, {'name': '1', 'pose': 'Unspecified', 'truncated': 0, 'difficult': 0, 'occluded': 0, 'bndbox': {'xmin': 41, 'ymin': 0, 'xmax': 51, 'ymax': 4}}, {'name': '1', 'pose': 'Unspecified', 'truncated': 0, 'difficult': 0, 'occluded': 0, 'bndbox': {'xmin': 47, 'ymin': 42, 'xmax': 58, 'ymax': 53}}]}
UnidentifiedImageError Traceback (most recent call last)
<ipython-input-22-bba703afc463> in <cell line: 12>() 10 image_path = '/content/poolncar/training_data/training_data/images/000000000.jpg' 11 ---> 12 example = dict_to_tf_example(data, image_path, label_map_dict, unique_id, ignore_difficult_instances=False, ann_json_dict=None)
1 frames
<ipython-input-16-a326bb7d4621> in dict_to_tf_example(data, image_path, label_map_dict, unique_id, ignore_difficult_instances, ann_json_dict, debug) 23 # image가 JPEG 타입인지 확인. 24 encoded_jpg_io = io.BytesIO(encoded_jpg) ---> 25 image = PIL.Image.open(encoded_jpg_io) 26 if image.format != 'JPEG': 27 raise ValueError('Image format not JPEG') /usr/local/lib/python3.10/dist-packages/PIL/Image.py in open(fp, mode, formats) 3281 continue 3282 except BaseException: -> 3283 if exclusive_fp: 3284 fp.close() 3285 raise
UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7e88a4459710>
감사합니다.
(같은 파일에서 에러가 또 납니다.)
AutoML EfficientDet으로 Esri Object Detection Challenge 실습 - Esri 데이터를 TFRecord로 만들기 02
10분 33초
print('#### train용 tfrecords 생성 시작 ####') make_tfrecords(train_df, '/content/tfrecord/train/', 'train', num_shards=100) print('#### val용 tfrecords 생성 시작 ####') make_tfrecords(val_df, '/content/tfrecord/val/', 'val', num_shards=100) #### train용 tfrecords 생성 시작 #### On image 0 of 2998
UnidentifiedImageError Traceback (most recent call last)
<ipython-input-32-b025f44d5fbc> in <cell line: 2>() 1 print('#### train용 tfrecords 생성 시작 ####') ----> 2 make_tfrecords(train_df, '/content/tfrecord/train/', 'train', num_shards=100) 3 4 print('#### val용 tfrecords 생성 시작 ####') 5 make_tfrecords(val_df, '/content/tfrecord/val/', 'val', num_shards=100)
2 frames
<ipython-input-28-240ce93f88e2> in make_tfrecords(meta_df, output_dir, output_prefix, num_shards) 25 image_path = image_list[idx] 26 # 개별 Example 생성. ---> 27 tf_example = dict_to_tf_example(data, image_path, label_map_dict, unique_id, 28 ignore_difficult_instances=False, ann_json_dict=None, debug=False) 29 # num_shard만큼 만들어진 TFRecord에 Example을 iteration을 수행하면서 해당하는 TFRecord로 append
<ipython-input-16-a326bb7d4621> in dict_to_tf_example(data, image_path, label_map_dict, unique_id, ignore_difficult_instances, ann_json_dict, debug) 23 # image가 JPEG 타입인지 확인. 24 encoded_jpg_io = io.BytesIO(encoded_jpg) ---> 25 image = PIL.Image.open(encoded_jpg_io) 26 if image.format != 'JPEG': 27 raise ValueError('Image format not JPEG')
/usr/local/lib/python3.10/dist-packages/PIL/Image.py in open(fp, mode, formats) 3281 continue 3282 except BaseException: -> 3283 if exclusive_fp: 3284 fp.close() 3285 raise
UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7e889e745260>