Browse Source

add a fucntion to cover a folder to a image classes dataset.

tags/v0.110.4-Transformer-Model
dogvane 2 years ago
parent
commit
7165304ff8
2 changed files with 26 additions and 0 deletions
  1. +1
    -0
      src/TensorFlowNET.Keras/Preprocessings/Preprocessing.image_dataset_from_directory.cs
  2. +25
    -0
      src/TensorFlowNET.Keras/Preprocessings/Preprocessing.paths_and_labels_to_dataset.cs

+ 1
- 0
src/TensorFlowNET.Keras/Preprocessings/Preprocessing.image_dataset_from_directory.cs View File

@@ -58,6 +58,7 @@ namespace Tensorflow.Keras
if (shuffle)
dataset = dataset.shuffle(batch_size * 8, seed: seed);
dataset = dataset.batch(batch_size);
dataset.class_names = class_name_list;
return dataset;
}



+ 25
- 0
src/TensorFlowNET.Keras/Preprocessings/Preprocessing.paths_and_labels_to_dataset.cs View File

@@ -6,6 +6,31 @@ namespace Tensorflow.Keras
{
public partial class Preprocessing
{

/// <summary>
/// 图片路径转为数据处理用的dataset
/// </summary>
/// <param name="image_paths"></param>
/// <param name="image_size"></param>
/// <param name="num_channels"></param>
/// <param name="interpolation">
/// 用于调整大小的插值方法。支持`bilinear`、`nearest`、`bicubic`、`area`、`lanczos3`、`lanczos5`、`gaussian`、`mitchellcubic`。
/// 默认为`'bilinear'`。
/// </param>
/// <returns></returns>
public IDatasetV2 paths_to_dataset(string[] image_paths,
Shape image_size,
int num_channels = 3,
int num_classes = 6,
string interpolation = "bilinear")
{
var path_ds = tf.data.Dataset.from_tensor_slices(image_paths);
var img_ds = path_ds.map(x => path_to_image(x, image_size, num_channels, interpolation));
var label_ds = dataset_utils.labels_to_dataset(new int[num_classes] , "", num_classes);

return img_ds;
}

public IDatasetV2 paths_and_labels_to_dataset(string[] image_paths,
Shape image_size,
int num_channels,


Loading…
Cancel
Save