MyCaffe  1.11.7.7
Deep learning software for Windows C# programmers.
MyCaffe.extras.NeuralStyleTransfer< T > Class Template Reference

The NeuralStyleTransfer object uses the GramLayer, TVLossLayer and LBFGSSolver to perform the neural style transfer algorithm. More...

Inheritance diagram for MyCaffe.extras.NeuralStyleTransfer< T >:

Public Member Functions

 NeuralStyleTransfer (CudaDnn< T > cuda, Log log, CancelEvent evtCancel, string strModelType, string strModel, byte[] rgWeights, bool bCaffeModel, SolverParameter.SolverType solverType=SolverParameter.SolverType.LBFGS, double dfLearningRate=1.5, int nLBFGSCorrections=100, double dfDataScale=1.0, Net< T > netShare=null)
 The constructor. More...
 
 NeuralStyleTransfer (CudaDnn< T > cuda, Log log, CancelEvent evtCancel, Dictionary< string, Tuple< double, double > > rgLayers, string strModelDesc, byte[] rgWeights, bool bCaffeModel, SolverParameter.SolverType solverType=SolverParameter.SolverType.LBFGS, double dfLearningRate=1.0, int nMaxImageSize=840, int nLBFGSCorrections=100, double dfDataScale=1.0, Net< T > netShare=null)
 The constructor. More...
 
void Dispose ()
 Release all resources used. More...
 
void SetupHalfSize (bool bAllowHs, bool bAllowOnGram, bool bAllowOnEvent, bool bAllowOnLoss, bool bAllowOnScalar)
 Setup which layers are allowed to use half-sized memory when their convolution counterparts use it. More...
 
Bitmap Process (Bitmap bmpStyle, Bitmap bmpContent, int nIterations, int nIntermediateOutput=-1, double dfTvLoss=0, int nMaxSize=-1, bool bEnablePartialSolution=false)
 Process the content image by applying the style to it that was learned from the style image. More...
 
Bitmap ProcessNext (out Bitmap bmpIntermediate, out int nIntermediateIdx)
 Process the next partial part of the solution. This function is only valid after calling Process with bEnablePartialSolution = true. More...
 

Static Public Member Functions

static string CreateConfigurationString (string strSolver, double dfLearningRate, int nMaxImageSize, int nIterations, int nIntermediateIterations, Dictionary< string, Tuple< double, double > > rgWts, List< int > rgGpuID, int nLBFGSCorrections, double dfDataScale, bool bAllowHs, bool bAllowHsGram, bool bAllowHsEvent, bool bAllowHsScalar, bool bAllowHsLoss)
 The CreateConfigurationString function packs all deep draw settings into a configuration string. More...
 
static Dictionary< string, Tuple< double, double > > ParseConfigurationString (string strConfig, out string strSolver, out double dfLearningRate, out int nMaxImageSize, out int nIterations, out int nIntermediateIterations, out List< int > rgGpuID, out int nLBFGSCorrections, out double dfDataScale, out bool bAllowHs, out bool bAllowHsGram, out bool bAllowHsEvent, out bool bAllowHsScalar, out bool bAllowHsLoss)
 The ParseConfigurationString method parses a deep draw configuration string into the actual settings. More...
 

Events

EventHandler< NeuralStyleIntermediateOutputArgsOnIntermediateOutput
 Specifies the event fired after producing intermediate output (e.g. when m_nIntermediateOutput > 0) More...
 

Detailed Description

The NeuralStyleTransfer object uses the GramLayer, TVLossLayer and LBFGSSolver to perform the neural style transfer algorithm.

See also
minFunc by Marc Schmidt, 2005
ftokarev/caffe-neural-style Github by ftokarev, 2017.
fzliu/style-transfer Github by Frank Liu and Dylan Paiton, 2015.
A Neural Algorithm of Artistic Style by Leon A. Gatys, Alexander S. Ecker, and Matthias Bethge, 2015
Neural Style Transfer: Creating Art with Deep Learning using tf.keras and eager execution by Raymond Yuan, Medium, 2018
Neural Artistic Style Transfer: A Comprehensive Look by Shubhang Desai, Medium, 2017

Definition at line 30 of file NeuralStyleTransfer.cs.

Constructor & Destructor Documentation

◆ NeuralStyleTransfer() [1/2]

MyCaffe.extras.NeuralStyleTransfer< T >.NeuralStyleTransfer ( CudaDnn< T >  cuda,
Log  log,
CancelEvent  evtCancel,
string  strModelType,
string  strModel,
byte[]  rgWeights,
bool  bCaffeModel,
SolverParameter.SolverType  solverType = SolverParameter.SolverType.LBFGS,
double  dfLearningRate = 1.5,
int  nLBFGSCorrections = 100,
double  dfDataScale = 1.0,
Net< T >  netShare = null 
)

