Kaggle competition: Natural Language Processing with Disaster Tweets
<SOS> metric: meanfscore Kaggle data source: natural-language-processing-with-disaster-tweets<choose_model_class>
pip install -U lightautoml
model_struct = 'tf_efficientdet_d7'
def get_valnet_file(Get_Path):
config = get_efficientdet_config(model_struct)
 net = EfficientDet(config, pretrained_backbone=False)
 config.num_classes = 1
config.image_size = img_size
net.class_net = HeadNet(config, num_outputs=config.num_classes, norm_kwargs=dict(eps=.001, momentum=.01))
checkpoint = torch.load(Get_Path)
 net.load_state_dict(checkpoint['model_state_dict'])
 del checkpoint
net = DetBenchEval(net, config)
 net.eval() ;
return net.cuda()
def makePseudolabel() :

 use_cuda = True
max_label_numbers = 0
DATA_ROOT_PATH = '.. /input/global-wheat-detection/test'
image_ids = [path.split('/')[-1][:-4] for path in glob(f'{DATA_ROOT_PATH}/*.jpg')]
model = Darknet(CONFIG)
 model.load_weights(WEIGHTS)
 if use_cuda:
model.cuda()
if Effdet:
net = get_valnet_file(PESUDO_WEIGHTS)
 model.eval()
num_classes = model.num_classes
class_names = 'wheat'
count = 0
pesudo_result = []
for image_id in image_ids:
enboxes = []
enscores = []
try:
img = cv2.imread(f'{DATA_ROOT_PATH}/{image_id}.jpg')
 img = cv2.resize(img,(model.width, model.height))
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
 if Yolov4:
if is_ROT:
for i in range(4):
img1 = TTAImage(img, i)
 img1 = img1.transpose(2, 0, 1)
 img1 = torch.from_numpy(img1 ).float().div(255.0 ).unsqueeze(0)
 img1 = img1.cuda()
img1 = torch.autograd.Variable(img1)
 with torch.no_grad() :
output = model(img1)
 boxes = utils.post_processing(img1, NMS_CONF_THR, NMS_CONF_THR, output)
 det = np.array(boxes)
 if det.size !=0:
boxes, scores = process_det(0, det, NMS_CONF_THR)
 for _ in range(3-i):
boxes = rotBoxes90(boxes, *img.shape[:2])
 enboxes.append(boxes)
 enscores.append(scores)
 with torch.no_grad() :
img1 = img.transpose(2, 0, 1)
 img1 = torch.from_numpy(img1 ).float().div(255.0 ).unsqueeze(0)
 img1 = img1.cuda()
img1 = torch.autograd.Variable(img1)
 output = model(img1)
 boxes = utils.post_processing(img1, NMS_CONF_THR, NMS_CONF_THR, output)
 det = np.array(boxes)
 if det.size !=0:
boxes, scores = process_det(0, det, NMS_CONF_THR)
 enboxes.append(boxes)
 enscores.append(scores)
 if Effdet:
img1 = img.transpose(2, 0, 1)
 img1 = torch.from_numpy(img1 ).cuda()
img1 = img1.float()
img1 /= 255.0
if p_HF:
with torch.no_grad() :
imgs = torch.stack(( img1,)).float().cuda()
for tta_transform in tta_transforms:
det = net(tta_transform.batch_augment(imgs.clone()), torch.tensor([1]*imgs.shape[0] ).float().cuda())
 for i in range(imgs.shape[0]):
boxes = det[i].detach().cpu().numpy() [:,:4]
scores = det[i].detach().cpu().numpy() [:,4]
indexes = np.where(scores > pesudo_thres)[0]
boxes = boxes[indexes]
boxes[:, 2] = boxes[:, 2] + boxes[:, 0]
boxes[:, 3] = boxes[:, 3] + boxes[:, 1]
boxes = tta_transform.deaugment_boxes(boxes.copy())
 enboxes.append(boxes)
 enscores.append(scores)
 boxes, scores, labels = run_wbf(enboxes, enscores, image_size=1024, iou_thr=best_iou_thr, skip_box_thr=best_skip_box_thr)
 boxes = boxes.astype(np.int32 ).clip(min=0, max=1024)
 indices = scores >= best_score_threshold
