avatarJulie Nyhus MSN, FNP-BC

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

4467

Abstract

self, img</span>): height, width, channels = img.shape results = self.model.predict(source=img.copy(), save=<span class="hljs-literal">False</span>, save_txt=<span class="hljs-literal">False</span>) result = results[<span class="hljs-number">0</span>] segmentation_contours_idx = [] <span class="hljs-keyword">for</span> seg <span class="hljs-keyword">in</span> result.masks.segments: <span class="hljs-comment"># contours</span> seg[:, <span class="hljs-number">0</span>] *= width seg[:, <span class="hljs-number">1</span>] *= height segment = np.array(seg, dtype=np.int32) segmentation_contours_idx.append(segment) bboxes = np.array(result.boxes.xyxy.cpu(), dtype=<span class="hljs-string">"int"</span>) class_ids = np.array(result.boxes.cls.cpu(), dtype=<span class="hljs-string">"int"</span>) scores = np.array(result.boxes.conf.cpu(), dtype=<span class="hljs-string">"float"</span>).<span class="hljs-built_in">round</span>(<span class="hljs-number">2</span>) <span class="hljs-keyword">return</span> bboxes, class_ids, segmentation_contours_idx, scores</pre></div><h2 id="1088">4. Interpreting the codes</h2><p id="3a87">Let’s run the code and try to interpret it.</p><p id="cbca">It shows the size of image is 448x640 of class frisbee or sports ball</p><div id="6b8d"><pre><span class="hljs-keyword">for</span> bbox, class_id, seg, score <span class="hljs-keyword">in</span> zip(bboxes, classes, segmentations, scores): cv2.rectangle(img,(x,y), (x2, y2),(0,0,255),2) <span class="hljs-built_in">print</span>(bboxes)</pre></div><figure id="f0ba"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*H07F26athuNmWdqS6zYATQ.png"><figcaption></figcaption></figure><p id="b4ce"><b>5. Draw the Bounding Box</b></p><p id="dc45">Let’s draw the bounding box to ensure we have the correct object.</p><div id="faa6"><pre>for bbox, class_id, seg, score in <span class="hljs-built_in">zip</span>(bboxes, classes, segmentations, scores): cv2.<span class="hljs-built_in">rectangle</span>(img,(x,y), (x2, y2),(<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">255</span>),<span class="hljs-number">2</span>)</pre></div><figure id="e4d1"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*Wd8CPiRMeTM8-X5dUjT5FA.png"><figcaption></figcaption></figure><p id="8507"><b>6. Draw polylines</b></p><p id="fa79">Here is the opencv format: <code>cv2.polylines(image, [pts], isClosed, color, thickness)</code></p><div id="2616"><pre>for bbox, class_id, seg, score in <span class="hljs-built_in">zip</span>(bboxes, classes, segmentations, scores): cv2.<span class="hljs-built_in">rectangle</span>(img,(x,y), (x2, y2),(<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">255</span>),<span class="hljs-number">2</span>) cv2.<span class="hljs-built_in">polylines</span>(img,[seg], True, (<span class="hljs-number">255</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>), <span class="hljs-number">2</span>)</pre></div><figure id="186d"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*JBl0ztp8GVsxdxv6kbufNg.png"><figcaption></figcaption></figure><p id="37d3"><b>7. Display class_id in the images</b></p><div id="f77a"><pre>for bbox, class_id, seg, score in <span class="hljs-built_in">zip</span>(bboxes, classes, segmentations, scores): cv2.<span class="hljs-built_in">rectangle</span>(img,(x,y), (x2, y2),(<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">255</span>),<span class="hljs-number">2</span>) cv2.<span class="hljs-built_in">polylines</span>(img,[seg], True, (<span class="hljs-number">255</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>), <span class="hljs-number">2</span>) cv2.<span class="hljs-built_in">putText</span>(img,<span class="hljs-built_in">str</span>(class_id), (x, y-<span class="hljs-number">10</span>), cv2.FONT_HERSHEY_PLAIN, <span class="hljs-number">2</span>, (<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">255</span>),<span class="hljs-number">2</span>)</pre></div><figure id="541f"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*9u3k7CZJoWD0J8SFHr20kg.png"><figcaption></figcaption></figu

Options

