Based on the full range of yolov5 models [n/s/m/l/x], develop and construct a fine-grained target detection and recognition system for cats with different parameter levels

I have always been a fan of cat animals. When I was a child at home, I always had a few cats to kill time. One of my recent ideas is to develop a fine-grained animal detection and recognition system. The core of this article is based on cat data. To develop and build a fine-grained detection and recognition system for cats, first look at the renderings:

 The data set used in this article is collected and obtained from Baidu search engine, and then manually classified and marked.

The code uses the requests library to send HTTP requests and parse the JSON data of Baidu image search results. Then, it will download the specified number of images and save them to a local folder ("./images" in the example). When using this crawler, please pay attention to comply with the usage rules and laws and regulations of the website. The core code implementation is as follows:

import os
import requests
from urllib.parse import quote

def baidu_image_crawler(keyword, num_images):
    keyword = quote(keyword)  # 对关键词进行URL编码
    url = f"https://image.baidu.com/search/acjson?tn=resultjson_com&ipn=rj&word={keyword}&pn=0&rn={num_images}"
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36"
    }
    
    response = requests.get(url, headers=headers)
    response.raise_for_status()
    data = response.json()

    save_dir = "./images"  # 图片保存目录
    if not os.path.exists(save_dir):
        os.makedirs(save_dir)

    for item in data["data"]:
        if "thumbURL" in item:
            image_url = item["thumbURL"]
            try:
                response = requests.get(image_url, headers=headers)
                response.raise_for_status()
                file_name = image_url.split("/")[-1]
                save_path = os.path.join(save_dir, file_name)
                with open(save_path, "wb") as f:
                    f.write(response.content)
                print(f"Saved image: {file_name}")
            except Exception as e:
                print(f"Failed to download image: {image_url}, Error: {e}")

# 示例用法
keyword = "cat"  # 输入关键词
num_images = 10  # 需要下载的图片数量
baidu_image_crawler(keyword, num_images)

After manual processing, the required data set is obtained. Next, simply look at the data set:

 A total of 12 different types of cat data have been collected and obtained here, because I am not very familiar with many cat species. The data of each type of data specially compiled here are as follows. If you are interested, you can read it. If you are familiar with it If you don’t, you don’t need to read more, here is the right to give yourself a science introduction to learn and understand.

【Abyssian cat】

The Abyssian cat is a cat breed from Ethiopia, Africa. They are characterized by a long body, long legs and a pointed tail. The Abyssian cat has a distinctive brindle coat color, usually showing a light brown base with black lines. Their eyes are generally green or yellow-green. Abyssian cats are lively and intelligent, and love to interact with people and perform activities. They are very curious about their surroundings and their family and love to be involved in various activities. The Abyssian is a popular domestic cat breed considered by many to be an ideal companion animal.

【leopard cat】

Leopard cats are small and medium-sized cats, mainly distributed in Asia, such as China, India and other places. They have distinctive leopard-like spots, hence the name ocelot. Leopard cats are relatively small, usually about 40-60 cm in length, 25-40 cm in tail length, and 2-5 kg ​​in weight. With their flexible bodies and keen minds, they are excellent climbers and hunters.

Leopard cats usually live in environments such as forests, mountains and jungles. They are good at hiding and hunting skills and feed on small mammals, birds and reptiles. Leopard cats are mainly active at night and are nocturnal animals.

Ocelots bear some resemblance to leopards in appearance, but they are smaller and have less prominent spots and bushy fur. The color of the leopard cat's coat varies from region to region, and is generally grayish brown with black and brown markings on the undercoat. This makes them great camouflage abilities in their natural environment.

Leopard cats are protected in some areas as their numbers dwindle, mainly due to habitat destruction and illegal hunting. As wild animals, leopard cats are not suitable for keeping as pets and should be protected and respected.

[Hakuman cat]

The Birman cat is a long-bodied cat with a light golden coat. Birmans have a narrow face with contrasting colors between the face, ears, head and tail. The eyes of the Birman cat are unique sapphire pupils, and its limbs and soles are as cute as wearing white socks.

Birman cats are gentle and gentle, very friendly and have a melodious meow. Birman cats are medium-sized cats with only key color patches, strong muscles, medium-length limbs, and large and round paws.

【Bombay cat】

The Bombay cat is a famous short-haired cat bred in the United States. The whole body is pitch-black, shiny, and the short hair clings to the body, like patent leather. The Bombay cat is bred by crossing the Burmese cat and the American short-haired cat. It not only retains the color of the American short-haired cat, but also looks like a Burmese cat. It has a unique color-black, the kittens are slightly lighter, and the adult cats are black and monochromatic, with short and shiny hair. They are called "little black panthers".

