@epfml/discojs 2.1.2-p20240624145915.0 → 2.1.2-p20240627125649.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/default_tasks/cifar10.js +7 -5
- package/dist/default_tasks/index.d.ts +0 -1
- package/dist/default_tasks/index.js +0 -1
- package/dist/default_tasks/lus_covid.js +8 -7
- package/dist/default_tasks/mnist.js +11 -9
- package/dist/default_tasks/simple_face.js +4 -2
- package/dist/default_tasks/titanic.js +11 -9
- package/dist/default_tasks/wikitext.js +11 -9
- package/dist/task/display_information.d.ts +1 -0
- package/dist/task/display_information.js +4 -2
- package/package.json +1 -1
- package/dist/default_tasks/skin_condition.d.ts +0 -2
- package/dist/default_tasks/skin_condition.js +0 -80
|
@@ -8,13 +8,15 @@ export const cifar10 = {
|
|
|
8
8
|
displayInformation: {
|
|
9
9
|
taskTitle: 'CIFAR10',
|
|
10
10
|
summary: {
|
|
11
|
-
preview: '
|
|
12
|
-
overview:
|
|
11
|
+
preview: 'CIFAR-10 is a classic image classification task, and one of the most widely used datasets for machine learning research.',
|
|
12
|
+
overview: "The dataset contains 60,000 32x32 color images in 10 different classes: airplanes, cars, birds, cats, deer, dogs, frogs, horses, ships, and trucks. The official CIFAR-10 website can be found <a class='underline text-blue-400' href='https://www.cs.toronto.edu/~kriz/cifar.html' target='_blank'>here</a>. You can find a link to a sample dataset at the next step (Connect Your Data)."
|
|
13
13
|
},
|
|
14
|
-
|
|
14
|
+
model: 'The model is a pretrained <a class="underline text-blue-400" target="_blank" href="https://github.com/tensorflow/tfjs-models/tree/master/mobilenet">MobileNetV1 model</a> trained in Tensorflow.js. The last output layer is replaced with a fully connected layer with softmax activation and one output neuron per CIFAR10 category. The data preprocessing reshapes images into 224x224 pixels and normalizes values between 0 and 1. The neural network is optimized via Stochastic Gradient Descent and a categorical Cross Entropy loss.',
|
|
15
|
+
dataFormatInformation: 'Images should be of .png format and of size 32x32. <br> The CSV file should start with the exact header "filename,label", and each row should contain an image filename (without extension) and its label.<br><br> For example if you have images: 0.png (of a frog) and 1.png (of a car) <br> The CSV file should be: <br>filename, label <br><br> 0, frog <br> 1, car',
|
|
15
16
|
dataExampleText: 'Below you can find 10 random examples from each of the 10 classes in the dataset.',
|
|
16
17
|
dataExampleImage: 'https://storage.googleapis.com/deai-313515.appspot.com/example_training_data/cifar10-example.png',
|
|
17
|
-
sampleDatasetLink: 'https://
|
|
18
|
+
sampleDatasetLink: 'https://storage.googleapis.com/deai-313515.appspot.com/example_training_data.tar.gz',
|
|
19
|
+
sampleDatasetInstructions: 'Opening the link should start downloading a zip file which you can unzip. To connect the data, use the CSV option below and select the file named "cifar10-labels.csv". You can now connect the images located in the "CIFAR10" folder. Note that there are only 24 images in this sample dataset which is far too few to successfully train a machine learning model.'
|
|
18
20
|
},
|
|
19
21
|
trainingInformation: {
|
|
20
22
|
modelID: 'cifar10-model',
|
|
@@ -23,7 +25,7 @@ export const cifar10 = {
|
|
|
23
25
|
validationSplit: 0.2,
|
|
24
26
|
batchSize: 10,
|
|
25
27
|
dataType: 'image',
|
|
26
|
-
preprocessingFunctions: [data.ImagePreprocessing.Resize],
|
|
28
|
+
preprocessingFunctions: [data.ImagePreprocessing.Resize, data.ImagePreprocessing.Normalize],
|
|
27
29
|
IMAGE_H: 224,
|
|
28
30
|
IMAGE_W: 224,
|
|
29
31
|
LABEL_LIST: ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck'],
|
|
@@ -5,16 +5,17 @@ export const lusCovid = {
|
|
|
5
5
|
return {
|
|
6
6
|
id: 'lus_covid',
|
|
7
7
|
displayInformation: {
|
|
8
|
-
taskTitle: 'COVID Lung
|
|
8
|
+
taskTitle: 'COVID-19 Diagnosis from Lung Ultrasounds',
|
|
9
9
|
summary: {
|
|
10
|
-
preview:
|
|
11
|
-
overview: "Don't have a dataset of your own?
|
|
10
|
+
preview: "Medical images are a typical example of data that exists in huge quantity yet that can't be shared due to confidentiality reasons. Medical applications would immensely benefit from training on data currently locked. More data diversity leads to better generalization and bias mitigation.",
|
|
11
|
+
overview: "Disco allows data owners to collaboratively train machine learning models using their respective data without any privacy breach. This example problem is about diagnosing whether patients are positive or negative to COVID-19 from lung ultrasounds images. <br>Don't have a dataset of your own? You can find a link to a sample dataset at the next step."
|
|
12
12
|
},
|
|
13
|
-
model: "
|
|
14
|
-
dataFormatInformation: 'This model takes as input an image dataset
|
|
15
|
-
dataExampleText: 'Below you can find an example of an expected lung image
|
|
13
|
+
model: "The model is a simple Convolutional Neural Network composed of two convolutional layers with ReLU activations and max pooling layers, followed by a fully connected output layer. The data preprocessing reshapes images into 100x100 pixels and normalizes values between 0 and 1",
|
|
14
|
+
dataFormatInformation: 'This model takes as input an image dataset of lung ultrasounds. The images are resized automatically.',
|
|
15
|
+
dataExampleText: 'Below you can find an example of an expected lung image.',
|
|
16
16
|
dataExampleImage: 'https://storage.googleapis.com/deai-313515.appspot.com/example_training_data/2_QAID_1.masked.reshaped.squared.224.png',
|
|
17
|
-
sampleDatasetLink: 'https://drive.switch.ch/index.php/s/zM5ZrUWK3taaIly'
|
|
17
|
+
sampleDatasetLink: 'https://drive.switch.ch/index.php/s/zM5ZrUWK3taaIly',
|
|
18
|
+
sampleDatasetInstructions: 'Opening the link will take you to a Switch Drive folder. You can click on the Download button in the top right corner. Unzip the file and you will get two subfolders: "COVID-" and "COVID+". You can connect the data by using the Group option and selecting each image group in its respective field.'
|
|
18
19
|
},
|
|
19
20
|
trainingInformation: {
|
|
20
21
|
modelID: 'lus-covid-model',
|
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
import * as tf from '@tensorflow/tfjs';
|
|
2
|
-
import { models } from '../index.js';
|
|
2
|
+
import { data, models } from '../index.js';
|
|
3
3
|
export const mnist = {
|
|
4
4
|
getTask() {
|
|
5
5
|
return {
|
|
6
6
|
id: 'mnist',
|
|
7
7
|
displayInformation: {
|
|
8
|
-
taskTitle: '
|
|
8
|
+
taskTitle: 'Handwritten Digit Recognition',
|
|
9
9
|
summary: {
|
|
10
|
-
preview: "
|
|
11
|
-
overview:
|
|
10
|
+
preview: "The MNIST handwritten digit classification problem is a classic dataset used in computer vision and deep learning. The objective is to classify handwritten digits from 28x28 pixel images.",
|
|
11
|
+
overview: "Download the classic MNIST dataset of hand-written numbers <a class='underline text-blue-400' target='_blank' href='https://www.kaggle.com/scolianni/mnistasjpg'>here</a>. You can also find a sample dataset at the next step."
|
|
12
12
|
},
|
|
13
|
-
model:
|
|
14
|
-
dataFormatInformation: 'This model is trained on images corresponding to digits 0 to 9. You can
|
|
13
|
+
model: "The model is a simple Convolutional Neural Network composed of three convolutional layers with ReLU activations and max pooling layers, followed by two fully connected layers. The data preprocessing simply normalizes values between 0 and 1. The neural network is optimized via RMSProp and a categorical cross-entropy loss.",
|
|
14
|
+
dataFormatInformation: 'This model is trained on images corresponding to digits 0 to 9. You can connect your own images of each digit in the box corresponding to its label. The model takes images of size 28x28 as input.',
|
|
15
15
|
dataExampleText: 'Below you can find an example of an expected image representing the digit 9.',
|
|
16
|
-
dataExampleImage: 'http://storage.googleapis.com/deai-313515.appspot.com/example_training_data/9-mnist-example.png'
|
|
16
|
+
dataExampleImage: 'http://storage.googleapis.com/deai-313515.appspot.com/example_training_data/9-mnist-example.png',
|
|
17
|
+
sampleDatasetLink: 'https://storage.googleapis.com/deai-313515.appspot.com/MNIST_samples.tar.gz',
|
|
18
|
+
sampleDatasetInstructions: 'Opening the link should start downloading a zip file which you can unzip. You can connect the data with the CSV option below using the CSV file named "mnist_labels.csv". After selecting in the CSV file, you will be able to connect the data under in the "images" folder.'
|
|
17
19
|
},
|
|
18
20
|
trainingInformation: {
|
|
19
21
|
modelID: 'mnist-model',
|
|
20
|
-
epochs:
|
|
22
|
+
epochs: 20,
|
|
21
23
|
roundDuration: 10,
|
|
22
24
|
validationSplit: 0.2,
|
|
23
25
|
batchSize: 30,
|
|
24
26
|
dataType: 'image',
|
|
25
27
|
IMAGE_H: 28,
|
|
26
28
|
IMAGE_W: 28,
|
|
27
|
-
preprocessingFunctions: [],
|
|
29
|
+
preprocessingFunctions: [data.ImagePreprocessing.Normalize],
|
|
28
30
|
LABEL_LIST: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
|
|
29
31
|
scheme: 'decentralized',
|
|
30
32
|
noiseScale: undefined,
|
|
@@ -9,11 +9,13 @@ export const simpleFace = {
|
|
|
9
9
|
taskTitle: 'Simple Face',
|
|
10
10
|
summary: {
|
|
11
11
|
preview: 'Can you detect if the person in a picture is a child or an adult?',
|
|
12
|
-
overview: 'Simple face is a small subset of face_task from Kaggle'
|
|
12
|
+
overview: 'Simple face is a small subset of the public face_task dataset from Kaggle'
|
|
13
13
|
},
|
|
14
14
|
dataFormatInformation: '',
|
|
15
15
|
dataExampleText: 'Below you can find an example',
|
|
16
|
-
dataExampleImage: 'https://storage.googleapis.com/deai-313515.appspot.com/example_training_data/simple_face-example.png'
|
|
16
|
+
dataExampleImage: 'https://storage.googleapis.com/deai-313515.appspot.com/example_training_data/simple_face-example.png',
|
|
17
|
+
sampleDatasetLink: "https://storage.googleapis.com/deai-313515.appspot.com/example_training_data.tar.gz",
|
|
18
|
+
sampleDatasetInstructions: 'Opening the link should start downloading a zip file which you can unzip. Inside the "example_training_data" directory you should find the "simple_face" folder which contains the "adult" and "child" folders. To connect the data, select the Group option below and connect adults and children image groups.'
|
|
17
19
|
},
|
|
18
20
|
trainingInformation: {
|
|
19
21
|
modelID: 'simple_face-model',
|
|
@@ -5,14 +5,14 @@ export const titanic = {
|
|
|
5
5
|
return {
|
|
6
6
|
id: 'titanic',
|
|
7
7
|
displayInformation: {
|
|
8
|
-
taskTitle: 'Titanic',
|
|
8
|
+
taskTitle: 'Titanic Prediction',
|
|
9
9
|
summary: {
|
|
10
|
-
preview: "
|
|
11
|
-
overview:
|
|
10
|
+
preview: "The Titanic classification task is one of the main entrypoints into machine learning. Using passenger data (name, age, gender, socio-economic class, etc), the goal is to identify who was more likely to survive the infamous shipwreck.",
|
|
11
|
+
overview: "The original competition can be found on <a target='_blank' class='underline text-blue-400' href='https://www.kaggle.com/c/titanic'>Kaggle</a> and a link to the training set can be found here <a target='_blank' class='underline text-blue-400' href='https://storage.googleapis.com/deai-313515.appspot.com/example_training_data/titanic_train.csv'>here</a>."
|
|
12
12
|
},
|
|
13
|
-
model: 'The
|
|
14
|
-
dataFormatInformation: '
|
|
15
|
-
dataExampleText: '
|
|
13
|
+
model: 'The model is a simple 5-layer feedforward network with ReLU activations. The model is optimized with Adam and binary cross-entropy loss. The preprocessing only fills missing value with a placeholder value (0).',
|
|
14
|
+
dataFormatInformation: 'The expected format for the tabular dataset is exactly the same as the sample data provided above or in the Kaggle competition. It is a CSV file with 12 columns. The features are general information about the passenger (sex, age, name, etc.) and specific related Titanic data such as the ticket class bought by the passenger, its cabin number, etc.<br>The first line of the CSV contains the header: "PassengerId, Survived, Pclass, Name, Sex, Age, SibSp, Parch, Ticket, Fare, Cabin, Embarked"<br>Each subsequent row contains passenger data.',
|
|
15
|
+
dataExampleText: "Here's an example of one data point:",
|
|
16
16
|
dataExample: [
|
|
17
17
|
{ columnName: 'PassengerId', columnData: '1' },
|
|
18
18
|
{ columnName: 'Survived', columnData: '0' },
|
|
@@ -40,11 +40,13 @@ export const titanic = {
|
|
|
40
40
|
'Cabin',
|
|
41
41
|
'Embarked',
|
|
42
42
|
'Pclass'
|
|
43
|
-
]
|
|
43
|
+
],
|
|
44
|
+
sampleDatasetLink: "https://storage.googleapis.com/deai-313515.appspot.com/example_training_data/titanic_train.csv",
|
|
45
|
+
sampleDatasetInstructions: 'Opening the link should start downloading a CSV file which you can drag and drop in the field below.'
|
|
44
46
|
},
|
|
45
47
|
trainingInformation: {
|
|
46
48
|
modelID: 'titanic-model',
|
|
47
|
-
epochs:
|
|
49
|
+
epochs: 40,
|
|
48
50
|
roundDuration: 10,
|
|
49
51
|
validationSplit: 0.2,
|
|
50
52
|
batchSize: 30,
|
|
@@ -79,7 +81,7 @@ export const titanic = {
|
|
|
79
81
|
model.add(tf.layers.dense({ units: 32, activation: 'relu' }));
|
|
80
82
|
model.add(tf.layers.dense({ units: 1, activation: 'sigmoid' }));
|
|
81
83
|
model.compile({
|
|
82
|
-
optimizer:
|
|
84
|
+
optimizer: 'adam',
|
|
83
85
|
loss: 'binaryCrossentropy',
|
|
84
86
|
metrics: ['accuracy']
|
|
85
87
|
});
|
|
@@ -2,20 +2,22 @@ import { data, models } from '../index.js';
|
|
|
2
2
|
export const wikitext = {
|
|
3
3
|
getTask() {
|
|
4
4
|
return {
|
|
5
|
-
id: '
|
|
5
|
+
id: 'llm_task',
|
|
6
6
|
displayInformation: {
|
|
7
|
-
taskTitle: 'Language
|
|
7
|
+
taskTitle: 'GPT Language Modeling',
|
|
8
8
|
summary: {
|
|
9
|
-
preview: '
|
|
10
|
-
overview:
|
|
9
|
+
preview: 'Train a language model (L)LM in your browser, collaboratively and from scratch.',
|
|
10
|
+
overview: "You can train a GPT-2 model in your browser and in a collaborative manner on any textual dataset. As an example, you can try the Wikitext-103 dataset, composed of Wikipedia articles, widely used in natural language modeling, which you can download <a class='underline text-blue-400' target='_blank' href='https://dax-cdn.cdn.appdomain.cloud/dax-wikitext-103/1.0.1/wikitext-103.tar.gz'>here</a>. More information on how to connect the dataset at the next step."
|
|
11
11
|
},
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
model: 'The model follows the exact GPT-2 architecture and is implemented in TensorFlow.js. The tokenizer used for preprocessing is the GPT-2 Byte-Pair encoding tokenizer. The model is trained via an Adam optimizer with unit gradient clipping and softmax cross-entropy loss. To accommodate all devices, the context length is currently kept at 128 and the batch size at 1.',
|
|
13
|
+
dataFormatInformation: 'You can use any natural language (text) dataset you like. For example the Wikitext-103 dataset is organized as a large text file, with each line representing a segment of raw text from Wikipedia articles.',
|
|
14
|
+
dataExampleText: 'An example excerpt from the dataset is: <i>"For the first twenty years of its existence , the only staged performances of Parsifal took place in the Bayreuth Festspielhaus , the venue for which Wagner conceived the work ( except eight private performances for Ludwig II at Munich in 1884 and 1885 ) ."</i>',
|
|
15
|
+
sampleDatasetLink: 'https://dax-cdn.cdn.appdomain.cloud/dax-wikitext-103/1.0.1/wikitext-103.tar.gz',
|
|
16
|
+
sampleDatasetInstructions: 'Opening the link should start downloading a zip file. Unzip it and drag and drop the training set named "wiki.train.tokens" in the field below (or use the "Select File" button). Even though the file extension is ".tokens" it is indeed a text file. You can use "wiki.test.tokens" at the evaluation step after training a language model.'
|
|
15
17
|
},
|
|
16
18
|
trainingInformation: {
|
|
17
19
|
dataType: 'text',
|
|
18
|
-
modelID: '
|
|
20
|
+
modelID: 'llm-raw-model',
|
|
19
21
|
preprocessingFunctions: [data.TextPreprocessing.Tokenize, data.TextPreprocessing.LeftPadding],
|
|
20
22
|
scheme: 'federated',
|
|
21
23
|
epochs: 5,
|
|
@@ -23,7 +25,7 @@ export const wikitext = {
|
|
|
23
25
|
// But if set to 0 then the webapp doesn't display the validation metrics
|
|
24
26
|
validationSplit: 0.1,
|
|
25
27
|
roundDuration: 2,
|
|
26
|
-
batchSize: 1, // If set too high (e.g. 16)
|
|
28
|
+
batchSize: 1, // If set too high (e.g. 16) firefox raises a WebGL error
|
|
27
29
|
tokenizer: 'Xenova/gpt2',
|
|
28
30
|
maxSequenceLength: 128,
|
|
29
31
|
tensorBackend: 'gpt'
|
|
@@ -4,13 +4,14 @@ export function isDisplayInformation(raw) {
|
|
|
4
4
|
if (typeof raw !== 'object' || raw === null) {
|
|
5
5
|
return false;
|
|
6
6
|
}
|
|
7
|
-
const { dataExample, dataExampleImage, dataExampleText, dataFormatInformation, sampleDatasetLink, headers, model, summary, taskTitle, } = raw;
|
|
7
|
+
const { dataExample, dataExampleImage, dataExampleText, dataFormatInformation, sampleDatasetLink, sampleDatasetInstructions, headers, model, summary, taskTitle, } = raw;
|
|
8
8
|
if (typeof taskTitle !== 'string' ||
|
|
9
9
|
(dataExampleText !== undefined && typeof dataExampleText !== 'string') ||
|
|
10
10
|
(sampleDatasetLink !== undefined && typeof sampleDatasetLink !== 'string') ||
|
|
11
11
|
(dataFormatInformation !== undefined && typeof dataFormatInformation !== 'string') ||
|
|
12
12
|
(model !== undefined && typeof model !== 'string') ||
|
|
13
|
-
(dataExampleImage !== undefined && typeof dataExampleImage !== 'string')
|
|
13
|
+
(dataExampleImage !== undefined && typeof dataExampleImage !== 'string') ||
|
|
14
|
+
(sampleDatasetInstructions !== undefined && typeof sampleDatasetInstructions !== 'string')) {
|
|
14
15
|
return false;
|
|
15
16
|
}
|
|
16
17
|
if (!isSummary(summary)) {
|
|
@@ -46,6 +47,7 @@ export function isDisplayInformation(raw) {
|
|
|
46
47
|
dataExampleText,
|
|
47
48
|
dataFormatInformation,
|
|
48
49
|
sampleDatasetLink,
|
|
50
|
+
sampleDatasetInstructions,
|
|
49
51
|
headers,
|
|
50
52
|
model,
|
|
51
53
|
summary,
|
package/package.json
CHANGED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import * as tf from '@tensorflow/tfjs';
|
|
2
|
-
import { data, models } from '../index.js';
|
|
3
|
-
const IMAGE_SIZE = 128;
|
|
4
|
-
const LABELS = ['Eczema', 'Allergic Contact Dermatitis', 'Urticaria'];
|
|
5
|
-
export const skinCondition = {
|
|
6
|
-
getTask() {
|
|
7
|
-
return {
|
|
8
|
-
id: 'skin_condition',
|
|
9
|
-
displayInformation: {
|
|
10
|
-
taskTitle: 'Skin Condition Classification',
|
|
11
|
-
summary: {
|
|
12
|
-
preview: "Identify common skin conditions from volunteer image contributions. You can find a sample dataset of 400 images <a class='underline text-primary-dark dark:text-primary-light' href='https://storage.googleapis.com/deai-313515.appspot.com/scin_sample.zip'>here</a> or see the full <a class='underline text-primary-dark dark:text-primary-light' href='https://github.com/google-research-datasets/scin/tree/main'>SCIN dataset</a>. You can find how to download and preprocess the dataset <a class='underline text-primary-dark dark:text-primary-light' href='https://github.com/epfml/disco/blob/develop/docs/examples/scin_dataset.ipynb'>in this notebook</a>.",
|
|
13
|
-
overview: "The <a class='underline text-primary-dark dark:text-primary-light' href='https://github.com/google-research-datasets/scin/tree/main'>SCIN (Skin Condition Image Network) open access dataset</a> aims to supplement publicly available dermatology datasets from health system sources with representative images from internet users. To this end, the SCIN dataset was collected from Google Search users in the United States through a voluntary, consented image donation application. The SCIN dataset is intended for health education and research, and to increase the diversity of dermatology images available for public use. The SCIN dataset contains 5,000+ volunteer contributions (10,000+ images) of common dermatology conditions. Contributions include Images, self-reported demographic, history, and symptom information, and self-reported Fitzpatrick skin type (sFST). In addition, dermatologist labels of the skin condition are provided for each contribution. You can find more information on the dataset and classification task <a class='underline text-primary-dark dark:text-primary-light' href='https://arxiv.org/abs/2402.18545'>here</a>."
|
|
14
|
-
},
|
|
15
|
-
dataFormatInformation: "There are hundreds of skin condition labels in the SCIN dataset. For the sake of simplicity, we only include the 3 most common conditions in the sample dataset: 'Eczema', 'Allergic Contact Dermatitis' and 'Urticaria'. Therefore, each image is expected to be labeled with one of these three categories.",
|
|
16
|
-
sampleDatasetLink: 'https://storage.googleapis.com/deai-313515.appspot.com/scin_sample.zip'
|
|
17
|
-
},
|
|
18
|
-
trainingInformation: {
|
|
19
|
-
modelID: 'skin-condition-model',
|
|
20
|
-
epochs: 10,
|
|
21
|
-
roundDuration: 2,
|
|
22
|
-
validationSplit: 0.3,
|
|
23
|
-
batchSize: 8,
|
|
24
|
-
preprocessingFunctions: [data.ImagePreprocessing.Resize, data.ImagePreprocessing.Normalize],
|
|
25
|
-
dataType: 'image',
|
|
26
|
-
IMAGE_H: IMAGE_SIZE,
|
|
27
|
-
IMAGE_W: IMAGE_SIZE,
|
|
28
|
-
LABEL_LIST: LABELS,
|
|
29
|
-
scheme: 'federated',
|
|
30
|
-
noiseScale: undefined,
|
|
31
|
-
clippingRadius: undefined,
|
|
32
|
-
tensorBackend: 'tfjs'
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
},
|
|
36
|
-
async getModel() {
|
|
37
|
-
const imageChannels = 3;
|
|
38
|
-
const numOutputClasses = LABELS.length;
|
|
39
|
-
const model = tf.sequential();
|
|
40
|
-
model.add(tf.layers.conv2d({
|
|
41
|
-
inputShape: [IMAGE_SIZE, IMAGE_SIZE, imageChannels],
|
|
42
|
-
filters: 8,
|
|
43
|
-
kernelSize: 3,
|
|
44
|
-
strides: 1,
|
|
45
|
-
kernelInitializer: 'varianceScaling',
|
|
46
|
-
activation: 'relu'
|
|
47
|
-
}));
|
|
48
|
-
model.add(tf.layers.maxPooling2d({ poolSize: [2, 2] }));
|
|
49
|
-
model.add(tf.layers.dropout({ rate: 0.2 }));
|
|
50
|
-
const convFilters = [16, 32, 64, 128];
|
|
51
|
-
for (const filters of convFilters) {
|
|
52
|
-
model.add(tf.layers.conv2d({
|
|
53
|
-
filters: filters,
|
|
54
|
-
kernelSize: 3,
|
|
55
|
-
strides: 1,
|
|
56
|
-
kernelInitializer: 'varianceScaling',
|
|
57
|
-
activation: 'relu'
|
|
58
|
-
}));
|
|
59
|
-
model.add(tf.layers.maxPooling2d({ poolSize: [2, 2] }));
|
|
60
|
-
model.add(tf.layers.dropout({ rate: 0.2 }));
|
|
61
|
-
}
|
|
62
|
-
model.add(tf.layers.flatten());
|
|
63
|
-
model.add(tf.layers.dense({
|
|
64
|
-
units: 64,
|
|
65
|
-
kernelInitializer: 'varianceScaling',
|
|
66
|
-
activation: 'relu',
|
|
67
|
-
}));
|
|
68
|
-
model.add(tf.layers.dense({
|
|
69
|
-
units: numOutputClasses,
|
|
70
|
-
kernelInitializer: 'varianceScaling',
|
|
71
|
-
activation: 'softmax'
|
|
72
|
-
}));
|
|
73
|
-
model.compile({
|
|
74
|
-
optimizer: tf.train.adam(),
|
|
75
|
-
loss: 'categoricalCrossentropy',
|
|
76
|
-
metrics: ['accuracy']
|
|
77
|
-
});
|
|
78
|
-
return Promise.resolve(new models.TFJS(model));
|
|
79
|
-
}
|
|
80
|
-
};
|