boxes = boxes[indices]
scores = scores[indices]
lineo = ''
for box in boxes:
x, y, x1, y1 = box
lineo += ' %d,%d,%d,%d,0'%(x, y, x1, y1)
 os.makedirs('convertor', exist_ok=True)
 if len(lineo)>0:
with open('convertor/train.txt', 'a')as f:
f.write(f'{image_id}.jpg')
 f.write(lineo)
 f.write('
')
 sh.copy(".. /input/global-wheat-detection/test/{}.jpg".format(image_id),'convertor/{}.jpg'.format(image_id))
result = {
'image_id': image_id,
'box': enboxes,
'score': enscores
}
if boxes.shape[0]>max_label_numbers:
max_label_numbers = boxes.shape[0]
pesudo_result.append(result)
 print(path,image_id)
 except:
boxes = []
scores = []
print('one error')
 return pesudo_result, max_label_numbers 
<load_pretrained>
pip install -U transformers
if is_TEST:
if PSEUDO:
remain_times = 60
!python train.py -TRAIN_EPOCHS {EPO} -cfgfile {CONFIG} -op {OPTIMIZER} -dir /kaggle/working/convertor -pretrained {WEIGHTS} -train_label_path convertor/train.txt -val_label_path convertor/val.txt -optimizer radam -iou-type ciou -l 0.0001 -g 0 -classes 1 -maxboxes {max_label_numbers+10} -time_limit {remain_times}
else:
pass
else:
pass 
<find_best_params>
import os
import time
import numpy as np
import pandas as pd
from sklearn.metrics import f1_score
from sklearn.model_selection import train_test_split
import torch
import matplotlib.pyplot as plt
from lightautoml.automl.presets.text_presets import TabularNLPAutoML
from lightautoml.dataset.roles import DatetimeRole
from lightautoml.tasks import Task
if VALIDATE and is_TEST:
all_predictions = validate()

 for score_threshold in tqdm(np.arange(0.1, 0.25, 0.01), total=np.arange(0.1, 0.25, 0.01 ).shape[0]):
final_score = calculate_final_score(all_predictions, best_iou_thr, best_skip_box_thr, score_threshold)
 if final_score > best_final_score:
best_final_score = final_score
best_score_threshold = score_threshold
print('-'*30)
 print(f'[Best Score Threshold]: {best_score_threshold}')
 print(f'[OOF Score]: {best_final_score:.4f}')
 print('-'*30)
<define_variables>
N_THREADS = 4
RANDOM_STATE = 42
TEST_SIZE = 0.2
TIMEOUT = 6 * 3600
TARGET_NAME = 'target'
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)
 def detect_cv2(pesudo_result):

 use_cuda = True
DATA_ROOT_PATH = '.. /input/global-wheat-detection/test'
image_ids = [path.split('/')[-1][:-4] for path in glob(f'{DATA_ROOT_PATH}/*.jpg')]
weights = 'checkpoints/last.pt'
Effdet = False
if not os.path.exists(weights):
Effdet = True
model = Darknet(CONFIG)
 model.load_weights(WEIGHTS)
 print('OLD WEIGHT')
 else:
model = torch.load(weights)
 if(len(pesudo_result)>0)and(GET_PESUDO==True):
print('get pesudo label')
 if use_cuda:
model.cuda()
if Effdet:
net = get_valnet_file(PESUDO_WEIGHTS)
 model.eval()
num_classes = model.num_classes
class_names = 'wheat'
results = []
fig, ax = plt.subplots(5, 2, figsize=(30, 70))
count = 0
for image_id in image_ids:
enboxes = []
enscores = []
try:
img = cv2.imread(f'{DATA_ROOT_PATH}/{image_id}.jpg')
 h, w = img.shape[:2]
img = cv2.resize(img,(model.width, model.height))
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
 if Yolov4:
if is_ROT:
for i in range(4):
img1 = TTAImage(img, i)
 with torch.no_grad() :
img1 = img1.transpose(2, 0, 1)
 img1 = torch.from_numpy(img1 ).float().unsqueeze(0 ).cuda()
img1 /= 255.0
img1 = torch.autograd.Variable(img1)
 output = model(img1)
 boxes = utils.post_processing(img1, NMS_CONF_THR, NMS_CONF_THR, output)
 det = np.array(boxes)
 boxes, scores = process_det(0, det, NMS_CONF_THR)
 for _ in range(3-i):
