this is a custom metric i wrote to check the data types and shapes of p: def…
- User
this is a custom metric i wrote to check the data types and shapes of p:
def compute_metrics(p) -> Dict[str, float]: preds = p.predictions # tuple labels = p.label_ids # np.ndarray; (batch_size, num_tokens)
codelabels_text = [processor.decode(lbl_token_ids, skip_special_tokens=True) for lbl_token_ids in labels] # lbl_token_ids examples: [ 101, 2748, 102] - 'yes'; [ 101, 2053, 102] - 'no' labels_binary = [1 if 'yes' in lbl_text else 0 for lbl_text in labels_text] print(len(preds)) # 2 print(type(preds[0])) # np.ndarray print(preds[0].shape) # (batch_size, 577, 768) print(type(preds[1])) # np.ndarray print(preds[1].shape) # (batch_size, 577, 768) return {'accuracy': 0.5}Why are there 2 things in preds and why do they have that shape?
- Assistant
From your description and the provided code, it looks like the
predsvariable contains the predictions from a model that outputs multiple components, specifically with a shape of(batch_size, 577, 768).Explanation of
- User
why after using the processor for BLIP: processor = BlipProcessor.from_pretrained('./blip-vqa-capfilt-large', do_image_splitting=False, do_rescale=False) the result has shape torch.Size([batch_size, 3, 384, 384])? Is that number the one the authors decided to rescale the images to?
- Assistant
The output shape of
torch.Size([batch_size, 3, 384, 384])after processing images with theBlipProcessoris consistent with standard practices in image processing for deep learning models, particularly in the context of models designed for tasks such as visualization or image processing. - User
assert a == b does not work with np.ndarrays. how shopuld i do it?
- Assistant
When comparing two NumPy arrays using
assert, the comparison will not work as expected because the comparison of NumPy arrays does not return a single boolean value. Instead, it returns an array of booleans, which indicates the element-wise comparison of the two arrays.Instead of using
assert a == b, you should use one of the following methods to assert equality between NumPy arrays:-
Using
np.array_equal: This function checks if two arrays have the same shape and elements.pythonimport numpy as np a = np.array([1, 2, 3]) b = np.array([1, 2, 3]) assert np.array_equal(a, b), "Arrays are not equal" -
Using
np.allclose: If you want to consider floating-point precision (for example, comparing the results of computations), you can use , which allows you to specify the tolerance level for comparisons.
-