The constructor.

Parameters
cudaSpecifies the instance of CudaDnn to use.
logSpecifies the output log.
evtCancelSpecifies the cancel event used to abort processing.
strModelTypeSpecifies the model type: 'vgg19', 'vgg16'
strModelSpecifies the network model to use.
rgWeightsOptionally, specifies the weights to use (or null to ignore).
bCaffeModelSpecifies whether or not the weights are in the caffe (true) or mycaffe (false) format.
solverTypeOptionally, specifies the solver type to use (default = LBFGS).
dfLearningRateOptionally, specifies the solver learning rate (default = 1.0).
nLBFGSCorrectionsOptionally, specifies the number of LBFGS corrections to use (default = 100, only applies when using LBFGS solver).
dfDataScaleOptionally, specifies the data scaling factor (default = 1.0).
netShareOptionally, specifies a net to share.

Definition at line 89 of file NeuralStyleTransfer.cs.

◆ NeuralStyleTransfer() [2/2]

MyCaffe.extras.NeuralStyleTransfer< T >.NeuralStyleTransfer ( CudaDnn< T >  cuda,
Log  log,
CancelEvent  evtCancel,
Dictionary< string, Tuple< double, double > >  rgLayers,
string  strModelDesc,
byte[]  rgWeights,
bool  bCaffeModel,
SolverParameter.SolverType  solverType = SolverParameter.SolverType.LBFGS,
double  dfLearningRate = 1.0,
int  nMaxImageSize = 840,
int  nLBFGSCorrections = 100,
double  dfDataScale = 1.0,
Net< T >  netShare = null 
)

The constructor.

Parameters
cudaSpecifies the instance of CudaDnn to use.
logSpecifies the output log.
evtCancelSpecifies the cancel event used to abort processing.
rgLayersSpecifies the layers along with their style and content weights.
strModelDescSpecifies the network model descriptor to use.
rgWeightsOptionally, specifies the weights to use (or null to ignore).
bCaffeModelSpecifies whether or not the weights are in the caffe (true) or mycaffe (false) format.
solverTypeOptionally, specifies the solver type to use (default = LBFGS).
dfLearningRateOptionally, specifies the solver learning rate (default = 1.0).
nMaxImageSizeOptionally, specifies the default maximum image size (default = 840).
nLBFGSCorrectionsOptionally, specifies the LBFGS Corrections (only used when using the LBFGS solver, default = 100).
dfDataScaleOptionally, specifies the data scaling factor (default = 1.0).
netShareOptionally, specifies a net to share.

Definition at line 137 of file NeuralStyleTransfer.cs.

Member Function Documentation

◆ CreateConfigurationString()

static string MyCaffe.extras.NeuralStyleTransfer< T >.CreateConfigurationString ( string  strSolver,
double  dfLearningRate,
int  nMaxImageSize,
int  nIterations,
int  nIntermediateIterations,
Dictionary< string, Tuple< double, double > >  rgWts,
List< int >  rgGpuID,
int  nLBFGSCorrections,
double  dfDataScale,
bool  bAllowHs,
bool  bAllowHsGram,
bool  bAllowHsEvent,
bool  bAllowHsScalar,
bool  bAllowHsLoss 
)
static

The CreateConfigurationString function packs all deep draw settings into a configuration string.

Parameters
strSolverSpecifies the type of solver to use.
dfLearningRateSpecifies the learning rate to use with the solver.
nMaxImageSizeSpecifies the maximum image size to use.
nIterationsSpecifies the number of iterations to run.
nIntermediateIterationsSpecifies how often to output intermediate images if any (a value of 0 disables intermediate output).
rgWtsSpecifies the layers to use and their weights for style and content.
rgGpuIDSpecifies the GPUIDs on which to run the Neural Style.
nLBFGSCorrectionsSpecifies the LBFGS corrections to use, only applies when using the LBFGS Solver.
dfDataScaleSpecifies the data scale (default = 1.0).
bAllowHsSpecivies to allow half sized memory.
bAllowHsGramSpecifies to allow half sized memory on gram layers.
bAllowHsEventSpecifies to allow half sized memory on event layers.
bAllowHsScalarSpecifies to allow half sized memory on scalar layers.
bAllowHsLossSpecifies to allow half sized memory on loss layers.
Returns
The configuration string is returned.

Definition at line 1023 of file NeuralStyleTransfer.cs.

◆ Dispose()

void MyCaffe.extras.NeuralStyleTransfer< T >.Dispose ( )

