{"id":11654,"date":"2021-03-11T18:14:28","date_gmt":"2021-03-11T17:14:28","guid":{"rendered":"http:\/\/flaven.fr\/?p=11654"},"modified":"2026-09-16T10:09:41","modified_gmt":"2026-09-16T08:09:41","slug":"improve-a-cmss-photos-library-qualification-with-ai-object-detection-from-images-in-python-with-opencv-and-yolo","status":"publish","type":"post","link":"https:\/\/flaven.fr\/2021\/03\/improve-a-cmss-photos-library-qualification-with-ai-object-detection-from-images-in-python-with-opencv-and-yolo\/","title":{"rendered":"Improve a CMS&#8217;s photos library qualification with AI, Object Detection from images in Python with OpenCv and YOLO"},"content":{"rendered":"<p>Still digging, in Python, on more versatile usage in object detection from images to improve a house-made CMS multimedia searches. What a sentence! So, maybe, you have heard about the acronym YOLO one stands for &#8220;You Only Live Once&#8221;, a kind of modern version of the Latin &#8220;Carpe Diem&#8221;, the other YOLO stands for &#8220;You Only Look Once&#8221;.<\/p>\n<p>So, let\u2019s give a quick definition of the second YOLO thing and it&#8217;s all about image recognition.<\/p>\n<p><a href=\"https:\/\/github.com\/bflaven\/BlogArticlesExamples\/tree\/master\/python_playing_with_object_detection_opencv_yolo\" target=\"_blank\" rel=\"noopener\">All the files can be found on my github account at https:\/\/github.com\/bflaven\/BlogArticlesExamples\/tree\/master\/python_playing_with_object_detection_opencv_yolo<\/a><\/p>\n<h3>What is this other YOLO thing?<\/h3>\n<p><b>YOLO is an extremely fast multi object detection algorithm which uses convolutional neural network (CNN) to detect and identify objects. Maybe less sexy than the first definition but pretty useful when like me you try to increase the images library relevance categorization&#8230;<\/b><\/p>\n<p><i>At least, I also like the name of the library YOLO. I was figured out a funny dialog between developers mimicking pseudo rappers &#8220;What kinda python lib do you like, Bro!&#8221;, &#8220;YOLO, man! Totally. Need to check it out NOW!&#8221; \ud83d\ude42<\/i><\/p>\n<p>Anyway, let&#8217;s expose my objective.<\/p>\n<h3>To make better image categorization for a CMS<\/h3>\n<p>I have already exposed the issue, I am tackling with it already in a previous post dedicated to facial recognition.<\/p>\n<ul>\n<li>If you are interested, you can check the post &#8220;Improve a CMS\u2019s photos library qualification with AI, facial recognition in python, to provide better images search results to users&#8221; at <a href=\"https:\/\/flaven.fr\/2020\/06\/improve-a-cms-photos-library-qualification-with-ai-facial-recognition-in-python-to-provide-better-images-search-results-to-users\/\" target=\"_blank\" rel=\"noopener\">https:\/\/flaven.fr\/2020\/06\/improve-a-cms-photos-library-qualification-with-ai-facial-recognition-in-python-to-provide-better-images-search-results-to-users\/<\/a><\/li>\n<\/ul>\n<p>If you ever read that post&#8217;s blog, I made few attempts on facial recognition with people faces mostly presidents. On a very European centric point of view, presidents can be range from known, less know to totally unknow!<\/p>\n<p>Unfortunately, it is OK for human faces but not for any other element inside pictures to be recognized e.g. cars, buildings, dog, horse, human, tree&#8230;. whatever.<\/p>\n<p>Well, as I am consistent or stubborn, my objective is still the same as a Backoffice&#8217;s PO: the multimedia library carries thousand of images that are uncorrectly tagged: no caption, no keywords&#8230; etc So, performing searches on that dataset is problematic. To be even more straightforward, I will answer &#8220;GIGO&#8221;, the famous &#8220;Garbage In, Garbage Out&#8221;. GIGO produces search results that suck! So how can the situation be improved, one possibility is to enhance image search with a fine-grained keywords attached to each picture but without making the job by humans. This is where you&#8217;d better call IA to the rescue.<\/p>\n<p>Like always that is very practical issue, I won&#8217;t give you any explanations about the YOLO algorithm and what is &#8220;behind the curtain&#8221; with matrix and formula stuff both because it does not really interest me, I am user first and also because I am just no able to do so! No, I will focus on results !<\/p>\n<h3>Set-up your environnement<\/h3>\n<p>At the very beginning, I was looking for an example using TensorFlow Image Recognition but I decide to go for YOLO. I found it much easier to implement. Let&#8217;s see quickly what you need to play with YOLO.<\/p>\n<p><b>Python librairies<\/b><br \/>\nFirst, I am using my mac and a remote disk to install all the required libraries with the help of anaconda, to save space disk. In addition to the principal Python libraries used in the scripts that are easy to install with pip or anaconda.<\/p>\n<pre lang=\"python\">\r\n# YOLO object detection requirements\r\nimport cv2 as cv\r\nimport numpy as np\r\nimport time\r\n\r\n# to parse the directory\r\nimport os\r\n\r\n# to import in mysql\r\nimport mysql.connector as mysql\r\n<\/pre>\n<p>I just advise to use this command to install opencv.<\/p>\n<pre lang=\"python\">\r\n# to install cv2 or opencv use this command\r\npip install opencv-python\r\n\r\n# this command is not working\r\npip install opencv\r\n<\/pre>\n<p>You will have to download the YOLO files.<\/p>\n<p><b>Got the look YOLO!<\/b><\/p>\n<p>So easy to get YOLO, it requires 3 files to download:<\/p>\n<ol>\n<li>File_1 : In order to run the network, you will have to download the pre-trained YOLO weight file (237 MB). <a href=\"https:\/\/pjreddie.com\/media\/files\/yolov3.weights\" target=\"_blank\" rel=\"noopener\">Download yolov3.weights<\/a><\/li>\n<li>File_2 : You have also download the the YOLO configuration file: yolov3.cfg &#8211; <a href=\"https:\/\/opencv-tutorial.readthedocs.io\/en\/latest\/_downloads\/10e685aad953495a95c17bfecd1649e5\/yolov3.cfg\" target=\"_blank\" rel=\"noopener\">Download yolov3.cfg<\/a><\/li>\n<li>File_3 : Get the 80 COCO class names: coco.names &#8211; <a href=\"https:\/\/opencv-tutorial.readthedocs.io\/en\/latest\/_downloads\/a9fb13cbea0745f3d11da9017d1b8467\/coco.names\" target=\"_blank\" rel=\"noopener\">Download coco.names<\/a><\/li>\n<\/ol>\n<p><b>You are done! You have the requirements to use YOLO.<\/b><\/p>\n<p><i>Source: <a href=\"https:\/\/opencv-tutorial.readthedocs.io\/en\/latest\/yolo\/yolo.html\" target=\"_blank\" rel=\"noopener\">https:\/\/opencv-tutorial.readthedocs.io\/en\/latest\/yolo\/yolo.html<\/a><\/i><\/p>\n<h3>Few commands to use MySQL<\/h3>\n<p>I suppose that you have installed MySQL on your computer. I always forget the main commands when I am in the console so here are quick reminders.<br \/>\nFor more explanations, you can check the previous post on facial recognition.<\/p>\n<pre lang=\"bash\">\r\n# to connect to the db\r\nmysql -u root -p \r\n<\/pre>\n<pre lang=\"sql\">\r\n# commands select and use db\r\nSHOW DATABASES;\r\nUSE yolo_images;\r\n\r\n# commands select and use db\r\nSHOW TABLES;\r\n# describe yolo_advanced_images\r\nDESCRIBE yolo_advanced_images;\r\n\r\n\r\n# select a dump .sql\r\nSOURCE \/Users\/brunoflaven\/Documents\/01_work\/blog_articles\/tensorflow_image_recognition\/mysql_yolo_advanced_images_1.sql\r\n\r\n# select all records\r\nSELECT COUNT(*) FROM yolo_advanced_images;\r\n\r\n# select all records\r\nSELECT * FROM yolo_advanced_images;\r\n\r\n# delete single image with the help of the id\r\nDELETE FROM yolo_advanced_images WHERE id = '96';\t\r\nDELETE FROM yolo_advanced_images WHERE id = '97';\r\n\r\n\r\n# empty table\r\nTRUNCATE TABLE yolo_advanced_images;\r\n<\/pre>\n<p><b>The table structure `yolo_advanced_images` for databas yolo_images<\/b><\/p>\n<pre lang=\"sql\">\r\nDROP TABLE IF EXISTS `yolo_advanced_images`;\r\n\r\nCREATE TABLE `yolo_advanced_images` (\r\n  `id` bigint unsigned NOT NULL AUTO_INCREMENT,\r\n  `file` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',\r\n`keywords` varchar\r\n(255) CHARACTER\r\nSET utf8mb4\r\nCOLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',\r\n  PRIMARY KEY (`id`)\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;\r\n\r\nLOCK TABLES `yolo_advanced_images` WRITE;\r\n\r\nINSERT INTO `yolo_advanced_images` (`id`, `file`)\r\nVALUES\r\n\t(NULL,'image1.jpg', 'keyword_1_img_1'),\r\n\t(NULL,'image1.jpg', 'keyword_2_img_1'),\r\n\t(NULL,'image2.jpg', 'keyword_1_img_2'),\r\n\t(NULL,'image3.jpg', 'keyword_1_img_3' );\r\n<\/pre>\n<p><b>Conclusion:<\/b> I have made also a translation in Spanish of the coco.names. You can just download the file coco_es.names from my github account. Meaning that I can tag in any language (English, Spanish, Russian, Portuguese&#8230;) images with the help of YOLO. So, for instance, I can provide a better image search in any language by providing a native language tagging system for the same dataset of images.<br \/>\nAfter, that, you can even improve the tagging system by coupling it with facial recognition. Using the principles detailed in my previous post on facial recognition, you&#8217;ll be able to precise who are the persons on pictures if it is a president, an NBA star&#8230; whatever the known faces images you drop in your sample aka the directory of know faces! So, that can inject proper noun like Macron, Trump, Bryan, Biden&#8230; in addition to the keyword created by YOLO for &#8220;person&#8221;. Then you are good! By injecting these new tags into the real multimedia database used in the CMS, you may considerably improve users&#8217; images searches and never felt anymore so miserable!<\/p>\n<p><i>Image copyright is <a href=\"https:\/\/www.vexels.com\/\" target=\"_blank\" rel=\"noopener\">www.vexels.com<\/a><\/i><\/p>\n<h3>Read more<\/h3>\n<ul>\n<li>Convenient functions for YOLO v4 based on AlexeyAB Darknet Yolo.<br \/><a href=\"https:\/\/darknet.gong.im\/\" target=\"_blank\" rel=\"noopener\">https:\/\/darknet.gong.im\/<\/a><\/li>\n<li>Darknet: Open Source Neural Networks in C<br \/><a href=\"https:\/\/pjreddie.com\/darknet\/\" target=\"_blank\" rel=\"noopener\">https:\/\/pjreddie.com\/darknet\/<\/a><\/li>\n<li>How to Perform YOLO Object Detection using OpenCV and PyTorch in Python<br \/><a href=\"https:\/\/www.thepythoncode.com\/article\/yolo-object-detection-with-opencv-and-pytorch-in-python\" target=\"_blank\" rel=\"noopener\">https:\/\/www.thepythoncode.com\/article\/yolo-object-detection-with-opencv-and-pytorch-in-python<\/a><\/li>\n<li>yoloface<br \/><a href=\"https:\/\/github.com\/sthanhng\/yoloface\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/sthanhng\/yoloface<\/a><\/li>\n<li>Working With Files in Python<br \/><a href=\"https:\/\/realpython.com\/working-with-files-in-python\/#listing-all-files-in-a-directory\" target=\"_blank\" rel=\"noopener\">https:\/\/realpython.com\/working-with-files-in-python\/#listing-all-files-in-a-directory<br \/>\n<\/a><\/li>\n<li>darknet<br \/><a href=\"https:\/\/github.com\/pjreddie\/darknet\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/pjreddie\/darknet<\/a><\/li>\n<li>TensorFlow Image Recognition Python API Tutorial<br \/><a href=\"https:\/\/towardsdatascience.com\/tensorflow-image-recognition-python-api-e35f7d412a70\" target=\"_blank\" rel=\"noopener\">https:\/\/towardsdatascience.com\/tensorflow-image-recognition-python-api-e35f7d412a70<\/a><\/li>\n<li>Object Detection with ImageAI in Python<br \/><a href=\"https:\/\/stackabuse.com\/object-detection-with-imageai-in-python\/\" target=\"_blank\" rel=\"noopener\">https:\/\/stackabuse.com\/object-detection-with-imageai-in-python\/<\/a><\/li>\n<li>YOLO Object Detection from image with OpenCV and Python<br \/><a href=\"https:\/\/www.codespeedy.com\/yolo-object-detection-from-image-with-opencv-and-python\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.codespeedy.com\/yolo-object-detection-from-image-with-opencv-and-python\/<\/a><\/li>\n<li>Run YoloV3 detections on thousands of images and save outputs? #723<br \/><a href=\"https:\/\/github.com\/pjreddie\/darknet\/issues\/723\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/pjreddie\/darknet\/issues\/723<\/a><\/li>\n<li>AlexeyAB\/darknet<br \/><a href=\"https:\/\/github.com\/AlexeyAB\/darknet\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/AlexeyAB\/darknet<\/a><\/li>\n<li>darkflow<br \/><a href=\"https:\/\/github.com\/thtrieu\/darkflow\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/thtrieu\/darkflow<\/a><\/li>\n<li>Review: YOLOv3 \u2014 You Only Look Once (Object Detection)<br \/><a href=\"https:\/\/towardsdatascience.com\/review-yolov3-you-only-look-once-object-detection-eab75d7a1ba6\" target=\"_blank\" rel=\"noopener\">https:\/\/towardsdatascience.com\/review-yolov3-you-only-look-once-object-detection-eab75d7a1ba6<\/a><\/li>\n<li>Tutorial: Build your custom real-time object classifier<br \/><a href=\"https:\/\/towardsdatascience.com\/tutorial-build-an-object-detection-system-using-yolo-9a930513643a\" target=\"_blank\" rel=\"noopener\">https:\/\/towardsdatascience.com\/tutorial-build-an-object-detection-system-using-yolo-9a930513643a<\/a><\/li>\n<li>Image recognition with TensorFlow and Keras<br \/><a href=\"https:\/\/developer.ibm.com\/technologies\/artificial-intelligence\/articles\/image-recognition-challenge-with-tensorflow-and-keras-pt1\" target=\"_blank\" rel=\"noopener\">https:\/\/developer.ibm.com\/technologies\/artificial-intelligence\/articles\/image-recognition-challenge-with-tensorflow-and-keras-pt1<\/a><\/li>\n<li>Deep Learning based Object Detection using YOLOv3 with OpenCV ( Python \/ C++ )<br \/><a href=\"https:\/\/learnopencv.com\/deep-learning-based-object-detection-using-yolov3-with-opencv-python-c\/\" target=\"_blank\" rel=\"noopener\">https:\/\/learnopencv.com\/deep-learning-based-object-detection-using-yolov3-with-opencv-python-c\/<br \/>\n<\/a><\/li>\n<li>Deep Learning with OpenCV<br \/><a href=\"https:\/\/www.pyimagesearch.com\/2017\/08\/21\/deep-learning-with-opencv\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.pyimagesearch.com\/2017\/08\/21\/deep-learning-with-opencv\/<br \/>\n<\/a><\/li>\n<li>Top 8 Image-Processing Python Libraries Used in Machine Learning<br \/><a href=\"https:\/\/neptune.ai\/blog\/image-processing-python-libraries-for-machine-learning\" target=\"_blank\" rel=\"noopener\">https:\/\/neptune.ai\/blog\/image-processing-python-libraries-for-machine-learning<\/a><\/li>\n<li>Image Recognition Tutorial in Python for Beginners<br \/><a href=\"https:\/\/howtocreateapps.com\/image-recognition-python\/\" target=\"_blank\" rel=\"noopener\">https:\/\/howtocreateapps.com\/image-recognition-python\/<\/a><\/li>\n<li>Image Recognition in Python with TensorFlow and Keras<br \/><a href=\"https:\/\/stackabuse.com\/image-recognition-in-python-with-tensorflow-and-keras\/\" target=\"_blank\" rel=\"noopener\">https:\/\/stackabuse.com\/image-recognition-in-python-with-tensorflow-and-keras\/<\/a><\/li>\n<li>image-recognition on github<br \/><a href=\"https:\/\/github.com\/topics\/image-recognition\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/topics\/image-recognition<\/a><\/li>\n<li>Object Detection on Custom Dataset with YOLO (v5) using PyTorch and Python<br \/><a href=\"https:\/\/curiousily.com\/posts\/object-detection-on-custom-dataset-with-yolo-v5-using-pytorch-and-python\/\" target=\"_blank\" rel=\"noopener\">https:\/\/curiousily.com\/posts\/object-detection-on-custom-dataset-with-yolo-v5-using-pytorch-and-python\/<\/a><\/li>\n<li>Emergency-Vehicle-Classification-YOLO<br \/><a href=\"https:\/\/github.com\/SiddiAvinashM10\/Emergency-Vehicle-Classification-YOLO\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/SiddiAvinashM10\/Emergency-Vehicle-Classification-YOLO<\/a><\/li>\n<li>Create a simple image classifier using Tensorflow<br \/><a href=\"https:\/\/medium.com\/@linjunghsuan\/create-a-simple-image-classifier-using-tensorflow-a7061635984a\" target=\"_blank\" rel=\"noopener\">https:\/\/medium.com\/@linjunghsuan\/create-a-simple-image-classifier-using-tensorflow-a7061635984a<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Still digging, in Python, on more versatile usage in object detection from images to improve a house-made CMS multimedia searches. What a sentence! So, maybe,&hellip; <\/p>\n<p class=\"text-center\"><a href=\"https:\/\/flaven.fr\/2021\/03\/improve-a-cmss-photos-library-qualification-with-ai-object-detection-from-images-in-python-with-opencv-and-yolo\/\" class=\"more-link\">Continue reading &rarr; <span class=\"screen-reader-text\">Improve a CMS&#8217;s photos library qualification with AI, Object Detection from images in Python with OpenCv and YOLO<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":11657,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"bf_ai_meta_description":"Improve CMS photo library with AI. Use Python, OpenCV, and YOLO for object detection. Enhance multimedia searches with precise tools.","bf_ai_og_title":"Improve CMS with AI Object Detection","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[3438,3437,3444,3447,3449],"tags":[2547,2549,2532,2659,2221,2535,2662,2542,2666,2546,2660,2540,2544,1924,2211,2539,2661,2536,2657,2531,154,2467,2665,2316,2664,3495,2663,2667,2538,2545,2658],"class_list":["post-11654","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai-machine-learning","category-business-case-studies","category-programming-databases","category-technology-trends","category-tutorials-how-to","tag-ai","tag-ai-takeover","tag-anaconda","tag-categorization","tag-cms","tag-computer-vision","tag-database","tag-deep-learning","tag-english","tag-facial-recognition","tag-gigo","tag-ia","tag-image-classification","tag-language","tag-mysql","tag-ntlk","tag-numpy","tag-object-detection","tag-opencv","tag-p-o","tag-photos","tag-pictures","tag-portuguese","tag-python","tag-russian","tag-sentence-transformers","tag-spanish","tag-tagging","tag-tensorflow-keras","tag-video-classification","tag-yolo"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3Vuhl-31Y","jetpack_featured_media_url":"https:\/\/flaven.fr\/wp-content\/uploads\/2021\/03\/yolo_object_detection_from_image_with_opencv_python_b.jpg","_links":{"self":[{"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/posts\/11654","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/comments?post=11654"}],"version-history":[{"count":10,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/posts\/11654\/revisions"}],"predecessor-version":[{"id":11949,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/posts\/11654\/revisions\/11949"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/media\/11657"}],"wp:attachment":[{"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/media?parent=11654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/categories?post=11654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/tags?post=11654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}