【British Shorthair】

The British Shorthair is a well-known short-haired cat breed that originated in the United Kingdom. They have full, full bodies and a thick coat, giving them a straight, close-fitting appearance.

British Shorthairs come in a wide variety of coat colors and patterns, including single, bi-color, tri-color, spots, and stripes. Their eyes are usually a rich orange or yellow color that contrasts with their coat.

The cats of this breed are gentle and calm, and are generally considered a friendly, approachable and easy-going cat. They often display loyalty, patience, and closeness to their owners and family, but also need their own personal space and independent time.

British Shorthairs are generally inactive and relatively domestic. They usually like a comfortable environment and a quiet family life. While they are very friendly with their family, they may show some reservations with strangers.

It is very important for someone looking to keep a British Shorthair cat to provide them with high-quality food, moderate exercise and regular veterinary care. Beyond that, regular grooming can help keep them healthy and looking good.

Overall, the British Shorthair is a gentle, friendly and adaptable cat breed that makes it a great family pet. Their charm lies not only in their appearance and coat, but also in the bond they develop with their families

【Egyptian cat】

The Egyptian cat is a large, muscular cat with stubby limbs and short and dense hair. Its coat is soft and thick like velvet, rarely sheds and is easy to manage.

The history of cats in ancient Egyptian homes can be traced back to 3000-4000 BC, but the cats at that time may have been tame wild cats rather than domesticated cats. Beginning in 1900 BC, the ancient Egyptians began to raise some domesticated cats, but most of the cats at this time were "African wild cats" (libyca). By 1450 BC, cats became one of the frequent pets in Egyptian homes.

【Maine Coon】

The Maine Coon is a large, strong breed of short-haired cat that originated in the American state of Maine. They are a naturally occurring breed and the only African short-haired cats in North America.

Maine Coon cats have thick, bushy coats that are especially adapted to cold climates. They have a multi-layered coat that includes a waterproof outer layer and a downy inner layer. This makes them better adapted to cold temperatures when they are outdoors.

Maine Coon cats have a robust body with a strong bone structure and well-developed muscles. Their forelimbs are slightly longer than their hindlimbs, giving them a slightly raised back appearance. They have broad heads and golden or green eyes. The tail is bushy and tapered.

Maine Coons are very friendly, gentle, affectionate and sociable. They are generally friendly with family members and strangers, and get along well with children and other pets. They love closeness and attention and tend to be active in the family.

Although Maine Coons have a larger size, they are generally not as active and agile as other large cats. They are better suited to indoor living, but also need plenty of room to move around and explore.

Maine Coon cats are relatively simple to maintain, and their coats need to be brushed once a week to keep them in good condition. They have no special requirements for food, but they need to provide high-quality cat food to meet their nutritional needs.

Overall, the Maine Coon is a gentle, friendly, and approachable cat breed that makes a great family companion. Their appearance and character traits make them beloved and ideal for many.

【Persian cat】

The Persian cat is a very well-known long-haired cat breed that originated in the Persian region (present-day Iran). They are known around the world for their beautiful appearance, bushy coat, and gentle disposition.

Persian cats have a pie-shaped head, wide and round faces, large round eyes, short flat noses, and small, intriguing mouths. Their bodies are strong and short, their limbs are short and thick, and their backs are straight. The most notable feature is its thick, long, full coat, which comes in a wide variety of colors and patterns.

Persian cats are gentle and friendly cats. They tend to be calm and quiet, and like to relax and enjoy gentle human company. They are often reserved towards strangers and show loyalty and affection towards family members. Due to its relatively domestic personality, Persian cats are suitable for living in indoor environments.

Due to their long, bushy coat, Persian cats require regular grooming and cleaning. This prevents matting, fluff and skin problems from occurring.

In terms of maintenance, Persian cats need to provide high-quality cat food to meet their nutritional needs and maintain an appropriate amount of water intake. In addition, regular veterinary check-ups and vaccinations are also essential.

All in all, the Persian cat is a very elegant, gentle and beautiful cat breed. Their appearance and personality make them an ideal pet choice for many, but keeping a Persian takes a little extra care and time.

【cat plush】

The Ragdoll is a very popular cat breed known around the world for its gentle disposition and charming appearance. They get their name from their soft, ragdoll-like appearance.

Ragdolls originated in the United States and were first bred in the 1960s. One of their characteristics is their large, bright blue eyes, which give them a gentle and loving appearance. They have a medium-sized body with strong bones in proportion to their body. The Ragdoll's coat is long and full, exhibiting a soft texture, usually a double coat of semi-medium length velvet on the outside and a dense undercoat on the inside.

