IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MATLAB Discussion :

[Out of Memory] Problème


Sujet :

MATLAB

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    50
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 50
    Par défaut [Out of Memory] Problème
    Bonjour,

    J'utilise un code qui doit me permettre de réaliser de l'interpolation 3D de données correspondantes à des déformations dans un volume. Le problème est que l'exécution rame à fond et que le programme bug avec l'erreur suivante apparaissant :

    ??? Out of memory. Type HELP MEMORY for your options.

    Error in ==> repmat at 62
    B = A(:, ones(siz(2), 1));

    Error in ==> splncore at 97
    offset = repmat(reshape(sub2ind(sizeg,ind{:}),4^d,1),1,n);

    Error in ==> interp3>spline3 at 670
    F = splncore(varargin([2 1 3]),varargin{4},varargin([6 5 7]));

    Error in ==> interp3 at 226
    vi = spline3(x,y,z,v,xi,yi,zi,ExtrapVal);

    Error in ==> Correction_TRS_SAG at 73
    dxn=interp3(xgrid,ygrid,zgrid,dxg,xinterp,yinterp,zinterp,'spline',0);


    J'ai bien regardé les commandes save et clear et essayé de les appliquer mais rien à faire... Je vous laisse ci-dessous le code de mon programme, le fichier Correction_TRS_SAG.m :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
     clear all;
    close all;
     
    % Reconstruction 3D du volume de coupes axiales 
     
    name1='MR.1.2.392.200036.9123.100.12.11.14250.20070612134013.90.'; 
    name3='.dcm';
    name=strcat(name1,int2str(16),name3);
    Imainfo=dicominfo(name);
    x0=Imainfo.ImagePositionPatient(1);
    y0=Imainfo.ImagePositionPatient(2);
    z0=Imainfo.ImagePositionPatient(3);
    op=Imainfo.ImageOrientationPatient;
    dimpix=Imainfo.PixelSpacing;
     
    volume = zeros(256,256,31);
     
    for cpt=16:46
     
        name=strcat(name1,int2str(cpt),name3);
        Imainfo=dicominfo(name);
        Ima = dicomread(Imainfo);
        volume(:,:,cpt-15)=Ima;
     
    end
     
    % Interpolation de la déformation
     
    for i=1:256
        xn(i)=x0+(i-1)*dimpix(1)*op(1)+(i-1)*dimpix(2)*op(4);        % Récupération coord3D coupe coronale pour chaque pixel   
        yn(i)=y0+(i-1)*dimpix(1)*op(2)+(i-1)*dimpix(2)*op(5);
    end
     
    for i=1:31
        zn(i)=z0+5*(i-1);
    end
    [xng,yng,zng] = meshgrid(xn,yn,zn);
    xnr=reshape(xng,length(xng(: )),1);
    ynr=reshape(yng,length(yng(: )),1);
    znr=reshape(zng,length(zng(: )),1);
    Pinterpr=[xnr ynr znr];
     
     
    load Correction3D;  % Chargement des données R2,q2,xgrille,ygrille,zgrille,dxg,dyg,dzg
     
    Pinterpb=Pinterpr';
    Q=zeros(size(Pinterpb));
        for i=1:size(Pinterpb,2)          %Calcul des points recalés                
            Q(:,i)=R2*Pinterpb(:,i)+q2(5:7);
        end
    Q=Q';
     
    xinterp=reshape(Q(:,1),256,256,31);
    yinterp=reshape(Q(:,2),256,256,31);
    zinterp=reshape(Q(:,3),256,256,31);
     
    dxn=interp3(xgrid,ygrid,zgrid,dxg,xinterp,yinterp,zinterp,'spline',0);
    dyn=interp3(xgrid,ygrid,zgrid,dyg,xinterp,yinterp,zinterp,'spline',0);
    dzn=interp3(xgrid,ygrid,zgrid,dzg,xinterp,yinterp,zinterp,'spline',0);
     
    xnd=xinterp+dxn;                                % Obtention des coord3D correspondantes dans image déformée
    ynd=yinterp+dyn;
    znd=zinterp+dzn;
     
    volume2=double(volume);
    Imac=interp3(xinterp,yinterp,zinterp,volume2,xnd(:,:,1),ynd(:,:,1),znd(:,:,1),'cubic');           % Obtention de l'intensité aux coord3D de la nouvelle image par interpolation sur image déformée
     
    figure (1)
    imshow(Imac,[],'notruesize');

    Merci de votre aide !

  2. #2
    Rédacteur/Modérateur

    Avatar de Jerome Briot
    Homme Profil pro
    Freelance mécatronique - Conseil, conception et formation
    Inscrit en
    Novembre 2006
    Messages
    20 317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance mécatronique - Conseil, conception et formation

    Informations forums :
    Inscription : Novembre 2006
    Messages : 20 317

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    50
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 50
    Par défaut
    Merci pour le lien je l'avais déjà lu, mais j'ai besoin de toutes mes variables actuellement utilisées, donc je ne peux pas les écraser... et je ne vois pas trop comment optimiser le code, donc si cela se résume à la puissance de l'ordi c'est vraiment limitant.

    Merci de votre aide

  4. #4
    Expert confirmé
    Avatar de Caro-Line
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    9 458
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 9 458
    Par défaut
    Tu dois bien pouvoir faire un peu de ménage, il y a des variables qui ne sont pas utilisées par la suite.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
     
    clear all;
    close all;
     
    % Reconstruction 3D du volume de coupes axiales 
     
    name1='MR.1.2.392.200036.9123.100.12.11.14250.20070612134013.90.'; 
    name3='.dcm';
    name=strcat(name1,int2str(16),name3);
    Imainfo=dicominfo(name);
    x0=Imainfo.ImagePositionPatient(1);
    y0=Imainfo.ImagePositionPatient(2);
    z0=Imainfo.ImagePositionPatient(3);
    op=Imainfo.ImageOrientationPatient;
    dimpix=Imainfo.PixelSpacing;
     
    volume = zeros(256,256,31);
     
    for cpt=16:46
     
        name=strcat(name1,int2str(cpt),name3);
        Imainfo=dicominfo(name);
        Ima = dicomread(Imainfo);
        volume(:,:,cpt-15)=Ima;
     
    end
     
    %Suppression des varibales non utilisées :
    clear Imainfo, Ima,name,name1,name3
     
    % Interpolation de la déformation
     
    for i=1:256
        xn(i)=x0+(i-1)*dimpix(1)*op(1)+(i-1)*dimpix(2)*op(4);        % Récupération coord3D coupe coronale pour chaque pixel   
        yn(i)=y0+(i-1)*dimpix(1)*op(2)+(i-1)*dimpix(2)*op(5);
    end
     
    for i=1:31
        zn(i)=z0+5*(i-1);
    end
     
    clear x0,y0,z,dimpix,op
     
    [xng,yng,zng] = meshgrid(xn,yn,zn);
     
    clear xn,yn,zn
     
    %etc...
    Après je ne dis pas que c'est ça qui va tout résoudre mais ça peut faire avancer.

    En particulier après tes reshape, effacer tes matrice Q et Pinterb qui je suppose sont assez grandes

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    50
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 50
    Par défaut
    Bonjour,

    J'ai effectué des opérations clear dans mon code et supprimé dans mes matrices 3D les NaN afin que l'interpolation 3D ne plante pas, mais le programme est très long et il plante au bout de 30-50 sec avec le message d'erreur suivant :

    ??? Error using ==> horzcat
    Out of memory. Type HELP MEMORY for your options.

    Error in ==> pwch at 36
    pc = mkpp(x,[reshape((dzdxdx-dzzdx)./dxd,dnm1,1) ...

    Error in ==> spline at 96
    pp = pwch(x,y,s,dx,divdif); pp.dim = sizey;

    Error in ==> splncore>splint at 121
    [ignored,coefs,l,k,d] = unmkpp(spline(x,y));

    Error in ==> splncore at 62
    values = splint(x{i},reshape(values,prod(nv(1:d-1)),nv(d))).';

    Error in ==> interp3>spline3 at 670
    F = splncore(varargin([2 1 3]),varargin{4},varargin([6 5 7]));

    Error in ==> interp3 at 218
    vi = spline3(x,y,z,v,xi,yi,zi);

    Error in ==> Correction_TRS_SAG at 119
    Imac=interp3(xinterp,yinterp,zinterp,volume,xnd(:,:,1),ynd(:,:,1),znd(:,:,1),'cubic'); % Obtention de l'intensité aux coord3D de la nouvelle image par interpolation sur image déformée
    Voici le code que j'ai optimisé, mais toujours sans succès :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    clear all;
    close all;
     
    % Reconstruction 3D du volume de coupes axiales 
     
    name1='MR.1.2.392.200036.9123.100.12.11.14250.20070612134013.90.'; 
    name3='.dcm';
    name=strcat(name1,int2str(16),name3);
    Imainfo=dicominfo(name);
    x0=Imainfo.ImagePositionPatient(1);
    y0=Imainfo.ImagePositionPatient(2);
    z0=Imainfo.ImagePositionPatient(3);
    op=Imainfo.ImageOrientationPatient;
    dimpix=Imainfo.PixelSpacing;
     
    volume = zeros(256,256,31);
     
    for cpt=16:46
     
        name=strcat(name1,int2str(cpt),name3);
        Imainfo=dicominfo(name);
        Ima = dicomread(Imainfo);
        volume(:,:,cpt-15)=Ima;
     
    end
     
    %Suppression des varibales non utilisées :
     
    clear Imainfo Ima name name1 name3;
     
    % Interpolation de la déformation
     
    for i=1:256
        xn(i)=x0+(i-1)*dimpix(1)*op(1)+(i-1)*dimpix(2)*op(4);        % Récupération coord3D coupe coronale pour chaque pixel   
        yn(i)=y0+(i-1)*dimpix(1)*op(2)+(i-1)*dimpix(2)*op(5);
    end
     
    for i=1:31
        zn(i)=z0+5*(i-1);
    end
     
    clear x0 y0 z0 dimpix op;
     
    [xng,yng,zng] = meshgrid(xn,yn,zn);
     
    clear xn yn zn;
     
    xnr=reshape(xng,length(xng(:)),1);
    ynr=reshape(yng,length(yng(:)),1);
    znr=reshape(zng,length(zng(:)),1);
    Pinterpr=[xnr ynr znr];
     
    load Correction3D;
     
    Pinterpb=Pinterpr';
     
    clear Pinterpr;
     
    Q=zeros(size(Pinterpb));
        for i=1:size(Pinterpb,2)          %Calcul des points recalés                
            Q(:,i)=R2*Pinterpb(:,i)+q2(5:7);
        end
    Q=Q';
     
    clear Pinterpb;
    clear R2 q2;
     
    xinterp=reshape(Q(:,1),256,256,31);
    yinterp=reshape(Q(:,2),256,256,31);
    zinterp=reshape(Q(:,3),256,256,31);
     
    clear Q;
     
    dxn=interp3(xgrid,ygrid,zgrid,dxg,xinterp,yinterp,zinterp);
    dyn=interp3(xgrid,ygrid,zgrid,dyg,xinterp,yinterp,zinterp);
    dzn=interp3(xgrid,ygrid,zgrid,dzg,xinterp,yinterp,zinterp);
     
    clear xgrid ygrid zgrid;
    clear dxg dyg dzg;
     
    [i,j,k]=find(dxn==NaN);
    dxn(i,j,k)=0;
    [i,j,k]=find(dyn==NaN);
    dyn(i,j,k)=0;
    [i,j,k]=find(dzn==NaN);
    dzn(i,j,k)=0;
    clear i j k;
     
    xnd=xinterp+dxn;                                % Obtention des coord3D correspondantes dans image déformée
    ynd=yinterp+dyn;
    znd=zinterp+dzn;
     
    clear dxn dyn dzn;
     
    % volume2=double(volume);
    Imac=interp3(xinterp,yinterp,zinterp,volume,xnd(:,:,1),ynd(:,:,1),znd(:,:,1),'cubic');           % Obtention de l'intensité aux coord3D de la nouvelle image par interpolation sur image déformée
     
    figure (9)
    imshow(Imac,[],'notruesize');

  6. #6
    Rédacteur/Modérateur

    Avatar de Jerome Briot
    Homme Profil pro
    Freelance mécatronique - Conseil, conception et formation
    Inscrit en
    Novembre 2006
    Messages
    20 317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance mécatronique - Conseil, conception et formation

    Informations forums :
    Inscription : Novembre 2006
    Messages : 20 317
    Par défaut
    A mon avis, il est peu problable d'éviter l'erreur "Out of memory" dans ton code. Tu touches aux limites de la gestion de mémoire par Matlab sur ta machine.

    Sinon :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    [xng,yng,zng] = meshgrid(xn,yn,zn);
     
    clear xn yn zn;
     
    xnr=reshape(xng,length(xng(:)),1);
    ynr=reshape(yng,length(yng(:)),1);
    znr=reshape(zng,length(zng(:)),1);
    Pinterpr=[xnr ynr znr];
     
    load Correction3D;
     
    Pinterpb=Pinterpr';
     
    clear Pinterpr;
    devient :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    [xng,yng,zng] = meshgrid(xn,yn,zn);
     
    clear xn yn zn;
     
    Pinterpb=[xng(:) yng(:) zng(:)].';
     
    load Correction3D;
    Ton code est truffé de variables intermédiaires inutiles... Q par exemple ne sert à rien. Tu peux écraser directement les valeurs de Pinterpb

    Mais je répète, pour le problème de mémoire, sous Windows à part arrêter des process inutiles, redémarrer en mode sans échec et autres (comme expliqué dans la )... je ne vois pas de solution rapide.

    Peux-tu mettre un WHOS juste avant la ligne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Imac=interp3(xinterp,yinterp,zinterp,volume,...
    et nous montrer ce que Matlab renvoie dans le command window

  7. #7
    Membre Expert
    Avatar de tug83
    Homme Profil pro
    MATLAB Geek !
    Inscrit en
    Juin 2006
    Messages
    1 781
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Alpes de Haute Provence (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : MATLAB Geek !
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2006
    Messages : 1 781
    Par défaut
    C'est quoi la taille de tes variables avant l'OOM? parce qu'il se peut que tu n'a plus de bloc contigu pour stocker tes variables...fais un
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    system_dependent_memstats
    la ligne juste avant que ça plante pour vérifier

Discussions similaires

  1. Problème 'out of memory'
    Par joyeux_lapin13 dans le forum SAS Base
    Réponses: 15
    Dernier message: 31/05/2014, 14h38
  2. Gros problème "out of memory" sur un site web
    Par petton dans le forum Développement Web avec .NET
    Réponses: 4
    Dernier message: 18/05/2011, 18h41
  3. [Liferay] Profiler pour problème de Out Of Memory
    Par Samaël63 dans le forum Portails
    Réponses: 0
    Dernier message: 22/06/2009, 12h06
  4. Problème de out of memory
    Par dodobn dans le forum Environnement de Développement Intégré (EDI)
    Réponses: 2
    Dernier message: 08/06/2009, 01h13
  5. J'ai tjrs le problème de Out of Memory
    Par Socrat dans le forum C++Builder
    Réponses: 24
    Dernier message: 22/07/2007, 10h27

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo