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.ffmpeg.global.avcodec; | |
import org.bytedeco.ffmpeg.global.avutil; | |
import org.bytedeco.javacv.*; | |
import org.bytedeco.opencv.opencv_core.*; | |
import static org.bytedeco.opencv.global.opencv_imgproc.*; | |
import static org.bytedeco.opencv.helper.opencv_core.RGB; | |
import org.bytedeco.opencv.opencv_videoio.VideoWriter; | |
import org.datavec.image.loader.NativeImageLoader; | |
import org.datavec.image.transform.ColorConversionTransform; | |
import org.deeplearning4j.nn.graph.ComputationGraph; |
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
class myCallback(tf.keras.callbacks.Callback): | |
def on_epoch_end(self, epoch, logs={}): | |
if(logs.get('acc')>0.6): | |
print("\nReached 60% accuracy so cancelling training!") | |
self.model.stop_training = True |
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
#Original source from https://github.com/opencv/opencv/blob/master/samples/python/tutorial_code/ShapeDescriptors/hull/hull_demo.py | |
from __future__ import print_function | |
import cv2 as cv | |
import numpy as np | |
import argparse | |
import random as rng | |
rng.seed(12345) |
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
(base) D:\Efficient-PyTorch\tools>python folder2lmdb.py -f "C:\Users\ChooWilson\.fastai\data\kaggle-cat-dog" -s train | |
Loading dataset from C:\Users\ChooWilson\.fastai\data\kaggle-cat-dog\train | |
Generate LMDB to C:\Users\ChooWilson\.fastai\data\kaggle-cat-dog\train.lmdb | |
2000 2000 | |
Traceback (most recent call last): | |
File "folder2lmdb.py", line 181, in <module> | |
folder2lmdb(args.folder, num_workers=args.procs, name=args.split) | |
File "folder2lmdb.py", line 150, in folder2lmdb | |
for idx, data in enumerate(data_loader): | |
File "C:\Users\ChooWilson\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 279, in __iter__ |
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)); | |
} |
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
<?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
/* | |
* | |
* * ****************************************************************************** | |
* * * 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
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
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; |