CARVIEW |
Select Language
HTTP/2 301
date: Sat, 19 Jul 2025 12:37:06 GMT
content-type: text/html; charset=utf-8
content-length: 0
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
location: https://github.com/tiny-dnn/tiny-dnn/wiki/Data-Format
cache-control: no-cache
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
set-cookie: _gh_sess=Rm%2FvUaUaEnJwpaXsPTosLJBKgBX1%2BXJCLbpFeX7KmuUXu2tHvsvhQNii%2FBCpD7BGyPZw0BJ9cRSvi1nBSkJLD%2FSw2WAn%2BVsPxa9%2FgHDwvRFWoD5%2F0TTuF5Pckwbre3MGKUQI%2BhFtbxZMWc9sQH6f7pRZrelWqLyi8oiB11OdMXsHVmeedZkHmyunQRXJKeBUMMw1iPbGymHY06Z1jD0BQe47f%2FUYnoIWRKLVfyQEKNqflf%2FD9qYDjmwZR6r6%2BpIrJD6YSFB01ftP1YMWCqayeA%3D%3D--BWTHUHWuJN9VJlXb--xqcJ%2BTnozrUcz%2F%2BYMXeIMQ%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.322998671.1752928625; Path=/; Domain=github.com; Expires=Sun, 19 Jul 2026 12:37:05 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Sun, 19 Jul 2026 12:37:05 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: A1B4:2E2A0B:400CAF:4EF7CD:687B9171
HTTP/2 200
date: Sat, 19 Jul 2025 12:37:06 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"376ddb96d1b3e5c58763abddb842d7b1"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
x-github-request-id: A1B4:2E2A0B:400CCA:4EF7FB:687B9171
Data Format · tiny-dnn/tiny-dnn Wiki · GitHub
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Data Format
nyanp edited this page May 31, 2015
·
14 revisions
Tiny-cnn has following interfaces to train networks.
template<typename LossFunction, typename Optimizer>
class network {
...
/**
* training conv-net
*
* @param in array of input data
* @param t array of training signals(label or vector)
* @param epoch number of training epochs
* @param on_batch_enumerate callback for each mini-batch enumerate
* @param on_epoch_enumerate callback for each epoch
*/
template <typename OnBatchEnumerate, typename OnEpochEnumerate, typename T>
void train(const std::vector<vec_t>& in,
const std::vector<T>& t,
size_t batch_size,
int epoch,
OnBatchEnumerate on_batch_enumerate,
OnEpochEnumerate on_epoch_enumerate);
/**
* training conv-net without callback
**/
template<typename T>
void train(const std::vector<vec_t>& in,
const std::vector<T>& t,
size_t batch_size = 1,
int epoch = 1);
...
};
"in" is array of input data, and "t" is array of training signal. Actual type of T depends on your task.
task | T |
---|---|
classification | label_t (typedef of size_t) |
regression | vec_t (typedef of std::vector<double>) |
using namespace tiny_cnn;
void classification() {
auto mlp = make_mlp<mse, adagrad, tan_h>({2, 10, 2});
std::vector<vec_t> data = { {0.1, 0.9}, {0.9, 0.1} };
std::vector<label_t> labels = { 1, 0 };
mlp.train(data, labels); // T == label_t
}
void regression() {
auto mlp = make_mlp<mse, adagrad, tan_h>({ 2, 10, 2 });
std::vector<vec_t> data = { { 0.1, 0.9 }, { 0.9, 0.1 } };
std::vector<vec_t> target = { { 0.3, 0.2 }, { 1.0, 0.0 } };
mlp.train(data, target); // T == vec_t
}
If you want to train network by your original data, You have to convert your data to vec_t, i.e. std::vector<double>. If your input is image data, pixels should be organized by row-wise.
Here are some examples.
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>
#include <boost/foreach.hpp>
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
// convert image to vec_t
void convert_image(const std::string& imagefilename,
double scale,
int w,
int h,
std::vector<vec_t>& data)
{
auto img = cv::imread(imagefilename, cv::IMREAD_GRAYSCALE);
if (img.data == nullptr) return; // cannot open, or it's not an image
cv::Mat_<uint8_t> resized;
cv::resize(img, resized, cv::Size(w, h));
vec_t d;
std::transform(resized.begin(), resized.end(), std::back_inserter(d),
[=](uint8_t c) { return c * scale; });
data.push_back(d);
}
// convert all images found in directory to vec_t
void convert_images(const std::string& directory,
double scale,
int w,
int h,
std::vector<vec_t>& data)
{
path dpath(directory);
BOOST_FOREACH(const path& p,
std::make_pair(directory_iterator(dpath), directory_iterator())) {
if (is_directory(p)) continue;
convert_image(p.string(), scale, w, h, data);
}
}
Another example can be found in issue#16, which can treat color channels.
2. using mnisten (image file => idx format)
mnisten is a library to convert image files to idx format.
mnisten -d my_image_files_directory_name -o my_prefix -s 32x32
After generating idx files, you can use parse_mnist_images / parse_mnist_labels utilities in mnist_parser.h
Caffe supports levelDB data format. Following code can convert levelDB created by Caffe into data/label arrays.
#include "leveldb/db.h"
void convert_leveldb(const std::string& dbname,
double scale,
std::vector<vec_t>& data,
std::vector<label_t>& label)
{
leveldb::DB *db;
leveldb::Options options;
options.create_if_missing = false;
auto status = leveldb::DB::Open(options, dbname, &db);
leveldb::Iterator* it = db->NewIterator(leveldb::ReadOptions());
for (it->SeekToFirst(); it->Valid(); it->Next()) {
const char* src = it->value().data();
size_t sz = it->value().size();
vec_t d;
std::transform(src, src + sz - 1, std::back_inserter(d),
[=](char c){ return c * scale; });
data.push_back(d);
label.push_back(src[sz - 1]);
}
delete it;
delete db;
}
© Copyright 2018, tiny-dnn team
Clone this wiki locally
You can’t perform that action at this time.