re><h2 id="1682">8. To fill the shape, just use FillPoly</h2><div id="5f1b"><pre>for bbox, class_id, seg, score in <span class="hljs-built_in">zip</span>(bboxes, classes, segmentations, scores): cv2.<span class="hljs-built_in">rectangle</span>(img,(x,y), (x2, y2),(<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">255</span>),<span class="hljs-number">2</span>) cv2.<span class="hljs-built_in">polylines</span>(img,[seg], True, (<span class="hljs-number">255</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>), <span class="hljs-number">2</span>) cv2.<span class="hljs-built_in">putText</span>(img,<span class="hljs-built_in">str</span>(class_id), (x, y-<span class="hljs-number">10</span>), cv2.FONT_HERSHEY_PLAIN, <span class="hljs-number">2</span>, (<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">255</span>),<span class="hljs-number">2</span>) cv2.<span class="hljs-built_in">fillPoly</span>(img, pts=[seg], color=(<span class="hljs-number">255</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>))</pre></div><figure id="6535"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*5nI1CNwifDKx7yKpFwDovw.png"><figcaption></figcaption></figure><p id="fe5c"><b>9. Load in our own image now</b></p><p id="1255">Now add in the our own weights and image to the pycharm</p><figure id="5e22"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*885EJtYZDG9W9AQDeGFCOQ.png"><figcaption></figcaption></figure><p id="08b7">Change the following codes</p><p id="5651">img = cv2.imread(“rugby.jpg”)</p><p id="7436">→ img = cv2.imread(“container.jpg”)</p><p id="ecdc">ys = YOLOSegmentation(‘yolov8m-seg.pt’)</p><p id="00de">→ ys = YOLOSegmentation(‘best.pt’)</p><div id="95c2"><pre><span class="hljs-attr">img</span> = cv2.imread(<span class="hljs-string">"rugby.jpg"</span>) <span class="hljs-attr">ys</span> = YOLOSegmentation(<span class="hljs-string">'yolov8m-seg.pt'</span>)</pre></div><div id="e1a1"><pre><span class="hljs-attr">img</span> = cv2.imread(<span class="hljs-string">"container.jpg"</span>) <span class="hljs-attr">ys</span> = YOLOSegmentation(<span class="hljs-string">'best.pt'</span>)</pre></div><p id="09db"><b>10. Test the image</b></p><p id="5b61">Here are the test results in Pycharm. According to data.yaml file, the class id is 0 (blue), 1(gray), 2(green), 3(red) and 4(yellow)</p><figure id="03b8"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*nzDJrIVpkXtXb4pDO5mtvg.png"><figcaption></figcaption></figure><figure id="55a6"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*rmGcevWHaCQ18iCRO5Pifw.png"><figcaption></figcaption></figure><p id="ac3e"><b>9.1 scores</b></p><p id="c2ac">The scores are following the sequence in Roboflow which is generated into a data.yaml file.</p><figure id="ad6d"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*BgCDYQ8n37iHXgOdbzM5pw.png"><figcaption></figcaption></figure><p id="4b1f">We see that there is a duplicate gray colour with the left side considered as a gray object</p><p id="7364"><b>9.2 Scores</b></p><p id="ff1d">Scores show relatively detection scores are high for blue and yellow. The worst score is gray since there are overdetected one of them.</p><figure id="effc"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*Kdy0tXlZunTzuRsoRHkCGw.png"><figcaption></figcaption></figure><h2 id="17ec">10. Now convert to TFLite model</h2><p id="2632">To convert to TFlite model, just run the following command</p><p id="b5cc">!yolo export model=/content/runs/segment/train2/weights/best.pt format=tflite</p><h1 id="279c">Conclusion</h1><p id="8788">As you can see, we can get more precise location and bounding boxes with object segmentation. Try this out and see if you can use it with other OpenCV function!</p><h1 id="daa2">References</h1><p id="30d7">Ref1:<a href="https://nirmalamurali.medium.com/image-classification-vs-semantic-segmentation-vs-instance-segmentation-625c33a08d50">https://nirmalamurali.medium.com/image-classification-vs-semantic-segmentation-vs-instance-segmentation-625c33a08d50</a></p><p id="d045">Ref2:<a href="https://pysource.com/2023/02/21/instance-segmentation-yolo-v8-opencv-with-python-tutorial/">https://pysource.com/2023/02/21/instance-segmentation-yolo-v8-opencv-with-python-tutorial/</a></p></article></body>