Ragdolls are known for their friendly, gentle and quiet disposition. They are very affectionate and good at forming strong bonds with family members and strangers alike. Ragdolls are well adapted to devoted home environments, love to be involved in family activities, and are friendly with children and other pets. They usually follow humans around the house instead of walking alone like other cats.

Like other long-haired cats, the Ragdoll's coat requires regular brushing and grooming to maintain its good appearance. At the same time, regular bathing is also necessary to keep their coat clean.

Ragdoll cats have no special requirements for food, but they need to provide high-quality cat food to meet their nutritional needs. At the same time, moderate exercise and regular veterinary inspections are also required for the maintenance of puppet cats.

All in all, the Ragdoll is a gentle, friendly and beautiful cat breed. They are very suitable as family pets, good at getting close to people, and bring unlimited happiness and companionship.

【Russian blue cat】

Russian Blue (Russian Blue) is an ancient cat breed that originated in Russia. They are known for their distinctive grey-blue coat, emerald green eyes, and elegant appearance.

The Russian Blue has a medium-sized body that is compact and muscular. Their heads are streamlined, with large, bright eyes and oval outlines. Their coat is very short and close, giving it a smooth feel. The color is its most distinguishing feature, a deep and uniform grayish-blue hue that appears smoky and soft.

Russian Blues are known for their gentle and calm disposition. They are usually very close to their families but can be somewhat reserved towards strangers. They like quiet surroundings and dislike places that are too loud or busy. These cats often develop a strong bond with their owners, enjoying the company of humans and participating in their daily activities.

Russian Blue cats require less effort to maintain. Due to their short, close-knit coat, they require only regular grooming and brushing to keep their coat smooth and clean. In addition, providing high-quality cat food, proper hydration and regular veterinary check-ups are also essential.

All in all, the Russian Blue is a graceful, calm and beautiful cat breed. Their gentle disposition and unique appearance make them ideal pets for many people. Whether in a family or as a single person, these cats provide endless joy and companionship.

【Thai Siamese cat】

Thai Siamese cat (Siamese cat) is an ancient and well-known cat breed, which originated in Thailand (the old name is Siam, hence the name). They are known for their blue eyes, spotted coat, and gentle disposition.

The Thai Siamese cat has an elegant appearance with a slender and well-proportioned body with strong muscles. Their heads are wedge-shaped and their eyes are large, bright and dark blue. The most striking feature of the Thai Siamese cat is its coat, which presents a light-colored body with darker spots on the ears, face, tail, and limbs.

Thai Siamese cats are known for their friendliness, approachability and lively disposition. They are very dependent on human companionship and love to be part of and form a strong bond with their family. These cats usually take the initiative to interact with people, willing to talk to people and make various sounds.

Thai Siamese cats have a low-maintenance coat that requires only regular grooming and brushing to keep it looking neat and smooth. In addition, providing high-quality cat food, regular veterinary check-ups and moderate exercise are also required for raising Thai Siamese cats.

All in all, the Thai Siamese cat is a beautiful, friendly and lively cat breed. They are suitable for being intimate with humans and can bring endless joy and joy to the family. Whether in a family or as a single person, these cats make lovely companions and companions.

【Sphynx cat】

The Sphinx cat is a peculiar breed with no hair all over the body, somewhat like the famous monster Sphinx Sphinx in ancient Egyptian mythology, so people named it the Sphinx cat. The Canadian Hairless cat is not completely hairless, its hair is very fine and close to the skin, it feels like a warm peach.

Sphynx cats are lively, playful, independent, non-aggressive, and can get along with other dogs and cats. Rich in affection, hoping to be favored by the owner.

Next, you can develop and build the training model. Here we have developed and used the yolov5 series of five models with different magnitude parameters to develop and build the cat detection and recognition model respectively. In order to be able to compare and analyze the overall The comparative analysis visualization looks like this:

The first is the F1 value comparison curve:

 Next, compare and visualize the changes in the loss curves during the training of five different models, as shown below:

 After that is the accuracy rate comparison curve, as shown below:

 Finally, the recall comparison curve is as follows:

 In order to further analyze the principle of model detection and recognition, GRADCAM is integrated here to visualize the ability of model detection and recognition, as shown below:

 If you are interested, you can also try to build your favorite animal fine-grained detection and recognition system. Practice can still bring you more progress and recognition.

Guess you like

Origin blog.csdn.net/Together_CZ/article/details/131430520