dotnet / dotnet/machinelearning

Image Clasisfication Trainer - Expected VarVector<Byte> got Vector<Byte>

Open
#5,936 5 comments 0 reactions 0 assignees View on GitHub
area-Vision
Dominant language
C#
Stars
9.4k
Forks
2k
Avg merge
2d 20h
Merged PRs (30d)
11

Description

Given an image classification pipeline with the following input schema throws an error `Expected VarVector got Vector`. To fix this, I've used a custom transform to map a `Vector` to `VarVector`. However, since my `Features` column is a `byte []` which is the expected input of the `ImageClassificationTrainer`, it's unclear why the error is thrown.

Input schema

```csharp
public class ModelInput
{
[ColumnName(@"Label")]
public string Label { get; set; }

[ColumnName(@"ImageSource"), ImageType(224,224)]
//public Image ImageSource { get; set; }
public Bitmap ImageSource { get; set; }
}
```

```csharp
var pipeline = mlContext.Transforms.Conversion.MapValueToKey(@"Label", @"Label")
.Append(mlContext.Transforms.ResizeImages("ImageSource_featurized", 224, 224, "ImageSource"))
.Append(mlContext.Transforms.ExtractPixels("ImageSource_featurized",outputAsFloatArray:false))
.Append(mlContext.Transforms.CustomMapping(new VectorMappingCustomAction().GetMapping(), contractName: "VectorMapping"))
.Append(mlContext.Transforms.CopyColumns(@"Features", @"ImageSource_featurized"))
.Append(mlContext.MulticlassClassification.Trainers.ImageClassification(labelColumnName:@"Label"))
.Append(mlContext.Transforms.Conversion.MapKeyToValue(@"PredictedLabel", @"PredictedLabel"));
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.