Release all resources used.

Definition at line 183 of file NeuralStyleTransfer.cs.

◆ ParseConfigurationString()

static Dictionary< string, Tuple< double, double > > MyCaffe.extras.NeuralStyleTransfer< T >.ParseConfigurationString ( string  strConfig,
out string  strSolver,
out double  dfLearningRate,
out int  nMaxImageSize,
out int  nIterations,
out int  nIntermediateIterations,
out List< int >  rgGpuID,
out int  nLBFGSCorrections,
out double  dfDataScale,
out bool  bAllowHs,
out bool  bAllowHsGram,
out bool  bAllowHsEvent,
out bool  bAllowHsScalar,
out bool  bAllowHsLoss 
)
static

The ParseConfigurationString method parses a deep draw configuration string into the actual settings.

Parameters
strConfigSpecifies the configuration string to parse.
strSolverReturns the solver to use.
dfLearningRateReturns the learning rate to use with the solver.
nMaxImageSizeReturns the maximum image size.
nIterationsReturns the number of iterations to run.
nIntermediateIterationsReturns how often to output intermediate images if any (a value of 0 disables intermediate output).
rgGpuIDReturns the list of GPUIDs on which to run the Neural Style.
nLBFGSCorrectionsReturns the LBFGS corrections to use, only applies when using the LBFGS Solver.
dfDataScaleReturns the data scale to use, default = 1.0.
bAllowHsReturns whether or not half size memory is allowed.
bAllowHsGramReturns whether or not to allow half size memory in the gram layers.
bAllowHsEventReturns whether or not to allow half size memory in the event layers.
bAllowHsScalarReturns whether or not to allow half size memory in the scalar layers.
bAllowHsLossReturns whether or not to allow half size memory in the loss layers.
Returns
Returns a list of layers along with their style and content weights.

Definition at line 1084 of file NeuralStyleTransfer.cs.

◆ Process()

Bitmap MyCaffe.extras.NeuralStyleTransfer< T >.Process ( Bitmap  bmpStyle,
Bitmap  bmpContent,
int  nIterations,
int  nIntermediateOutput = -1,
double  dfTvLoss = 0,
int  nMaxSize = -1,
bool  bEnablePartialSolution = false 
)

Process the content image by applying the style to it that was learned from the style image.

Parameters
bmpStyleSpecifies the image used to train the what style to apply to the content.
bmpContentSpecifies the content image to which the style is to be applied.
nIterationsSpecifies the number of training iterations.
nIntermediateOutputOptionally, specifies how often to output an intermediate image.
dfTvLossOptionally, specifies the TV-Loss weight for smoothing (default = 0, which disables this loss).
nMaxSizeOptionally, specifies a maximum image size override (default = -1, which uses the default).
bEnablePartialSolutionOptionally, specifies to run the process only up through the next intermediate image. Subsequent calls to ProcessNext moves to the next intermediate image until completed.
Returns
Upon completion the resulting final image is returned, otherwise when using bEnablePartionSolution = true, null is returned.

Definition at line 530 of file NeuralStyleTransfer.cs.

◆ ProcessNext()

Bitmap MyCaffe.extras.NeuralStyleTransfer< T >.ProcessNext ( out Bitmap  bmpIntermediate,
out int  nIntermediateIdx 
)

Process the next partial part of the solution. This function is only valid after calling Process with bEnablePartialSolution = true.

Parameters
bmpIntermediateReturns the intermediate image, if one was created.
nIntermediateIdxReturns the intermediate index for the image.
Returns
Upon completion, the final Bitmap is returned, otherwise null is returned.

Definition at line 919 of file NeuralStyleTransfer.cs.

◆ SetupHalfSize()

void MyCaffe.extras.NeuralStyleTransfer< T >.SetupHalfSize ( bool  bAllowHs,
bool  bAllowOnGram,
bool  bAllowOnEvent,
bool  bAllowOnLoss,
bool  bAllowOnScalar 
)

Setup which layers are allowed to use half-sized memory when their convolution counterparts use it.

Parameters
bAllowHsAllow half-size memory.
bAllowOnGramAllow half-size on the gram layers.
bAllowOnEventAllow half-size on the event layers.
bAllowOnLossAllow half-size on the loss layers.
bAllowOnScalarAllow half-size on the scalar layers.

Definition at line 215 of file NeuralStyleTransfer.cs.

Event Documentation

◆ OnIntermediateOutput

Specifies the event fired after producing intermediate output (e.g. when m_nIntermediateOutput > 0)

Definition at line 72 of file NeuralStyleTransfer.cs.


The documentation for this class was generated from the following file: