Skip to content

Commit

Permalink
add a fucntion to cover a folder to a image classes dataset.
Browse files Browse the repository at this point in the history
  • Loading branch information
dogvane committed Jul 9, 2023
1 parent fa213eb commit 7165304
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public IDatasetV2 image_dataset_from_directory(string directory,
if (shuffle)
dataset = dataset.shuffle(batch_size * 8, seed: seed);
dataset = dataset.batch(batch_size);
dataset.class_names = class_name_list;
return dataset;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7165304

Please sign in to comment.