Skip to content

Commit 6eec0ac

Browse files
Coding #73.
1 parent 2d84a63 commit 6eec0ac

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

neural/neuraldatasets.pas

+31-11
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,13 @@ function TinyImageTo1D(var TI: TTinySingleChannelImage): TTinySingleChannelImage
226226

227227
// creates CIFAR10 volumes required for training, testing and validation
228228
procedure CreateCifar10Volumes(out ImgTrainingVolumes, ImgValidationVolumes,
229-
ImgTestVolumes: TNNetVolumeList; color_encoding: byte = csEncodeRGB);
229+
ImgTestVolumes: TNNetVolumeList; color_encoding: byte = csEncodeRGB;
230+
ValidationSampleSize: integer = 2000);
230231

231232
// creates CIFAR100 volumes required for training, testing and validation
232233
procedure CreateCifar100Volumes(out ImgTrainingVolumes, ImgValidationVolumes,
233234
ImgTestVolumes: TNNetVolumeList; color_encoding: byte = csEncodeRGB;
234-
Verbose:boolean = true);
235+
Verbose:boolean = true; ValidationSampleSize: integer = 2000);
235236

236237
// creates MNIST volumes required for training, testing and validation
237238
procedure CreateMNISTVolumes(out ImgTrainingVolumes, ImgValidationVolumes,
@@ -831,14 +832,17 @@ procedure TranslateCifar10VolumesToMachineAnimal(VolumeList: TNNetVolumeList);
831832
end;
832833

833834
procedure CreateCifar10Volumes(out ImgTrainingVolumes, ImgValidationVolumes,
834-
ImgTestVolumes: TNNetVolumeList; color_encoding: byte = csEncodeRGB);
835+
ImgTestVolumes: TNNetVolumeList; color_encoding: byte = csEncodeRGB;
836+
ValidationSampleSize: integer = 2000);
835837
var
836-
I: integer;
838+
I, LastElement: integer;
837839
begin
838840
ImgTrainingVolumes := TNNetVolumeList.Create();
839841
ImgValidationVolumes := TNNetVolumeList.Create();
840842
ImgTestVolumes := TNNetVolumeList.Create();
841843

844+
if ValidationSampleSize > 10000 then ValidationSampleSize := 10000;
845+
842846
// creates required volumes to store images
843847
for I := 0 to 39999 do
844848
begin
@@ -857,28 +861,44 @@ procedure CreateCifar10Volumes(out ImgTrainingVolumes, ImgValidationVolumes,
857861
loadCifar10Dataset(ImgTrainingVolumes, 4, 30000, color_encoding);
858862
loadCifar10Dataset(ImgValidationVolumes, 5, 0, color_encoding);
859863
loadCifar10Dataset(ImgTestVolumes, 'test_batch.bin', 0, color_encoding);
864+
865+
// Should move validation volumes to training volumes?
866+
if ValidationSampleSize < 10000 then
867+
begin
868+
ImgValidationVolumes.FreeObjects := False;
869+
LastElement := ImgValidationVolumes.Count - 1;
870+
for I := LastElement downto (LastElement-(10000-ValidationSampleSize)+1) do
871+
begin
872+
ImgTrainingVolumes.Add(ImgValidationVolumes[I]);
873+
ImgValidationVolumes.Delete(I);
874+
end;
875+
ImgValidationVolumes.FreeObjects := True;
876+
end;
860877
end;
861878

862879
procedure CreateCifar100Volumes(out ImgTrainingVolumes, ImgValidationVolumes,
863880
ImgTestVolumes: TNNetVolumeList; color_encoding: byte = csEncodeRGB;
864-
Verbose:boolean = true);
881+
Verbose:boolean = true; ValidationSampleSize: integer = 2000);
865882
var
866883
I, LastElement: integer;
867884
begin
868885
ImgTrainingVolumes := TNNetVolumeList.Create();
869-
ImgTrainingVolumes.FreeObjects := false;
870886
ImgValidationVolumes := TNNetVolumeList.Create();
871887
ImgTestVolumes := TNNetVolumeList.Create();
872888
loadCifar100Dataset(ImgTrainingVolumes, 'train.bin', color_encoding, Verbose);
873889
loadCifar100Dataset(ImgTestVolumes, 'test.bin', color_encoding, Verbose);
874-
875890
LastElement := ImgTrainingVolumes.Count - 1;
876-
for I := LastElement downto (LastElement-4999) do
891+
if ValidationSampleSize > 0 then
877892
begin
878-
ImgValidationVolumes.Add(ImgTrainingVolumes[I]);
879-
ImgTrainingVolumes.Delete(I);
893+
ImgTrainingVolumes.FreeObjects := false;
894+
if ValidationSampleSize > 25000 then ValidationSampleSize := 25000;
895+
for I := LastElement downto (LastElement-ValidationSampleSize+1) do
896+
begin
897+
ImgValidationVolumes.Add(ImgTrainingVolumes[I]);
898+
ImgTrainingVolumes.Delete(I);
899+
end;
900+
ImgTrainingVolumes.FreeObjects := true;
880901
end;
881-
ImgTrainingVolumes.FreeObjects := true;
882902
end;
883903

884904
procedure CreateMNISTVolumes(out ImgTrainingVolumes, ImgValidationVolumes,

0 commit comments

Comments
 (0)