image_output_1.png
import cv2

import matplotlib.pyplot as plt

import os

import os

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import os

BASE_DIR = '/kaggle/input/global-wheat-detection/'
train_data = pd.read_csv(BASE_DIR + 'train.csv')
submission_file = pd.read_csv(BASE_DIR + 'sample_submission.csv')
train_images_dir = BASE_DIR + 'train/'

train_data.isna().sum()

train_data.nunique()

train_data.source.unique()

all_images = set((x.split('.')[0] for x in os.listdir(train_images_dir)))
images_with_bb = set(train_data.image_id.unique())
images_without_bb = all_images ^ images_with_bb

df_images_without_bb = pd.DataFrame(images_without_bb, columns=['image_id'])

def plot_images(image_list,rows,cols,title):
    fig,ax = plt.subplots(rows,cols,figsize = (16,5))
    ax = ax.flatten()
    for i, image_id in enumerate(image_list):
        image = cv2.imread(train_images_dir+'{}.jpg'.format(image_id))
        image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
        ax[i].imshow(image)
        ax[i].set_axis_off()
        ax[i].set_title(image_id)
    plt.suptitle(title)
    
# def plot_images_with_bb(train_data,rows,cols,title):
#     fig,ax = plt.subplots(rows,cols,figsize = (16,5))
#     ax = ax.flatten()
#     for row in train_data.iterrows():
#         image = cv2.imread(train_images_dir+'{}.jpg'.format(row[1]["image_id"]))
#         image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
#         image = cv2.rectangle(image,(row[1]["bbox"][0],row[1]["bbox"][1]),(row[1]["bbox"][0]+row[1]["bbox"][2],row[1]["bbox"][1]+row[1]["bbox"][3]),255,2)
#         ax[i].imshow(image)
#         ax[i].set_axis_off()
#         ax[i].set_title(image_id)
#     plt.suptitle(title)

plot_images(df_images_without_bb.sample(10)['image_id'].values, 2, 5, 'Images without wheat')