boxes = rotBoxes90(boxes, *img.shape[:2])
 enboxes.append(boxes)
 enscores.append(scores)
 with torch.no_grad() :
img1 = img.transpose(2, 0, 1)
 img1 = torch.from_numpy(img1 ).float().unsqueeze(0 ).cuda()
img1 /= 255.0
img1 = torch.autograd.Variable(img1)
 output = model(img1)
 boxes = utils.post_processing(img1, NMS_CONF_THR, NMS_CONF_THR, output)
 det = np.array(boxes)
 boxes, scores = process_det(0, det, NMS_CONF_THR)
 enboxes.append(boxes)
 enscores.append(scores)
 if Effdet:
img1 = img.transpose(2, 0, 1)
 img1 = torch.from_numpy(img1 ).cuda()
img1 = img1.float()
img1 /= 255.0
if p_HF:
with torch.no_grad() :
imgs = torch.stack(( img1,)).float().cuda()
for tta_transform in tta_transforms:
det = net(tta_transform.batch_augment(imgs.clone()), torch.tensor([1]*imgs.shape[0] ).float().cuda())
 for i in range(imgs.shape[0]):
boxes = det[i].detach().cpu().numpy() [:,:4]
scores = det[i].detach().cpu().numpy() [:,4]
indexes = np.where(scores > pesudo_thres)[0]
boxes = boxes[indexes]
boxes[:, 2] = boxes[:, 2] + boxes[:, 0]
boxes[:, 3] = boxes[:, 3] + boxes[:, 1]
boxes = tta_transform.deaugment_boxes(boxes.copy())
 enboxes.append(boxes)
 enscores.append(scores)
 if(len(pesudo_result)>0)and(GET_PESUDO==True):
if next(( inx for(inx,dic)in enumerate(pesudo_result)if dic['image_id']==image_id), None)is not None:
enboxes.extend(pesudo_result[next(( inx for(inx,dic)in enumerate(pesudo_result)if dic['image_id']==image_id), None)]['box'])
 enscores.extend(pesudo_result[next(( inx for(inx,dic)in enumerate(pesudo_result)if dic['image_id']==image_id), None)]['score'])
 boxes, scores, labels = run_wbf(enboxes, enscores, image_size=1024, iou_thr=best_iou_thr, skip_box_thr=best_skip_box_thr)
 boxes =(boxes/1024*h ).astype(np.int32 ).clip(min=0, max=h)
 boxes[:, 2] = boxes[:, 2] - boxes[:, 0]
boxes[:, 3] = boxes[:, 3] - boxes[:, 1]
indices = scores >= best_score_threshold
boxes = boxes[indices]
scores = scores[indices]
if(count<10)and(is_TEST==False):
img_ = img
for box, score in zip(boxes,scores):
cv2.rectangle(img_,(box[0], box[1]),(box[2]+box[0], box[3]+box[1]),(220, 0, 0), 2)
 cv2.putText(img_, '%.2f'%(score),(box[0], box[1]), cv2.FONT_HERSHEY_SIMPLEX, 0.5,(255,255,255), 2, cv2.LINE_AA)
 ax[count%5][count//5].imshow(img_)
 count+=1
except:
boxes = []
scores = []
print('one error')
 pass
result = {
'image_id': image_id,
'PredictionString': format_prediction_string(boxes, scores)
 }
results.append(result)
 return results<save_to_csv>
np.random.seed(RANDOM_STATE)
 torch.set_num_threads(N_THREADS )
results = detect_cv2(pesudo_result)
 test_df = pd.DataFrame(results, columns=['image_id', 'PredictionString'])
 test_df.to_csv('submission.csv', index=False)
 test_df.head()<import_modules>
%%time
train_data = pd.read_csv('.. /input/nlp-getting-started/train.csv')
 train_data.head()
sys.path.insert(0, ".. /input/weightedboxesfusion")
 device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
 print(device)
<choose_model_class>
test_data = pd.read_csv('.. /input/nlp-getting-started/test.csv')
 test_data.head()
def load_resnet101_model(checkpoint_path):
num_classes = 2
backbone = resnet_fpn_backbone('resnet101', pretrained= False)
 model_faster = FasterRCNN(backbone, num_classes)
 in_features = model_faster.roi_heads.box_predictor.cls_score.in_features
model_faster.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)
 checkpoint = torch.load(checkpoint_path)
 model_faster.load_state_dict(checkpoint['model_state_dict'])
 model_faster.to(device);
