with open(ann_files[0]) as json_file: data = json.load(json_file) tags = data['tags'] objects = data['objects'] img_path = ann_files[0].replace('/ann/', '/img/').split('.json')[0] label_path = ann_files[0].replace('/ann/', '/masks_machine/').split('.json')[0] print("Images dtype: {}".format(get_image(img_path).dtype)) print("Labels dtype: {}\n".format(get_image(label_path, label = True).dtype)) print("Images shape: {}".format(get_image(img_path, resize = True if resize else False).shape)) print("Labels shape: {}\n".format(get_image(label_path, label = True, resize = True if resize else False).shape)) # In[]: model = sm.Linknet_bottleneck_crop(backbone_name=backbone, input_shape=input_shape, classification_classes=classification_classes, segmentation_classes = segmentation_classes, classification_activation = 'sigmoid', segmentation_activation='sigmoid') model.load_weights('weights/' + weights + '.hdf5') # In[]: from keras.utils import plot_model plot_model(model, to_file='keras_model.png') # In[]: onnx_model = keras2onnx.convert_keras(model, model.name) # In[]: import onnx onnx.save_model(onnx_model, 'model.onnx') # In[]: preprocessing_fn = sm.get_preprocessing(backbone)
input_shape = (256, 640, 3) if resize else (512, 1280, 3) classification_classes = 1 segmentation_classes = 1 classification_activation = 'sigmoid' if classification_classes == 1 else 'softmax' segmentation_activation = 'sigmoid' if segmentation_classes == 1 else 'softmax' backbone = 'resnet18' weights = "2019-09-30 17-32-13" model = sm.Linknet_bottleneck_crop( backbone_name=backbone, input_shape=(256, 640, 3), classification_classes=classification_classes, segmentation_classes=segmentation_classes, classification_activation=classification_activation, segmentation_activation=segmentation_activation) model.load_weights('weights/' + weights + '.hdf5') preprocessing_fn = sm.get_preprocessing(backbone) model._make_predict_function() print("START ZERO PREDICT") model.predict(np.zeros(((1, ) + input_shape), dtype=np.uint8)) print("END ZERO PREDICT") font = cv2.FONT_HERSHEY_SIMPLEX fontScale = 1