Making the Cut — Part 3: An Education of Isolationism

My separation-from-religion experience

Photo by Aaron Burden on Unsplash

This is the third part of a 6-part series chronicling my journey away from religion. If it offends you, I’m sorry, but you really shouldn’t let other people’s experiences trouble you. This is my experience and isn’t intended to discredit your experiences or beliefs in any way. My journey is mine and your journey is yours. I respect them equally.

Part 3: An Education of Isolationism

Eventually, my father was saved, receiving the Holy Ghost with the evidence of speaking in tongues while at work one day in his truck cab. Meanwhile, my mother drifted away from The Body and the truth. I was too young to know why she wandered or where she went but would believe for many years that her unhappiness in our family was my fault, not my father’s nor my sibling’s and certainly not the church’s. Divorce made my tiny existence a smaller and more frightful place as my parents divided the household goods, the cars, and the children evenly among themselves.

As god’s will would have it, my older brother and I were sent to live with my father, who dutifully took us to church services every Wednesday and Saturday nights and twice on Sundays. Ensuring that we didn’t miss Thursday night bible study or Friday night church cleaning was also a crucial part of godly parenting. One of The Body doctrines was never miss a service, and my father was an avid doctrine supporter, as it suited him.

Daily christian school and church services: required.

Television and movies: banned.

Family prayer and devotion time: nonexistent.

It was the 1970s, an era of post-hippie self-absorption and rising inflation. The elders of the church feared that public education would poison the minds of its young members. By the time I was ten years old, the church constructed a new building with an attached, one-room learning center designed for christian education.

Sometime in the 1950s, modern christian education began picking up movement, creating christian curriculum written by christians for christains, containing christian history, christian values, and christian literature brimming with biblical stories of christian suffering, martyrdom, and death. In our one-room schoolhouse, The Body boarded the christian education train, providing a solid, bible-based education without interference from the world or the government. Influenced only by christian music, books, and people, The Body could be assured their children were safe, and their minds properly trained.

My siblings and I were among the first students to don red, white, and blue uniforms — knee-length dresses for girls, dress pants and ties for boys. Girls couldn’t cut their hair while boys were required to keep it trimmed close to the scalp. I recall a slight desire to fill the “no makeup” void with colorful socks and nail polish, but it only mattered to me. Individualism, although not discouraged, wasn’t encouraged. Students who were quick soon discovered that adults favored those who could blindly follow.

Climbing this steel scale of religion from a young age meant I only knew what I was taught. Our church and christian school belonged to The Body of Christ and daily attention was spent on perfecting christ’s body during school, while academics hung in the background. As my life morphed from middle-schooler to high-schooler, the world outside the church doors held a peculiar interest for me that was equally extraordinary and terrifying. I began to see the difference between us and the world.

Driver’s education was the one thing our little church school could’t offer. At 15 years old, I was sent to the public high school to attend driver’s ed classes with “worldly” teenagers. They wore jeans and smelled like damp carpets. I had no idea how to face their choosy stares and loud whispers. Although I had been repeatedly bullied the last few years by my own christian school mates — who yelled “dog face” and repeatedly barked at me when I passed them in the church hallway — this was a new discomfort. And I couldn’t wait for it to end. I longed to get back to bearing the burden of the flesh, which continually separated me from god and left me striving day after day for perfection and worthiness. Somehow, that was preferable to facing the uncertainty of the outside world.

Making the Cut — Part 4: The Real World

The Real World

One week every summer my siblings and I were sent away — two at a time — to stay in the country with our grandparents. It took a two-hour backseat car ride to get there, but it was always worth it. Since we are 15 months apart in age, my older brother and I were paired for these annual expeditions. My mother’s parents were nothing like my mother. They were interested and happy . . .

Don’t miss Making the Cut: Part 4

Here are links to Parts 1 and 2 if case you missed it!

If you found this article interesting, I accept hugs in the form of

— Generous highlighting and applause

— Copious comments spilling with gratitude and deep-thoughts

— Scads of followers Julie Nyhus MSN, FNP-BC

— Positive thoughts directed my way

In peace and light,

Joolz

Life Lessons
Self Improvement
Self-awareness
Religion And Spirituality
Life
Recommended from ReadMedium