model_faster.eval()
return model_faster
def load_resnet50_model(checkpoint_path):
num_classes = 2
backbone = resnet_fpn_backbone('resnet50', pretrained= False)
 model_faster = FasterRCNN(backbone, num_classes)
 in_features = model_faster.roi_heads.box_predictor.cls_score.in_features
model_faster.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)
 model_faster.to(device);
checkpoint = torch.load(checkpoint_path)
 model_faster.load_state_dict(checkpoint['model_state_dict'])
 model_faster.to(device);
model_faster.eval()
return model_faster
def load_resnet152_model(checkpoint_path):
num_classes = 2
backbone = resnet_fpn_backbone('resnet152', pretrained= False)
 model_faster = FasterRCNN(backbone, num_classes)
 in_features = model_faster.roi_heads.box_predictor.cls_score.in_features
model_faster.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)
 model_faster.to(device);
checkpoint = torch.load(checkpoint_path)
 model_faster.load_state_dict(checkpoint['model_state_dict'])
 model_faster.to(device);
model_faster.eval()
return model_faster 
<define_variables>
submission = pd.read_csv('.. /input/nlp-getting-started/sample_submission.csv')
 submission.head()
resnet101_33e = ".. /input/resnet10133e-1024/cp33.pt"
resnet50 = ".. /input/resnet50-40e/resnet50_40e.pt"
resnet101_25e = ".. /input/resnet101mymodel/cp25.pt"
resnet152_20e = ".. /input/resnet152-20e/cp20.pt"
resnet152_19e =".. /input/resnet152-19e/cp19(1 ).pt"<load_pretrained>
train_data.target.value_counts()
models = [
load_resnet50_model(resnet50),
load_resnet152_model(resnet152_20e),
load_resnet152_model(resnet152_19e)
 ]<data_type_conversions>
train_data['keyword'].value_counts(dropna = False )
DATA_ROOT_PATH = '.. /input/global-wheat-detection/test/'
class DatasetRetriever(Dataset):
def __init__(self, image_ids, transforms=None):
super().__init__()
self.image_ids = image_ids
self.transforms = transforms
def __getitem__(self, index: int):
image_id = self.image_ids[index]
image = cv2.imread(f'{DATA_ROOT_PATH}/{image_id}.jpg', cv2.IMREAD_COLOR)
 image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB ).astype(np.float32)
 image /= 255.0
if self.transforms:
sample = {'image': image}
sample = self.transforms(**sample)
 image = sample['image']
return image, image_id
def __len__(self)-> int:
return self.image_ids.shape[0]<concatenate>
train_data['location'].value_counts(dropna = False )
def get_valid_transforms() :
return A.Compose([
ToTensorV2(p=1.0),
], p=1.0 )<define_variables>
def clean_text(text):
return text
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 )<load_pretrained>
all_data = pd.concat([
train_data.drop(TARGET_NAME, axis = 1),
test_data
] ).reset_index(drop = True)
 all_data['location'] = all_data['location'].astype(str)
 all_data.loc[all_data['location'].value_counts() [all_data['location']].values < 5, 'location'] = "RARE_VALUE"
all_data.loc[all_data['location'] == 'nan', 'location'] = np.nan
all_data['text'] = all_data['text'].map(clean_text)
 all_data
dataset = DatasetRetriever(np.array([path.split('/')[-1][:-4] for path in glob.glob(f'{DATA_ROOT_PATH}/*.jpg')]),get_valid_transforms())
 def collate_fn(batch):
return tuple(zip(*batch))
data_loader = DataLoader(
 dataset,
batch_size=1,
shuffle=False,
num_workers=2,
drop_last=False,
collate_fn=collate_fn
)<categorify>
y_train = train_data.target.values
train_data = all_data[:len(train_data)]
train_data[TARGET_NAME] = y_train
test_data = all_data[len(train_data):]
class BaseWheatTTA:

 image_size = 1024
