当前位置:网站首页>Retinanet+keras train their own data set to tread on the pit
Retinanet+keras train their own data set to tread on the pit
2022-06-11 04:51:00 【Panbohhhhh】
1. After training the model , Run the training code , Report errors :ValueError: not enough values to unpack (expected 3, got 2)
Online search replies are opencv Version issue for .
The current period 2020 year 1 month 8 Japan 09:36:30, The version I use is :
opencv-contrib-python 4.1.2.30
opencv-python 4.1.2.30
resolvent :
Version independent .
In the original git Connecting Keras RetinaNet There are also descriptions .
principle : The trained model needs to be transformed into inference Model
Code : Insert a code chip here
# Running directly from the repository:
keras_retinanet/bin/convert_model.py /path/to/training/model.h5 /path/to/save/inference/model.h5
# Using the installed script:
retinanet-convert-model /path/to/training/model.h5 /path/to/save/inference/model.h5
Of course , I personally think this way , Too complicated .
Attached below are for personal use modeltest.py
import keras
from keras_retinanet import models
from keras_retinanet.utils.image import read_image_bgr, preprocess_image, resize_image
from keras_retinanet.utils.visualization import draw_box, draw_caption
from keras_retinanet.utils.colors import label_color
import matplotlib.pyplot as plt
import cv2
import os
# Whether to use gpu
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
import numpy as np
import time
import tensorflow as tf
def get_session():
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
return tf.Session(config=config)
# Set up tensorflow session by Keras Back end
keras.backend.tensorflow_backend.set_session(get_session())
# The converted inferred model address
# model_path = os.path.join('..', 'snapshots', 'predict.h5')
model_path = 'E:\\winebottle\\keras-retinanet-master\\keras_retinanet\\bin\\snapshots1\\resnet50_csv_19.h5'
# Load model
model = models.load_model(model_path, backbone_name='resnet50')
# solve ValueError: not enough values to unpack (expected 3, got 2)
model = models.convert_model(model)
# establish ID Mapping dictionary with category
labels_to_names = { 0:‘ Category 1’}
# Load the image to be detected
path = '/home/zbb/keras-retinanet/CSV/test/50.JPG'
save_path = ' Saved path '
image_names = sorted(os.listdir(path))
for image_path in image_names:
image = read_image_bgr(path + image_path)
print(path + image_path)
# copy To another object and to RGB file
draw = image.copy()
draw = cv2.cvtColor(draw, cv2.COLOR_BGR2RGB)
# Image preprocessing
image = preprocess_image(image)
image, scale = resize_image(image)
# Model to predict
start = time.time()
boxes, scores, labels = model.predict_on_batch(np.expand_dims(image, axis=0))
print("processing time: ", time.time() - start)
# Correction ratio
boxes /= scale
# Visual display of target detection
for box, score, label in zip(boxes[0], scores[0], labels[0]):
# Set the lowest threshold of prediction score
if score < 0.75:
break
color = label_color(label)
print(color)
b = box.astype(int)
draw_box(draw, b, color=color)
caption = "{} {:.3f}".format(labels_to_names[label], score)
draw_caption(draw, b, caption)
# Pictures show
plt.figure(figsize=(15, 15))
plt.axis('off')
plt.imshow(draw)
plt.savefig(save_path + image_path, format='JPG', transparent=True, pad_inches=0, dpi=300, bbox_inches='tight')
边栏推荐
- C语言试题三(语法选择题——含知识点详解)
- An adaptive chat site - anonymous online chat room PHP source code
- Network adapter purchase guide
- Powerful new UI installation force artifact wechat applet source code + multiple templates support multiple traffic main modes
- Leetcode question brushing series - mode 2 (datastructure linked list) - 83:remove duplicates from sorted list
- Overview of construction knowledge of Fuzhou mask clean workshop
- 图的最短路径问题 详细分解版
- The data center is evolving towards the "four high" trend, and the OCP network card and the whole cabinet will be delivered into the mainstream of the future data center
- 精益产品开发体系最佳实践及原则
- Leetcode question brushing series - mode 2 (datastructure linked list) - 21:merge two sorted lists merge two ordered linked lists
猜你喜欢

Mindmanager22 professional mind mapping tool
![[Transformer]AutoFormerV2:Searching the Search Space of Vision Transformer](/img/33/32796e4f807db99898d471ac5dfe2c.jpg)
[Transformer]AutoFormerV2:Searching the Search Space of Vision Transformer

华为设备配置本地虚拟专用网互访

Lianrui: how to rationally see the independent R & D of domestic CPU and the development of domestic hardware

Iris dataset - Introduction to machine learning
![[Transformer]On the Integration of Self-Attention and Convolution](/img/64/59f611533ebb0cc130d08c596a8ab2.jpg)
[Transformer]On the Integration of Self-Attention and Convolution

Exness: Liquidity Series - order Block, Unbalanced (II)

Mathematical basis of information and communication -- the first experiment

Visual (Single) Object Tracking -- SiamRPN

Check the digital tube with a multimeter
随机推荐
Redis master-slave replication, sentinel, cluster cluster principle + experiment (wait, it will be later, but it will be better)
华为设备配置跨域虚拟专用网
Exhibit express: Lianrui will bring three new products of the industry to debut in visionchina (Shenzhen) 2021
[Transformer]AutoFormerV2:Searching the Search Space of Vision Transformer
Go unit test example; Document reading and writing; serialize
Leetcode question brushing series - mode 2 (datastructure linked list) - 206:reverse linked list
How to purchase 25g optical network card
Emlog new navigation source code / with user center
Database introduction
Legend has it that setting shader attributes with shader ID can improve efficiency:)
Feature engineering feature dimension reduction
博途仿真时出现“没有针对此地址组态任何硬件,无法进行修改”解决办法
Tianchi - student test score forecast
The data center is evolving towards the "four high" trend, and the OCP network card and the whole cabinet will be delivered into the mainstream of the future data center
World programming language ranking in January 2022
董明珠称“格力手机做得不比苹果差”哪里来的底气?
Decision tree (hunt, ID3, C4.5, cart)
Simple linear regression of sklearn series
用万用表检测数码管
KD-Tree and LSH