필터 지우기
필터 지우기

GAN intermediate layer for image multiplication

조회 수: 1 (최근 30일)
Glacial Claw
Glacial Claw 2023년 2월 23일
편집: Rahul 2023년 3월 1일
So I have created a GAN that uses a regular noise input for image synthesis. However, I want to multiply or get the product of the generated image with an outside image to speed up training/ training convergence. Here is the basic idea:
%This is the layer setup I use for my GAN
numFilters = 128;
numLatentInputs = 256;
inputSize = [128 128 3];
projectionSize = [4 4 3];
layersGenerator = [
featureInputLayer(numLatentInputs)
projectAndReshapeLayer(projectionSize)
resize2dLayer('OutputSize',[4 4],'Method','bilinear')
batchNormalizationLayer
leakyReluLayer
resize2dLayer('OutputSize',[16 16],'Method','bilinear')
batchNormalizationLayer
leakyReluLayer
resize2dLayer('OutputSize',[32 32],'Method','bilinear')
batchNormalizationLayer
leakyReluLayer
resize2dLayer('OutputSize',[64 64],'Method','bilinear')
batchNormalizationLayer
leakyReluLayer
resize2dLayer('OutputSize',[128 128],'Method','bilinear')
batchNormalizationLayer
tanhLayer];
layersDiscriminator = [
imageInputLayer(inputSize,Normalization="none")
dropoutLayer(dropoutProb)
resize2dLayer('OutputSize',[128 128],'Method','bilinear')
convolution2dLayer(filterSize,numFilters,Stride=2,Padding="same")
leakyReluLayer(scale)
resize2dLayer('OutputSize',[64 64],'Method','bilinear')
convolution2dLayer(filterSize,2*numFilters,Stride=2,Padding="same")
batchNormalizationLayer
leakyReluLayer(scale)
resize2dLayer('OutputSize',[32 32],'Method','bilinear')
convolution2dLayer(filterSize,4*numFilters,Stride=2,Padding="same")
batchNormalizationLayer
leakyReluLayer(scale)
resize2dLayer('OutputSize',[16 16],'Method','bilinear')
convolution2dLayer(filterSize,8*numFilters,Stride=2,Padding="same")
batchNormalizationLayer
leakyReluLayer(scale)
resize2dLayer('OutputSize',[8 8],'Method','bilinear')
convolution2dLayer(8,1)
sigmoidLayer];
numEpochs = 2000;
miniBatchSize = 16;
learnRate = 0.0003;
gradientDecayFactor = 0.5;
squaredGradientDecayFactor = 0.999;
flipProb = 0.75;
validationFrequency = 5;
%The custom layer that I have already made:
classdef imageProduct < nnet.layer.Layer
properties (Constant)
ImageinputT = imread("image.jpg");
end
methods
function layer = imageProduct()
layer.Type = "Image Product";
layer.Description = "Combine Images";
layer.OutputNames = "out";
end
function [Z] = predict(~,X)
%gets the image size so the input image can be resized. Basically the target scale
[WidthX, HeightX] = size(X);
%resizes the imported image
GinputIm_scaled = imresize(crossAttention.ImageinputT, [WidthX HeightX]);
%converts images to double
GinputIm_scaled_single = single(GinputIm_scaled);
Xsingle = single(X);
%Gets the tensor product of the two images
Xnew = tensorprod(GinputIm_scaled_single, Xsingle);
Z = Xnew; %output image
end
end
end
  댓글 수: 1
Rahul
Rahul 2023년 3월 1일
편집: Rahul 2023년 3월 1일
What is exactly the issue? Are you receiving any error? Please post the error message if any.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by