• Exception
  • O’zbekiston respublikasi axborot texnologiyalari va kommunikasiyalarini rivojlantirish vazirligi




    Download 1.37 Mb.
    bet1/3
    Sana01.04.2024
    Hajmi1.37 Mb.
    #184004
      1   2   3
    Bog'liq
    Amaliy ish
    493, [@ABTbooks] 5000 words in a month

    O’ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKASIYALARINI RIVOJLANTIRISH VAZIRLIGI
    MUHAMMAD AL-XORAZMIY NOMIDAGI
    TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
    DASTURIY INJINIRING FAKULTETI

    Amaliy ish


    Bajardi: Tekshirdi:



    Тoshkent – 2024

    # importing the general dependencies
    import pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport cv2import osimport warnings
    warnings.filterwarnings('ignore')
    In [33]:
    # Lets check what we have in our dataset
    dataset_root = '/kaggle/input/affectnet-yolo-format/YOLO_format/'
    for root, directories, files in os.walk(dataset_root):
    # Do something with the current directory path 'root'
    print("Current directory:", root)

    # Do something with the list of subdirectories 'directories'
    print("Subdirectories:", directories)

    # Do something with the list of files 'files'
    print("Files:", len(files))
    Current directory: /kaggle/input/affectnet-yolo-format/YOLO_format/
    Subdirectories: ['valid', 'test', 'train']
    Files: 1
    Current directory: /kaggle/input/affectnet-yolo-format/YOLO_format/valid
    Subdirectories: ['labels', 'images']
    Files: 0
    Current directory: /kaggle/input/affectnet-yolo-format/YOLO_format/valid/labels
    Subdirectories: []
    Files: 5406
    Current directory: /kaggle/input/affectnet-yolo-format/YOLO_format/valid/images
    Subdirectories: []
    Files: 5406
    Current directory: /kaggle/input/affectnet-yolo-format/YOLO_format/test
    Subdirectories: ['labels', 'images']
    Files: 0
    Current directory: /kaggle/input/affectnet-yolo-format/YOLO_format/test/labels
    Subdirectories: []
    Files: 2755
    Current directory: /kaggle/input/affectnet-yolo-format/YOLO_format/test/images
    Subdirectories: []
    Files: 2755
    Current directory: /kaggle/input/affectnet-yolo-format/YOLO_format/train
    Subdirectories: ['labels', 'images']
    Files: 0
    Current directory: /kaggle/input/affectnet-yolo-format/YOLO_format/train/labels
    Subdirectories: []
    Files: 17101
    Current directory: /kaggle/input/affectnet-yolo-format/YOLO_format/train/images
    Subdirectories: []
    Files: 17101
    In [34]:
    # Lets observe some images from three folders
    # Define the paths to the image foldersimage_folders = [
    "/kaggle/input/affectnet-yolo-format/YOLO_format/valid/images",
    "/kaggle/input/affectnet-yolo-format/YOLO_format/test/images",
    "/kaggle/input/affectnet-yolo-format/YOLO_format/train/images"]
    # Define the number of images you want to display from each foldernum_images_per_folder = 5
    # Create a subplot gridfig, axes = plt.subplots(len(image_folders), num_images_per_folder, figsize=(15, 10))
    # Loop through each image folderfor i, folder in enumerate(image_folders):
    image_files = os.listdir(folder)[:num_images_per_folder] # Get the list of image files
    for j, image_file in enumerate(image_files):
    image_path = os.path.join(folder, image_file)
    try:
    # Open and display the image
    img = plt.imread(image_path)
    axes[i, j].imshow(img)
    axes[i, j].axis('off')
    except Exception as e:
    print(f"Error opening image: {image_path}")
    # Adjust layoutplt.tight_layout()plt.show()

    In [35]:
    # Lets observe an individual image with its corresponding labellabels_map = {
    '0' : 'Anger',
    '1' : 'Contempt',
    '2' : 'Disgust',
    '3' : 'Fear',
    '4' : 'Happy',
    '5' : 'Neutral',
    '6' : 'Sad',
    '7' : 'Surprise'}
    random_number = 333train_images_path = '/kaggle/input/affectnet-yolo-format/YOLO_format/train/images'random_image_path = os.path.join(train_images_path, os.listdir(train_images_path)[random_number])random_image = plt.imread(random_image_path)
    train_labels_path = '/kaggle/input/affectnet-yolo-format/YOLO_format/train/labels'random_label_file = random_image_path.split('/')[-1].split('.')[0] + '.txt'random_label_path = os.path.join(train_labels_path, random_label_file)
    with open(random_label_path, 'r') as file:
    # first character is the label
    first_character = file.read(1)image_class = labels_map[first_character]
    print(random_label_path)print(random_image_path)
    plt.imshow(random_image)plt.title(f'{image_class}')plt.show()
    /kaggle/input/affectnet-yolo-format/YOLO_format/train/labels/ffhq_5410.txt
    /kaggle/input/affectnet-yolo-format/YOLO_format/train/images/ffhq_5410.png

    In [36]:
    # Class frequenciesclass_frequencies = np.array([])
    # Define the paths to the image folderslabel_folders = [
    "/kaggle/input/affectnet-yolo-format/YOLO_format/valid/labels",
    "/kaggle/input/affectnet-yolo-format/YOLO_format/test/labels",
    "/kaggle/input/affectnet-yolo-format/YOLO_format/train/labels"]
    # Iterate over each label directory (valid, test, train)for label_dir in label_folders:

    # Iterate over each .txt file in the labels directory
    for file_name in os.listdir(label_dir):
    if file_name.endswith('.txt'):
    file_path = os.path.join(label_dir, file_name)

    # Read the first character of the file
    with open(file_path, 'r') as file:
    first_character = file.read(1)

    class_frequencies = np.append(class_frequencies, first_character)
    In [37]:
    unique, counts = np.unique(class_frequencies, return_counts=True)unique_mapped = [labels_map[x] for x in unique]
    # Create the bar plotplt.bar(unique_mapped, counts)
    # Add labels and titleplt.xlabel('Number')plt.ylabel('Frequency')plt.title('Frequency of Numbers')plt.xticks(rotation=45)
    # Show the plotplt.show()


    Download 1.37 Mb.
      1   2   3




    Download 1.37 Mb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    O’zbekiston respublikasi axborot texnologiyalari va kommunikasiyalarini rivojlantirish vazirligi

    Download 1.37 Mb.