This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Color; | |
import java.awt.BasicStroke; | |
import org.jfree.chart.ChartPanel; | |
import org.jfree.chart.JFreeChart; | |
import org.jfree.data.xy.XYDataset; | |
import org.jfree.data.xy.XYSeries; | |
import org.jfree.ui.ApplicationFrame; | |
import org.jfree.ui.RefineryUtilities; | |
import org.jfree.chart.plot.XYPlot; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.bytedeco.opencv.opencv_core.Mat; | |
import org.bytedeco.opencv.opencv_core.Point; | |
import org.bytedeco.opencv.opencv_core.Scalar; | |
import java.util.ArrayList; | |
import java.util.List; | |
import static org.bytedeco.opencv.global.opencv_highgui.*; | |
import static org.bytedeco.opencv.global.opencv_imgcodecs.imread; | |
import static org.bytedeco.opencv.global.opencv_imgproc.circle; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# script referenced from https://github.com/Cartucho/mAP/tree/master/scripts/extra | |
import sys | |
import os | |
import glob | |
import xml.etree.ElementTree as ET | |
# make sure that the cwd() in the beginning is the location of the python script (so that every path makes sense) | |
os.chdir(os.path.dirname(os.path.abspath(__file__))) | |
# change directory to the one with the files to be changed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Tip 1: Do not save the updater if you do not plan to continue training your model | |
// Set false for saveUpdater flag. | |
ModelSerializer.writeModel(model, modelFilename, false); | |
// Results: Model size drop almost 40%. | |
// Tip 2: Convert FP32 to FP16 floating point precision(Quantization), currently DL4J only supports float. {DOUBLE, FLOAT, HALF} | |
// Convert the parameters just as below: | |
model = model.convertDataType(DataType.HALF); | |
// Results: Model size drop by 50%, half of its original size. Accuracy did not drop. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.datavec.api.io.filters.BalancedPathFilter; | |
import org.datavec.api.io.labels.ParentPathLabelGenerator; | |
import org.datavec.api.split.FileSplit; | |
import org.datavec.api.split.InputSplit; | |
import org.datavec.image.loader.BaseImageLoader; | |
import org.datavec.image.recordreader.ImageRecordReader; | |
import org.deeplearning4j.api.storage.StatsStorage; | |
import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator; | |
import org.deeplearning4j.nn.conf.layers.DenseLayer; | |
import org.deeplearning4j.nn.conf.layers.OutputLayer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package global.skymind.solution.convolution.objectdetection; | |
import org.bytedeco.opencv.opencv_core.Mat; | |
import org.bytedeco.opencv.opencv_core.Point; | |
import org.bytedeco.opencv.opencv_core.Scalar; | |
import org.bytedeco.opencv.opencv_core.Size; | |
import org.datavec.image.loader.NativeImageLoader; | |
import org.deeplearning4j.nn.graph.ComputationGraph; | |
import org.deeplearning4j.nn.layers.objdetect.DetectedObject; | |
import org.deeplearning4j.nn.layers.objdetect.YoloUtils; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* | |
* * ****************************************************************************** | |
* * * Copyright (c) 2019 Skymind AI Bhd. | |
* * * Copyright (c) 2020 CertifAI Sdn. Bhd. | |
* * * | |
* * * This program and the accompanying materials are made available under the | |
* * * terms of the Apache License, Version 2.0 which is available at | |
* * * https://www.apache.org/licenses/LICENSE-2.0. | |
* * * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>org.certifai</groupId> | |
<artifactId>MyDL4JProject</artifactId> | |
<version>0.1-SNAPSHOT</version> | |
<name>Computer Vision</name> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Take note this config is just an example | |
// Take note that my input is a Rank 4 tensor, a DataSetIterator that uses ImageRecordReader | |
// Method 1: using .setInputTypes(InputType.convolutional(height,width,channels)) | |
ComputationGraphConfiguration config = new NeuralNetConfiguration.Builder() | |
.seed(seed) | |
.updater(new RmsProp(1e-3)) | |
.weightInit(WeightInit.XAVIER) | |
.l2(1e-4) | |
.graphBuilder() | |
.addInputs("input") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Train your model and save the model if the training loss is better than the previous. Set saveUpdater boolean as "true" if you plan to continue training. Needed for updaters like Adam. | |
for (int i = 1; i < epochs + 1; i++) { | |
tunedModel.fit(trainIterator); | |
if (tunedModel.score() < lowest) { | |
lowest = tunedModel.score(); | |
String modelFilename = new File(".").getAbsolutePath() + "/ImageClassifier_loss" + lowest + "_ep" + i + ".zip"; | |
ModelSerializer.writeModel(tunedModel, modelFilename, true); | |
} | |
System.out.println(String.format("Completed epoch %d.", i)); | |
} |