Dear @John6666
I tried this but not working with this error
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-38-9b0dbdbf42dd> in <cell line: 0>()
17 )
18
---> 19 trainer_after_train.evaluate()
20
21
8 frames
/usr/local/lib/python3.11/dist-packages/transformers/data/data_collator.py in torch_default_data_collator(features)
139 label = first["label"].item() if isinstance(first["label"], torch.Tensor) else first["label"]
140 dtype = torch.long if isinstance(label, int) else torch.float
--> 141 batch["labels"] = torch.tensor([f["label"] for f in features], dtype=dtype)
142 elif "label_ids" in first and first["label_ids"] is not None:
143 if isinstance(first["label_ids"], torch.Tensor):
TypeError: must be real number, not PngImageFile
Already trained with the same shape dataset that I have divided for training, validation, and test. Now I need to test the trained model with the test_dataset.
Separation codes:
John6666 previous code
dataset_repo = "seand0101/segformer-b0-finetuned-ade-512-512-manggarai-watergate"
ds = load_dataset(dataset_repo, split="train")
newdsl = []
for i in range(ds.num_rows):
newdsl.append({"pixel_values": ds[i]["pixel_values"], "label": im.fromarray(np.array(ds[i]["label"].convert("L")) / 255).convert("L")})
newds = Dataset.from_list(newdsl) # normalized dataset
Dividing the dataset
# 70% train, 30% test + validation
train_testvalid = newds.train_test_split(test_size=0.3)
train_testvalid
Dividing it for validation
# 70% train, 30% test + validation
train_testvalid = newds.train_test_split(test_size=0.3)
train_testvalid
Now for the test
# Split the 10% test + valid in half test, half valid
test_valid = train_testvalid['test'].train_test_split(test_size=0.3)
test_valid
Result
# gather everyone if you want to have a single DatasetDict
train_test_valid_dataset = DatasetDict({
'train': train_testvalid['train'],
'test': test_valid['test'],
'valid': test_valid['train']})
Output from result
Codes to validate with the test part of the dataset that came from here and produce such error
hub_model_id_after_train= "seand0101/segformer-b0-finetuned-ade20k-manggarai_rivergate_6"
model_after_train = SegformerForSemanticSegmentation.from_pretrained(
hub_model_id_after_train,
num_labels=num_labels,
id2label=id2label,
label2id=label2id,
ignore_mismatched_sizes=True, # Will ensure the segmentation specific components are reinitialized.
)
trainer_after_train = Trainer(
model=model_after_train,
args=training_args,
train_dataset=train_ds,
eval_dataset=np.array(test_ds),
compute_metrics=compute_metrics,
)
trainer_after_train.evaluate()
Did I evaluate it wrongly?
Btw if its not clear, I wanna test the model with part of the dataset so it outputs its own loss plot and accuracy or miou to the test model if that makes anything? or maybe just loss?, is this done correctly?