Skip to content

Commit

Permalink
add fashion
Browse files Browse the repository at this point in the history
  • Loading branch information
springkim committed Aug 2, 2018
1 parent 333bd8b commit 0c1f81e
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 24 deletions.
Binary file modified OpenIMDS_TEST/.vs/OpenIMDS_TEST/v14/.suo
Binary file not shown.
30 changes: 22 additions & 8 deletions OpenIMDS_TEST/test.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
#include"../classification/mnist.h"
#include"../classification/cifar10.h"
#include<opencv2/opencv.hpp>

int main(){
IMDSImage train=GetMnistTrainData();

void CifarTest() {
IMDSImage train = GetCifar10TrainData();
IMDSImage mini_batch = GetRandomMiniBatch(train, 64);

for(int i=0;i<mini_batch.n;i++){
cv::Mat img(mini_batch.h, mini_batch.w,CV_32FC1, mini_batch.image[i]);
cv::imshow("image",img);
for (int i = 0; i<mini_batch.n; i++) {
cv::Mat img(mini_batch.h, mini_batch.w, CV_32FC3, mini_batch.image[i]);
img.convertTo(img, CV_8UC3);
cv::resize(img, img, cv::Size(500, 500));
cv::imshow("image", img);
cv::waitKey();
}
}
void FashionTest() {
IMDSImage train = GetFashionTrainData();
IMDSImage mini_batch = GetRandomMiniBatch(train, 64);
for (int i = 0; i<mini_batch.n; i++) {
cv::Mat img(mini_batch.h, mini_batch.w, CV_32FC1, mini_batch.image[i]);
img.convertTo(img, CV_8UC1);
cv::resize(img, img, cv::Size(500, 500));
cv::imshow("image", img);
cv::waitKey();
}
}
int main(){
FashionTest();
return 0;
}
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ OpenIMDS

This simple header only C library can read popular classification datasets.

1. Classification datasets --------------------------
## 1. Classification datasets

We are using `IMDSImage` type for each datasets. It has width,height,the number of images,images and labels only.

#### MNIST
### MNIST(mnist.h)

<img src="https://i.imgur.com/9BcVOYQ.png" width="128">
<img src="https://i.imgur.com/9BcVOYQ.png" width="256">

The MNIST database of handwritten digits, available from this page, has a training set of 60,000 examples, and a test set of 10,000 examples. It is a subset of a larger set available from NIST. The digits have been size-normalized and centered in a fixed-size image.

Expand Down Expand Up @@ -40,10 +40,23 @@ IMDSImage GetMnistValidData(int padding=0,float alpha=1.0F,bool bias=true);`
IMDSImage train= GetMnistTrainData(0, 1 / 255.0F,true);
IMDSImage valid= GetMnistValidData(0, 1 / 255.0F,true);
```
### Fashion(mnist.h)

#### Cifar-10
<img src="https://i.imgur.com/MtTIit7.png" width="256">

<img src="https://i.imgur.com/X7Tv9dQ.png" width="128">
**[Fashion-MNIST](https://github.com/zalandoresearch/fashion-mnist)** is a dataset of Zalando's article images—consisting of a training set of 60,000 examples and a test set of 10,000 examples. Each example is a 28x28 grayscale image, associated with a label from 10 classes. We intend Fashion-MNIST to serve as a direct drop-in replacement for the original MNIST dataset for benchmarking machine learning algorithms. It shares the same image size and structure of training and testing splits.

```c
IMDSImage GetFashionTrainData(int padding=0,float alpha=1.0F,bool bias=true)
```
```c
IMDSImage GetFashionValidData(int padding=0,float alpha=1.0F,bool bias=true)
```

### Cifar-10(cifar10.h)

<img src="https://i.imgur.com/X7Tv9dQ.png" width="256">

The CIFAR-10 dataset consists of 60000 32x32 colour images in 10 classes, with 6000 images per class. There are 50000 training images and 10000 test images.

Expand Down
14 changes: 7 additions & 7 deletions classification/cifar10.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static inline IMDSImage __ReadCIFAR10(char* image_file, int padding, float alpha
imgs.n = 10000;
imgs.label = (int*)calloc(imgs.n, sizeof(int));
imgs.image = (float**)calloc(imgs.n, sizeof(float*));
char row[3073];
unsigned char row[3073];
for (int i = 0; i < 10000; i++) {
fread(row, 1, 3073, fp);
imgs.label[i] = (int)row[0];
Expand Down Expand Up @@ -156,11 +156,11 @@ static inline IMDSImage GetCifar10TrainData(int padding _IMDSCPPDV(0), float alp
char name_img[MAX_PATH + 1] = { 0 };
IMDSImage train;
char* url[5] = {
"https://www.dropbox.com/s/1u0hpkbbddn3hc1/openimds_cifar10_train_1.bin?dl=1"
,"https://www.dropbox.com/s/mxk1zozw42cqk2a/openimds_cifar10_train_2.bin?dl=1"
,"https://www.dropbox.com/s/cxg81q891j78wa9/openimds_cifar10_train_3.bin?dl=1"
,"https://www.dropbox.com/s/tcnds6l7rba5tn7/openimds_cifar10_train_4.bin?dl=1"
,"https://www.dropbox.com/s/u9500s411uocjgg/openimds_cifar10_train_5.bin?dl=1"
"https://github.com/springkim/OpenIMDS/releases/download/Cifar10/openimds_cifar10_train_1.bin"
,"https://github.com/springkim/OpenIMDS/releases/download/Cifar10/openimds_cifar10_train_2.bin"
,"https://github.com/springkim/OpenIMDS/releases/download/Cifar10/openimds_cifar10_train_3.bin"
,"https://github.com/springkim/OpenIMDS/releases/download/Cifar10/openimds_cifar10_train_4.bin"
,"https://github.com/springkim/OpenIMDS/releases/download/Cifar10/openimds_cifar10_train_5.bin"
};
train.c = 3;
train.w = 32 + padding * 2;
Expand All @@ -184,7 +184,7 @@ static inline IMDSImage GetCifar10TrainData(int padding _IMDSCPPDV(0), float alp
static inline IMDSImage GetCifar10ValidData(int padding _IMDSCPPDV(0), float alpha _IMDSCPPDV(1.0F), bool bias _IMDSCPPDV(true)) {
char tmp_path[MAX_PATH + 1] = { 0 };
char* name_img = "openimds_cifar10_test.bin";
char* url = "https://www.dropbox.com/s/uifxmb6hi0rmvr3/openimds_cifar10_test.bin?dl=1";
char* url = "https://github.com/springkim/OpenIMDS/releases/download/Cifar10/openimds_cifar10_test.bin";
__DownloadCifar10(tmp_path, url,name_img,30730000);
char path_img[MAX_PATH + 1] = { 0 };
strcat(strcpy(path_img, tmp_path), name_img);
Expand Down
34 changes: 30 additions & 4 deletions classification/mnist.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ static inline IMDSImage GetMnistTrainData(int padding _IMDSCPPDV(0), float alpha
char tmp_path[MAX_PATH + 1] = { 0 };
char* name_img = "openimds_mnist_train_image.bin";
char* name_lbl = "openimds_mnist_train_label.bin";
__DownloadMNIST(tmp_path, "https://www.dropbox.com/s/f56cag59pk58lel/openimds_mnist_train_image.bin?dl=1"
, "https://www.dropbox.com/s/r1rgfhshebdhnms/openimds_mnist_train_label.bin?dl=1"
__DownloadMNIST(tmp_path, "https://github.com/springkim/OpenIMDS/releases/download/MNIST/openimds_mnist_train_image.bin"
, "https://github.com/springkim/OpenIMDS/releases/download/MNIST/openimds_mnist_train_label.bin"
, name_img, name_lbl, 47040016,60008);
char path_img[MAX_PATH + 1] = { 0 };
char path_lbl[MAX_PATH + 1] = { 0 };
Expand All @@ -230,13 +230,39 @@ static inline IMDSImage GetMnistValidData(int padding _IMDSCPPDV(0), float alpha
char tmp_path[MAX_PATH + 1] = { 0 };
char* name_img = "openimds_mnist_valid_image.bin";
char* name_lbl = "openimds_mnist_valid_label.bin";
__DownloadMNIST(tmp_path, "https://www.dropbox.com/s/zsf4wicmmru34s9/openimds_mnist_valid_image.bin?dl=1"
, "https://www.dropbox.com/s/wsj7xetwmwuhxj8/openimds_mnist_valid_label.bin?dl=1"
__DownloadMNIST(tmp_path, "https://github.com/springkim/OpenIMDS/releases/download/MNIST/openimds_mnist_valid_image.bin"
, "https://github.com/springkim/OpenIMDS/releases/download/MNIST/openimds_mnist_valid_label.bin"
, name_img, name_lbl,7840016,10008);
char path_img[MAX_PATH + 1] = { 0 };
char path_lbl[MAX_PATH + 1] = { 0 };
strcat(strcpy(path_img, tmp_path), name_img);
strcat(strcpy(path_lbl, tmp_path), name_lbl);
return __ReadMNIST(path_img, path_lbl, padding, alpha,bias);
}
static inline IMDSImage GetFashionTrainData(int padding _IMDSCPPDV(0), float alpha _IMDSCPPDV(1.0F), bool bias _IMDSCPPDV(true)) {
char tmp_path[MAX_PATH + 1] = { 0 };
char* name_img = "openimds_fashion_train_image.bin";
char* name_lbl = "openimds_fashion_train_label.bin";
__DownloadMNIST(tmp_path, "https://github.com/springkim/OpenIMDS/releases/download/fashion/train-images-idx3-ubyte"
, "https://github.com/springkim/OpenIMDS/releases/download/fashion/train-labels-idx1-ubyte"
, name_img, name_lbl, 47040016, 60008);
char path_img[MAX_PATH + 1] = { 0 };
char path_lbl[MAX_PATH + 1] = { 0 };
strcat(strcpy(path_img, tmp_path), name_img);
strcat(strcpy(path_lbl, tmp_path), name_lbl);
return __ReadMNIST(path_img, path_lbl, padding, alpha, bias);
}
static inline IMDSImage GetFashionValidData(int padding _IMDSCPPDV(0), float alpha _IMDSCPPDV(1.0F), bool bias _IMDSCPPDV(true)) {
char tmp_path[MAX_PATH + 1] = { 0 };
char* name_img = "openimds_fashion_valid_image.bin";
char* name_lbl = "openimds_fashion_valid_label.bin";
__DownloadMNIST(tmp_path, "https://github.com/springkim/OpenIMDS/releases/download/fashion/t10k-images-idx3-ubyte"
, "https://github.com/springkim/OpenIMDS/releases/download/fashion/t10k-labels-idx1-ubyte"
, name_img, name_lbl, 7840016, 10008);
char path_img[MAX_PATH + 1] = { 0 };
char path_lbl[MAX_PATH + 1] = { 0 };
strcat(strcpy(path_img, tmp_path), name_img);
strcat(strcpy(path_lbl, tmp_path), name_lbl);
return __ReadMNIST(path_img, path_lbl, padding, alpha, bias);
}
#endif //MNIST_7E2_1_1C_MNIST_HPP_INCLUDED

0 comments on commit 0c1f81e

Please sign in to comment.