def augment(self, image):
raise NotImplementedError
def batch_augment(self, images):
raise NotImplementedError
def deaugment_boxes(self, boxes):
raise NotImplementedError
class TTAHorizontalFlip(BaseWheatTTA):

 def augment(self, image):
return image.flip(1)
 def batch_augment(self, images):
return images.flip(2)
 def deaugment_boxes(self, boxes):
boxes[:, [1,3]] = self.image_size - boxes[:, [3,1]]
return boxes
class TTAVerticalFlip(BaseWheatTTA):

 def augment(self, image):
return image.flip(2)
 def batch_augment(self, images):
return images.flip(3)
 def deaugment_boxes(self, boxes):
boxes[:, [0,2]] = self.image_size - boxes[:, [2,0]]
return boxes
class TTARotate90(BaseWheatTTA):

 def augment(self, image):
return torch.rot90(image, 1,(1, 2))
def batch_augment(self, images):
return torch.rot90(images, 1,(2, 3))
def deaugment_boxes(self, boxes):
res_boxes = boxes.copy()
res_boxes[:, [0,2]] = self.image_size - boxes[:, [1,3]]
res_boxes[:, [1,3]] = boxes[:, [2,0]]
return res_boxes
class TTARotate180(BaseWheatTTA):

 def augment(self, image):
return torch.rot90(image, 2,(1, 2))
def batch_augment(self, images):
return torch.rot90(images, 2,(2, 3))
def deaugment_boxes(self, boxes):
boxes[:, [0,1,2,3]] = self.image_size - boxes[:, [2,3,0,1]]
return boxes
class TTARotate270(BaseWheatTTA):

 def augment(self, image):
return torch.rot90(image, 3,(1, 2))
def batch_augment(self, images):
return torch.rot90(images, 3,(2, 3))
def deaugment_boxes(self, boxes):
res_boxes = boxes.copy()
res_boxes[:, [0,2]] = boxes[:, [1,3]]
res_boxes[:, [1,3]] = self.image_size - boxes[:, [2,0]]
return res_boxes
class TTACompose(BaseWheatTTA):

 def __init__(self, transforms):
self.transforms = transforms
def augment(self, image):
for transform in self.transforms:
image = transform.augment(image)
 return image
def batch_augment(self, images):
for transform in self.transforms:
images = transform.batch_augment(images)
 return images
def prepare_boxes(self, boxes):
result_boxes = boxes.copy()
result_boxes[:,0] = np.min(boxes[:, [0,2]], axis=1)
 result_boxes[:,2] = np.max(boxes[:, [0,2]], axis=1)
 result_boxes[:,1] = np.min(boxes[:, [1,3]], axis=1)
 result_boxes[:,3] = np.max(boxes[:, [1,3]], axis=1)
 return result_boxes
def deaugment_boxes(self, boxes):
for transform in self.transforms[::-1]:
boxes = transform.deaugment_boxes(boxes)
 return self.prepare_boxes(boxes )<predict_on_test>
%%time
roles = {'target': TARGET_NAME,
'text': ['text'],
'drop': ['id']}
def make_tta_predictions(model,images, score_threshold=0.35):
model.eval()
model.to(device)
 with torch.no_grad() :
images = torch.stack(images ).float().cuda()
predictions = []
for tta_transform in tta_transforms:
result = []
det = model(tta_transform.batch_augment(images.clone()))
for i in range(images.shape[0]):
boxes = det[i]['boxes'].detach().cpu().numpy() [:,:4]
scores = det[i]['scores'].detach().cpu().numpy() [:]
indexes = np.where(scores > score_threshold)[0]
boxes = boxes[indexes]
boxes = tta_transform.deaugment_boxes(boxes.copy())
 result.append({
'boxes': boxes,
'scores': scores[indexes],
})
 predictions.append(result)
 return predictions
def make_ensemble_predictions(images):
images = list(image.to(device)for image in images)
 result = []
for model in models:
predictions = make_tta_predictions(model, images)
 with torch.no_grad() :
for i in range(len(images)) :
boxes, scores, labels = run_wbf(predictions, image_index=i)
 outputs = {'boxes': boxes,'labels': labels, 'scores':scores }
result.append([outputs])
 torch.cuda.empty_cache()
