def pascal_voc_overlay(the_image): segment_image = semantic_segmentation() segment_image.load_pascalvoc_model( "model/deeplabv3_xception_tf_dim_ordering_tf_kernels.h5") segment_image.segmentAsPascalvoc(the_image, output_image_name='res' + '/' + f'{the_image}', overlay=True) st.image(f'res/{the_image}', caption='Output Image')
def sem_seg(): capture = cv2.VideoCapture(0) segment_video = semantic_segmentation() segment_video.load_ade20k_model( "deeplabv3_xception65_ade20k.h5") #loading_the_datamodel segment_video.process_camera_ade20k(capture, overlay=True, frames_per_second=10, output_video_name="sem_seg_out.mp4", show_frames=True, frame_name="frame")
def deep_segmentation(self, pic): path = '/Users/regevazran/Desktop/technion/semester i/project c/temp pic/' result = cv2.imwrite(path + 'temp_pic.jpg', pic) from pixellib.semantic import semantic_segmentation segment_image = semantic_segmentation() segment_image.load_pascalvoc_model( path + "deeplabv3_xception_tf_dim_ordering_tf_kernels.h5") segment_image.segmentAsPascalvoc(path + 'temp_pic.jpg', output_image_name=path + "image_new.jpg") return
def post(self): if request.json: image = request.json['image'] image_string = base64.b64decode(image) image_data = BytesIO(image_string) img = Image.open(image_data) img.save(INPUT_IMAGE) semantic_segment_image = semantic_segmentation() semantic_segment_image.load_pascalvoc_model(SEMANTIC_MODEL) semantic_segment_image.segmentAsPascalvoc( INPUT_IMAGE, output_image_name=OUTPUT_IMAGE) with open(OUTPUT_IMAGE, "rb") as img_file: my_string = base64.b64encode(img_file.read()) final_base64_image_string = my_string.decode('utf-8') return {"output_image": final_base64_image_string}
def prediction(img_file): # instantiating the semantic segmentation class segment_image = semantic_segmentation() # loading the model deeplabv3+ trained on pascal voc dataset. segment_image.load_pascalvoc_model(DATA_URL) # performing the segmentation on the input image segment_image.segmentAsPascalvoc(img_file, output_image_name = "output_images/out.jpg") out = plt.imread("output_images/out.jpg", 0) # performing the segmentation on the input image with overlay segment_image.segmentAsPascalvoc(img_file, output_image_name = "output_images/out_overlay.jpg", overlay = True) out_overlay = plt.imread("output_images/out_overlay.jpg") return out, out_overlay
def do_semantic(img_path): absolute_path = os.path.abspath( "model/deeplabv3_xception_tf_dim_ordering_tf_kernels.h5") segment_image = semantic_segmentation() # Load the xception model trained on pascal voc for segmenting objects. segment_image.load_pascalvoc_model(absolute_path) # segment_image.load_pascalvoc_model("pascal.h5") # Perform segmentation on an image segmap, segoverlay = segment_image.segmentAsPascalvoc( img_path, output_image_name="image1_new.jpg", overlay=True) return segoverlay # output, segmap = segment_image.segmentAsPascalvoc("sample1.jpg") # cv2.imwrite("img.jpg", segoverlay) # print(segoverlay.shape)
Original file is located at https://colab.research.google.com/drive/15lqIl-GIkW7G4QaYMcvYL4LgcPAChwTi """ ##Definición de Librerias import pixellib from pixellib.semantic import semantic_segmentation from pixellib.instance import instance_segmentation ##Semantic Segmentation print("Semantic Image Segmentation Process...") #Definition of semantic_segmentation in pixellib Library segment_image = semantic_segmentation() #Es necesario los pesos de deeplabv3_xception_tf_dim_ordering_tf_kernels.h5 segment_image.load_pascalvoc_model("deeplabv3_xception_tf_dim_ordering_tf_kernels.h5") #Semantic Segmentation segment_image.segmentAsPascalvoc("test7_4.jpg", output_image_name = "person_segmentationN.jpg") #Semantic Segmentation with image Mask segment_image.segmentAsPascalvoc("test7_4.jpg", output_image_name = "person_segmentationN_Mask.jpg", overlay = True) print("Done") ##Instance Segmentation print("Instance Image Segmentation Process...")
#https://github.com/ayoolaolafenwa/PixelLib/releases/download/1.3/deeplabv3_xception65_ade20k.h5 #https://github.com/ayoolaolafenwa/PixelLib/releases/download/1.1/deeplabv3_xception_tf_dim_ordering_tf_kernels.h5 # lets copy the files to c:/models import pixellib from pixellib.semantic import semantic_segmentation import cv2 cam = cv2.VideoCapture(0) # set the capturing resolotion to 1920 X 1080 cam.set(3, 1920) cam.set(4, 1080) semgment_video = semantic_segmentation() #semgment_video.load_ade20k_model("c:/models/deeplabv3_xception65_ade20k.h5") #seg, result = semgment_video.process_camera_ade20k(cam ,overlay=True, frames_per_second=15 , show_frames=True , frame_name="frame", output_video_name="c:/demo/cameraSemanticSegmentation.mp4" ) # remember to press q to quit the camera !!! #lets use the second model semgment_video.load_pascalvoc_model( 'c:/models/deeplabv3_xception_tf_dim_ordering_tf_kernels.h5') seg, result = semgment_video.process_camera_pascalvoc( cam, overlay=True, frames_per_second=15, show_frames=True, frame_name="frame",
def LoadSemanticSegmenter(): from pixellib.semantic import semantic_segmentation global Segmenter_Semantic Segmenter_Semantic = semantic_segmentation() Segmenter_Semantic.load_pascalvoc_model( ModelsDir + "deeplabv3_xception_tf_dim_ordering_tf_kernels.h5")
import cv2 #Pixellib is important library for Instance and Semantic segmentation from pixellib.instance import instance_segmentation from pixellib.semantic import semantic_segmentation ins_seg = instance_segmentation() #For instance segementation sem_seg = semantic_segmentation() #For semantic segementation ins_seg.load_model('mask_rcnn_coco.h5') #sem_seg.model('mask_rcnn_coco.h5') cap = cv2.VideoCapture(0) while True: ret, frame = cap.read() if ret: result = ins_seg.segmentFrame(frame, show_bboxes=True) #result = sem_seg.segmentFrameAsPascalvoc(frame) #result is tuple containing dict in 0 index and image in 1 index image = result[1] cv2.imshow("Instance", image) if cv2.waitKey(1) & 0xFF == ord("q"): break cap.release() cv2.destroyAllWindows()
#SEMANTIC SEGMENTATION import pixellib from pixellib.semantic import semantic_segmentation segment = semantic_segmentation() segment.load_pascalvoc_model("pascal.h5") out = segment.segmentAsPascalvoc("t1.jpg", output_image_name="image1.jpg") """#Apply segmentation overlay import pixellib from pixellib.semantic import semantic_segmentation segment = semantic_segmentation() segment.load_pascalvoc_model("pascal.h5") out = segment.segmentAsPascalvoc("t1.jpg", output_image_name = "image2.jpg", overlay=True) #INSTANCE SEGMENTATION import pixellib from pixellib.instance import instance_segmentation instance_seg = instance_segmentation() instance_seg.load_model("mask_rcnn_coco.h5") out = instance_seg.segmentImage("img.jpg", output_image_name = "image3.jpg") #Show segmented images with bounding boxes import pixellib from pixellib.instance import instance_segmentation instance_seg = instance_segmentation() instance_seg.load_model("mask_rcnn_coco.h5")
def __init__(self): self.model = semantic_segmentation() self.model.load_ade20k_model("deeplabv3_xception65_ade20k.h5")
import pixellib from pixellib.semantic import semantic_segmentation import cv2 #experimental script to play with better pixelators using various CV techniques. Sort of a mess right now segment_frame = semantic_segmentation() segment_frame.load_pascalvoc_model( "deeplabv3_xception_tf_dim_ordering_tf_kernels.h5") #segment_image.segmentAsPascalvoc("../images/person.jpg", output_image_name = "../images/image_new.jpg") vid = cv2.VideoCapture(0) while (True): # Input image #input = cv2.imread('../images/person.jpg') ret, input = vid.read() #input = cv2.imread('../images/person.jpg') segmap, output = segment_frame.segmentFrameAsPascalvoc(input) cv2.imshow('Input', input) cv2.imshow('Output', output) # the 'q' button is set as the # quitting button you may use any # desired button of your choice if cv2.waitKey(1) & 0xFF == ord('q'): break
import pixellib #semantic segmentation from pixellib.semantic import semantic_segmentation segment_img = semantic_segmentation() segment_img.load_ade20k_model("./model/deeplabv3_xception65_ade20k.h5") segment_img.segmentAsAde20k("./img/1.jpg", overlay=True, output_image_name="sem_seg_res.jpg") #instance segmentation from pixellib.instance import instance_segmentation segment_image = instance_segmentation() segment_image.load_model("./model/mask_rcnn_coco.h5") segment_image.segmentImage("./img/1.jpg", show_bboxes=True, output_image_name="ins_seg_res.jpg")