在keras+tensorflow框架下训练的权重可以在tf.keras.models.load_model调用,不必重新训练。
同理,keras+tensorflow框架下的function,在这些function前加tf.同样可以实现原框架下的功能。
import numpy as np
import tensorflow as tf
import cv2
import os
class MODEL_lug(object):
def __init__(self):
self.model=tf.keras.models.load_model('C:\\Users\\18367\\Desktop\\corner_test\\0324_lug_irv2.h5')
def predict(self,image_lug,width,height):
image_temp = np.zeros((height,width,3),dtype = np.uint8)
for channel in np.arange(3):
for j in np.arange(height):
for i in np.arange(width):
image_temp[j,i,channel]=image_lug[width*j*3+i*3+channel]
image_input = np.zeros((height, width, 3), dtype=np.uint8)
image_input[:, :, 0] = image_temp[:, :, 2]
image_input[:, :, 1] = image_temp[:, :, 1]
image_input[:, :, 2] = image_temp[:, :, 0]
image_inpu