return result
def run_wbf(predictions, image_index, image_size=1024, iou_thr=0.45, skip_box_thr=0.35,score_threshold = 0.35, weights=None,conf_type='max'):
boxes = [prediction[image_index]['boxes']/(image_size)for prediction in predictions]
scores = [prediction[image_index]['scores'] for prediction in predictions]
labels = [np.ones(prediction[image_index]['scores'].shape[0])for prediction in predictions]
boxes, scores, labels = weighted_boxes_fusion(boxes, scores, labels, weights=weights, iou_thr=iou_thr, skip_box_thr=skip_box_thr, conf_type=conf_type)
 indexes = np.where(scores > score_threshold)[0]
boxes = boxes[indexes]
scores = scores[indexes]
boxes = boxes*(image_size-1)
 return boxes, scores, labels<concatenate>
%%time
automl = TabularNLPAutoML(task = task,
timeout = TIMEOUT,
cpu_limit = N_THREADS,
reader_params = {'cv': 5},
general_params = {'nested_cv': False, 'use_algos': [['linear_l2', 'lgb', 'nn']]},
text_params = {'lang': 'en'},
nn_params = {'lang': 'en',
'bert_name': 'vinai/bertweet-base',
'opt_params': { 'lr': 1e-5},
'max_length': 300, 'bs': 13,
'n_epoch': 5
}, 
)
 oof_pred = automl.fit_predict(train_data, roles = roles)
 print('oof_pred:
{}
Shape = {}'.format(oof_pred, oof_pred.shape))
tta_transforms = []
for tta_combination in product([TTAHorizontalFlip() , None],
[TTAVerticalFlip() , None],
[TTARotate90() , TTARotate180() , TTARotate270() , None]):
tta_transforms.append(TTACompose([tta_transform for tta_transform in tta_combination if tta_transform])) 
<define_variables>
automl.collect_used_feats()
validation_image_precisions = []
iou_thresholds = [x for x in np.arange(0.5, 0.76, 0.05)]
results = []
ts = 0.147
for images, image_ids in data_loader:
predictions = make_ensemble_predictions(images)
 for i, image in enumerate(images):
boxes, scores, labels = run_wbf(predictions, image_index=i, iou_thr=0.35, skip_box_thr=0.35, score_threshold = 0.35, weights=None,conf_type='avg')
 boxes = boxes.round().astype(np.int32 ).clip(min=0, max=1023)
 image_id = image_ids[i]
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)
<save_to_csv>
test_pred = automl.predict(test_data)
 print('Prediction for test data:
{}
Shape = {}'.format(test_pred, test_pred.shape))
test_df = pd.DataFrame(results, columns=['image_id', 'PredictionString'])
 test_df.to_csv('submission.csv', index=False)
 test_df.head(10 )<install_modules>
def select_threshold_f1(y_true, y_pred):
best_score = -1
best_thr = None
for thr in np.arange(0, 1.01, 0.01):
score = f1_score(y_true,(y_pred > thr ).astype(int))
if score > best_score:
best_score = score
best_thr = thr
print('Best score: {}
Best selected threshold: {:.2f}'.format(best_score, best_thr))
return best_thr
best_thr = select_threshold_f1(train_data[TARGET_NAME], oof_pred.data[:, 0] )
!pip install --no-deps '.. /input/timm-package/timm-0.1.26-py3-none-any.whl' > /dev/null
!pip install --no-deps '.. /input/pycocotools/pycocotools-2.0-cp37-cp37m-linux_x86_64.whl' > /dev/null<set_options>
submission['target'] =(test_pred.data[:, 0] > best_thr ).astype(int)
 submission
SEED = 42
def seed_everything(seed):
random.seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 np.random.seed(seed)
 torch.manual_seed(seed)
 torch.cuda.manual_seed(seed)
 torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = True
seed_everything(SEED )<load_from_csv>
submission['target'].value_counts()
marking = pd.read_csv('.. /input/global-wheat-detection/train.csv')
 bboxs = np.stack(marking['bbox'].apply(lambda x: np.fromstring(x[1:-1], sep=',')))
 for i, column in enumerate(['x', 'y', 'w', 'h']):
marking[column] = bboxs[:,i]
marking.drop(columns=['bbox'], inplace=True)
 marking.sample(10 )<feature_engineering>
submission.to_csv('LightAutoML_preds_without_id.csv', index = False )