Skip to content

Instantly share code, notes, and snippets.

View codezakh's full-sized avatar

Zaid Khan codezakh

View GitHub Profile
@codezakh
codezakh / blip2_confidence_snippet.py
Created February 4, 2024 14:32
Get the answers+confidence from a BLIP-2 model for a VQA task.
outputs = blip2.generate(
pixel_values=pixel_values,
input_ids=input_ids,
attention_mask=attention_mask,
do_sample=False,
num_beams=5,
max_new_tokens=10,
min_length=1,
length_penalty=-1,
return_dict_in_generate=True,
class CustomBatchSampler(Sampler):
def __init__(self, batch_size, dataset):
self.sampler = SequentialSampler(dataset)
self.batch_size = batch_size
self.drop_last = False
self.dataset = dataset
def __iter__(self):
batch = []
for idx in self.sampler:
batch.append(idx)
@codezakh
codezakh / random_prediction.py
Last active November 23, 2019 04:39
Code to predict random labels on the validation pairs in Phase 1 of the RFIW 2020 Verification Track,
import pandas as pd
import numpy as np
val_pairs = pd.read_csv('val_pairs.csv').set_index('index')
# Randomly predict {0, 1} for each pair.
random_predictions = np.random.randint(0,2, size=len(val_pairs))
# Add the predictions as a column named "label".
val_pairs['label'] = pd.Series(random_predictions)
@codezakh
codezakh / microsoftOCRsample.json
Created August 17, 2017 21:03
An example response returned by the microsoft cognition api when using OCR.
{
"language": "en",
"textAngle": 0.0,
"orientation": "Up",
"regions": [
{
"boundingBox": "22,25,1389,1863",
"lines": [
{
"boundingBox": "22,25,1389,49",