how to generate deep dream data from own Images ?
Ältere Kommentare anzeigen
how to generate deep dream data from own Images ?
Akzeptierte Antwort
Weitere Antworten (9)
Delprat Sebastien
am 4 Jan. 2018
Bearbeitet: Star Strider
am 4 Jan. 2018
clear all;
close all;
clc;
% ===============================
% You will need to download the net using the Matlab app finder tool
% ===============================
No=1;
switch No
case 1
net=alexnet;
netname='AlexNet';
layer = 23; % Ouput layer before classification
case 2
net=vgg16;
netname='VGG16';
layer = 39; % Ouput layer before classification
end
InputSize=net.Layers(1).InputSize;
fprintf('==============================\n');
fprintf('Network layers\n');
net.Layers
fprintf('==============================\n');
fprintf('Network classes\n');
for i=1:length(net.Layers(end).ClassNames)
fprintf('%i - %s\n',i,net.Layers(end).ClassNames{i});
end
% ==============================================
% Your image to be used as a starting dream
% ==============================================
FileName='Poisson';
initImg=imread([FileName '.jpg']);
initImg=imresize(initImg,InputSize(1:2));
[label,scores] = classify(net,initImg);
% Display network output, just for info (display the 5 more probable
% classes)
[~,idx] = sort(scores,'descend');
idx = idx(5:-1:1);
classNames = net.Layers(end).ClassNames;
classNamesTop = classNames(idx);
scoreTop = scores(idx);
fprintf('Most probable classes:\n');
for i=1:length(idx)
fprintf('%i - %s - %f\n',i,classNamesTop{i},scoreTop(i));
end
% Display initial image
figure;
imshow(initImg)
channels = [208]; % Golden retriever
channels = 53; % Thunder snake
channels = 481; % Cash machine
channels = 158; % Papillon
channels = 162; % Basset
channels = 328; % Starfish
channels = 818; % sports car
fprintf('Targeted class: %s\n',net.Layers(end).ClassNames{channels});
levels = 1; % 1 or 2 is good
iterations = 20; % higher better, but also longer
I = deepDreamImage(net,layer,channels, ...
'Verbose',true, ...
'NumIterations',iterations, ...
'PyramidLevels',levels,...
'InitialImage',initImg);% 'PyramidScale',1.2,...
% Save result and built file name using algorithm config
Classname=net.Layers(end).ClassNames{channels};
name=sprintf('dreem_%s_%s_chl_%i_iter_%i_lvl_%i_%s',netname,FileName,channels,iterations,levels,Classname);
imwrite(I,[name '.jpg']);
% Display result
figure
imshow(I)
Original image:

Dreamed image (fish interpreted as a snake)

Selva Karna
am 29 Mär. 2018
Bearbeitet: Selva Karna
am 29 Mär. 2018
0 Stimmen
6 Kommentare
Image Analyst
am 29 Mär. 2018
See attached zoom demo.
Selva Karna
am 29 Mär. 2018
Image Analyst
am 29 Mär. 2018
I totally don't understand the question. You want to change what?
Selva Karna
am 30 Mär. 2018
Selva Karna
am 30 Mär. 2018
Image Analyst
am 31 Mär. 2018
Alexnet is built assuming that size. If you want different size you'd have to use a different network. However, you will probably find it does just fine with resizing your images to that. It will most likely still work with your images.
Delprat Sebastien
am 1 Apr. 2018
0 Stimmen
Please look at the following code https://fr.mathworks.com/matlabcentral/fileexchange/66710-deep-dreaming-animation-for-matlab
There is : 1) a required modification to add clipping to the original matlab code 2) a script that generate an animation from image (with resizing) using recursive deepdream
NB : please read carefully the patch.m file... Enjoy
Selva Karna
am 2 Apr. 2018
Bearbeitet: Image Analyst
am 2 Apr. 2018
2 Kommentare
Delprat Sebastien
am 2 Apr. 2018
Bearbeitet: Delprat Sebastien
am 2 Apr. 2018
If you do not copy the error in detail, I cannot help. Did you copy the deepDreamImageLaplacianNorm as deepDreamImageLaplacianNorm2 in the specified matlab toolbox folder?
Selva Karna
am 3 Apr. 2018
Bearbeitet: Selva Karna
am 3 Apr. 2018
Selva Karna
am 3 Apr. 2018
0 Stimmen
Delprat Sebastien
am 3 Apr. 2018
0 Stimmen
In the deepDreamImageLaplacianNorm2.m you must not comment the gradient ascend % X = X + gradient * stepSize; X=max(XMin2,min(X,XMax2));
=> should be (mind the % removal) X = X + gradient * stepSize; X=max(XMin2,min(X,XMax2));
Selva Karna
am 3 Apr. 2018
0 Stimmen
Delprat Sebastien
am 3 Apr. 2018
0 Stimmen
Unfortunately, due to Mathworks copyright, I cannot disclose the source code of their functions. If you follow the steps detailed in the patch. M files, this should be OK.
In your previous code, you did add a comment on the original line x = x + g*stepsize. Remove this comment and it should work.
voxey
am 4 Apr. 2018
0 Stimmen
check the image size
Kategorien
Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


