Kaggle competition: Global Wheat Detection
<SOS> metric: custom metric Kaggle data source: global-wheat-detection<save_to_csv>
import numpy as np
import pandas as pd
import os
df.to_csv('crf_correction.csv',index=False )<load_from_csv>
!pip install -U /kaggle/input/orkatzfdata/torch-1.5.0+cu101-cp37-cp37m-linux_x86_64.whl /kaggle/input/orkatzfdata/torchvision-0.6.0+cu101-cp37-cp37m-linux_x86_64.whl
train_df = pd.read_csv('.. /input/train.csv')
 test_df = pd.read_csv('.. /input/test.csv')
 sub_df = pd.read_csv('.. /input/sample_submission.csv' )<count_missing_values>
!pip install '/kaggle/input/pycocotools/pycocotools-2.0-cp37-cp37m-linux_x86_64.whl'
!pip install /kaggle/input/orkatzfdata/yacs-0.1.7-py3-none-any.whl
!mkdir fvcore
!cp -R '/kaggle/input/orkatzfdata/fvcore-0.1.dev200407/fvcore-0.1.dev200407/'./fvcore
!pip install fvcore/fvcore-0.1.dev200407/.
 !mkdir detectron2-ResNeSt
!cp -R /kaggle/input/orkatzfdata/detectron2-ResNeSt/*./detectron2-ResNeSt/
!pip install detectron2-ResNeSt/ .
train_df.isna().sum()<count_missing_values>
setup_logger()
test_df.isna().sum()<feature_engineering>
cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCO-Detection/faster_cascade_rcnn_ResNeSt_101_FPN_syncbn_range-scale_1x.yaml"))
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 1
cfg.MODEL.WEIGHTS = os.path.join('/kaggle/input/model-pth2/', "model_fold2.pth")
 cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.4
cfg.DATASETS.TEST =("m5_val",)
 predictor1 = DefaultPredictor(cfg )
def genres_preprocessing(elem):
string = str(elem)
 str1 = string.replace(']','' ).replace('[','' ).replace('{','' ).replace('}','' ).replace (<feature_engineering>
df_sub = pd.read_csv('/kaggle/input/global-wheat-detection/sample_submission.csv' )
genres_df.index.values
for g in genres_df.index.values:
train_df['isGenre_' + g] = train_df['genres_processed'].apply(lambda x: 1 if g in x else 0)
 test_df['isGenre_' + g] = test_df['genres_processed'].apply(lambda x: 1 if g in x else 0 )<feature_engineering>
def format_prediction_string(boxes, scores):
pred_strings = []
for j in zip(scores, boxes):
pred_strings.append("{0:.4f} {1} {2} {3} {4}".format(j[0], j[1][0], j[1][1], j[1][2], j[1][3]))
return " ".join(pred_strings )
train_df["is_english_language"] = train_df.original_language.apply(lambda x: 1 if x == "en" else 0)
 test_df["is_english_language"] = test_df.original_language.apply(lambda x: 1 if x == "en" else 0)
 train_df.is_english_language = train_df.is_english_language.fillna(1)
 test_df.is_english_language = test_df.is_english_language.fillna(1)
 sns.set(rc={'figure.figsize':(12,8)})
 ax = sns.countplot(x="is_english_language", data=train_df )<feature_engineering>
results = []
for image_id in df_sub['image_id']:
im = cv2.imread('/kaggle/input/global-wheat-detection/test/{}.jpg'.format(image_id))
boxes = []
scores = []
labels = []
outputs = predictor1(im)
 out = outputs["instances"].to("cpu")
 scores = out.get_fields() ['scores'].numpy()
boxes = out.get_fields() ['pred_boxes'].tensor.numpy().astype(int)
 labels= out.get_fields() ['scores'].numpy()
boxes = boxes.astype(int)
 boxes[:, 2] = boxes[:, 2] - boxes[:, 0]
boxes[:, 3] = boxes[:, 3] - boxes[:, 1]
result = {'image_id': image_id,'PredictionString': format_prediction_string(boxes, scores)}
results.append(result )
<feature_engineering><EOS> 
test_df = pd.DataFrame(results, columns=['image_id', 'PredictionString'])
 test_df.to_csv('submission.csv', index=False )