You Are Here:

Community: Developer Discussion Boards

#1 Old Wink OutOfMemory Exception???????? - 2009-04-08, 17:07

Join Date: Sep 2008
Posts: 24
akshaychaudhari
Offline
Registered User
hi,
i am doing project on image process. i am getting OutOfMemory Exception.
i reduced size of image from 84*106 to 40*60 and further down.
but it don't work. i have to process only 10 images.
please tell me solution how can i solve it?
Reply With Quote

#2 Old Re: OutOfMemory Exception???????? - 2009-04-08, 17:19

Join Date: Apr 2007
Posts: 1,757
Tiger79's Avatar
Tiger79
Offline
Forum Nokia Champion
on which device is this ?
Reply With Quote

#3 Old Re: OutOfMemory Exception???????? - 2009-04-08, 17:27

Join Date: Sep 2008
Posts: 24
akshaychaudhari
Offline
Registered User
first it occurs on emulator and then on n73
Reply With Quote

#4 Old Re: OutOfMemory Exception???????? - 2009-04-08, 18:21

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
If it's happening on the emulator, then you need to trace the exception, and find out where it is being thrown.
Reply With Quote

#5 Old Thumbs up Re: OutOfMemory Exception???????? - 2009-04-08, 18:29

Join Date: Sep 2008
Posts: 1,195
Location: DELHI
Send a message via Yahoo to jitu_goldie
jitu_goldie's Avatar
jitu_goldie
Offline
Forum Nokia Champion
mention the size of images and the procedure to initialize them. Post ur code here.


thanks,
jitu_goldie..

KEEP TRYING..
Reply With Quote

#6 Old Re: OutOfMemory Exception???????? - 2009-04-08, 19:16

Join Date: Sep 2008
Posts: 24
akshaychaudhari
Offline
Registered User
thanks....
image size is 84*106 and m using JAMA package for calculating
matrix operation

The line which are written in bold may cause problem
as i removed them its working properly....



/**
* image size 84*106
*/
public class Spl123 {

double[][] eigenFace(double[][] face_v){ //face_v is [10][84*106]

int length = 84*106;
int nrfaces = 10;
int i, j, col,rows, pix, image;
double temp = 0.0;
//double[][] faces = new double[nrfaces][length];
double[] avgF = new double[length];

/*
Compute average face of all of the faces.
*/
for ( pix = 0; pix < length; pix++) {
temp = 0;
for ( image = 0; image < nrfaces; image++) {
temp += face_v[image][pix];
}
avgF[pix] = temp / nrfaces;
}
/*
Compute difference.
*/
for ( pix = 0; pix < length; pix++){
for ( image = 0; image < nrfaces; image++) {
face_v[image][pix] = face_v[image][pix] - avgF[pix];
}
}
//System.arraycopy(face_v,0,faces,0,face_v.length);
Sample faceM = new Sample(face_v, nrfaces,length);
Sample faceM_transpose = faceM.transpose();
Sample covarM = faceM.times(faceM_transpose);

int a = covarM.getRowDimension();
int b = covarM.getColumnDimension();
// double[][] v = covarM.getArray();

System.out.println(a);
System.out.println(b);
// System.out.println(avgF[1]);
System.out.println(nrfaces);
/*
for(i = 0;i<a;i++)
{
for(j=0;j < b ; j++)
{
System.out.println(v[i][j]);
}
}
/*
Compute eigenvalues and eigenvector.
*/
EigenvalueDecomposition E = covarM.eig();

double[] eigValue = diag(E.getD().getArray());
double[][] eigVector = E.getV().getArray();
/*
* We only need the largest associated values of the eigenvalues.
* Thus we sort them (and keep an index of them)
*/
int[] index = new int[nrfaces];
double[][] tempVector = new double[nrfaces][nrfaces]; /* Temporary new eigVector */

for ( i = 0; i <nrfaces; i++) /* Enumerate all the entries */
index[i] = i;
doubleQuickSort(eigValue, index,0,nrfaces-1);

// Put the index in inverse
int[] tempV = new int[nrfaces];
for ( j = 0; j < nrfaces; j++)
tempV[nrfaces-1-j] = index[j];

index = tempV;

/*
* Put the sorted eigenvalues in the appropiate columns.
*/
for ( col = nrfaces-1; col >= 0; col --) {
for ( rows = 0; rows < nrfaces; rows++ ){
tempVector[rows][col] = eigVector[rows][index[col]];
}
}
eigVector = tempVector;
eigValue = null;
tempVector = null;
Sample eigVectorM = new Sample(eigVector, nrfaces,nrfaces);
eigVector = eigVectorM.times(faceM).getArray();


/* Normalize our eigen vector matrix. */

for ( image = 0; image < nrfaces; image++) {
temp = max(eigVector[image]); // Our max
for ( pix = 0; pix < eigVector[0].length; pix++)
// Normalize
eigVector[image][pix] = Math.abs( eigVector[image][pix] / temp);
}


return eigVector;
}
//*******************************************************
public void fisherFace(double[][] face_f) //face_v is [10][84*106]

{
int length = 84*106;
int nrfaces = 10;
int nusr = 5;
int i, j,k, m, pix, image,tp;
double temp = 0.0;
double[][] tmp = face_f;
double[][] meanUser = new double[2][84*106];
double[][] row1= new double[10][length];
double[] avgTot = new double[length];
double[][] row = new double[2][length];

/*
Compute average face of all of the faces.
*/
for ( pix = 0; pix < length; pix++) {
temp = 0;
for ( image = 0; image < nrfaces; image++) {
temp += tmp[image][pix];
}
avgTot[pix] = temp / nrfaces;
}
/*
Compute difference.
*/
for ( pix = 0; pix < length; pix++){
for ( image = 0; image < nrfaces; image++) {
tmp[image][pix] = tmp[image][pix] - avgTot[pix];
}
}

/*
* Calculate mean of one user
*/
//m=0;
for(k=0;k<2;k++)
{
if(k==0)
{
image= j =0;
tp = nusr;
}else
{
image = j = k*nusr;
tp = image + nusr;
}
for ( pix = 0; pix < length; pix++) {
temp = 0;
for (image = j; image < tp; image++) {
temp += face_f[image][pix];
}
meanUser[k][pix] = temp / nusr;
}
}
/*Calculate diff bet one user and avg */
for(k=0;k<2;k++)
{
for ( pix = 0; pix < length; pix++){
row[k][pix] = meanUser[k][pix] - avgTot[pix];
}
}
Sample faceM = new Sample(row);
Sample faceM_transpose = faceM.transpose();
double[][] Sb = (faceM_transpose.times(faceM)).getArray();
Sample Sbb = new Sample(Sb);

//Sb = Sbb.times(faceM).getArray();

/*
* Calculate (each of user image) - (avg of that user)
*/
m=0;
for(k=0;k<2;k++)
{
for(i=0;i<5;i++,m++)
{
for ( pix = 0; pix < length; pix++)
{
row1[m][pix] = face_f[m][pix] - meanUser[k][pix];
}
}
}

faceM = new Sample(row1);
faceM_transpose = faceM.transpose();
// Sample Sw = faceM.times(faceM_transpose);

double[][] Sw = (faceM_transpose.times(faceM)).getArray();
Sample Sww = new Sample(Sw);
//Sw = Sww.times(faceM).getArray();
/*
* Calculation of face space
*/
meanUser = null;
row = row1 = null;
avgTot = null;
// length = nusr = null;

tmp = eigenFace(face_f);

Sbb = new Sample(Sb);
Sample tr = new Sample(tmp);
Sample tr1 = tr.times(Sbb);
tr = tr.transpose();
Sbb = tr1.times(tr);

Sww = new Sample(Sw);
tr = new Sample(tmp);
tr1 = tr.times(Sww);
tr = tr.transpose();
Sww = tr1.times(tr);

}

//*****************************************************************
static double max(double[] a) {
double b = a[0];
for (int i = 0; i < a.length; i++)
if (a[i] > b) b = a[i];

return b;
}

static double[] diag(double[][] m) {

double[] d = new double[m.length];
for (int i = 0; i< m.length; i++)
d[i] = m[i][i];
return d;
}
/**
* Quick sort on a vector with an index.
*
* @param a the array of numbers. This will be modified and sorted
* ascendingly (smalles to highest)
* @param index the index of the numbers as related to original
* location.
* @param lo the index where to start from. Usually 0.
* @param hi the index where to stop. Usually a.length()
*/
static void doubleQuickSort(double a[], int index[], int lo0, int hi0) {
int lo = lo0;
int hi = hi0;
double mid;

if ( hi0 > lo0) {

/* Arbitrarily establishing partition element as the midpoint of
* the array.
*/
mid = a[ ( lo0 + hi0 ) / 2 ];
// loop through the array until indices cross
while( lo <= hi ) {

while( ( lo < hi0 ) && ( a[lo] < mid )) {
++lo;
}


while( ( hi > lo0 ) && ( a[hi] > mid )) {
--hi;
}

// if the indexes have not crossed, swap
if( lo <= hi ) {
swap(a, index, lo, hi);
++lo;
--hi;
}
}

if( lo0 < hi ) {
doubleQuickSort( a, index, lo0, hi );
}

if( lo < hi0 ) {
doubleQuickSort( a, index,lo, hi0 );
}
}
}
static private void swap(double a[], int[] index, int i, int j) {
double T;
T = a[i];
a[i] = a[j];
a[j] = T;
// Index
index[i] = i;
index[j] = j;
}


}
Last edited by akshaychaudhari : 2009-04-08 at 20:15.
Reply With Quote

#7 Old Re: OutOfMemory Exception???????? - 2009-04-08, 19:30

Join Date: Feb 2009
Posts: 37
manish88
Offline
Registered User
Assign null value to the objects and arrays which are not required this may help you KEEP TRYING
Reply With Quote

#8 Old Re: OutOfMemory Exception???????? - 2009-04-08, 19:33

Join Date: Sep 2008
Posts: 24
akshaychaudhari
Offline
Registered User
i tried it
its not working properly
Last edited by akshaychaudhari : 2009-04-08 at 19:40.
Reply With Quote

#9 Old Re: OutOfMemory Exception???????? - 2009-04-08, 20:12

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
That code looked expensive!

Remember that an array of doubles is eight bytes per element. So, (84 * 106 * 10) doubles at eight bytes each, comes to around 800k.

I recommend you consider a less memory-intensive algorithm.
Reply With Quote

#10 Old Re: OutOfMemory Exception???????? - 2009-04-08, 20:18

Join Date: Sep 2008
Posts: 24
akshaychaudhari
Offline
Registered User
thanks for replying....
i reduced size to 40*60 and no of images from 5 to 3 still it shows error
Reply With Quote

#11 Old Re: OutOfMemory Exception???????? - 2009-04-08, 22:12

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
I suggest you use the memory analyser in the Wireless Toolkit. Then you will see where the memory is being used.

The problem is simply that you are using too much memory.
Reply With Quote

#12 Old Re: OutOfMemory Exception???????? - 2009-04-09, 06:53

Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
Send a message via Skype™ to raj_J2ME
raj_J2ME's Avatar
raj_J2ME
Offline
Forum Nokia Champion
Hi,
You must check this with the memory monitor...as grahm suggest...
And after a while you keep on calling Garbage collector from the memory monitor...and you will come to know that exactly how much is the memory required...watch the graph carefully,
check the object by clicking the objects Tab..
Also make sure that you are not creating any arrays,images,or so in in a loop...A deep code review is recommended..


Thanks

R a j - The K e r n e l
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
s60 3rd ed emulator crash Kimau Symbian Tools & SDKs 2 2008-06-18 23:12
outOfMemory exception on device with 2mb memory gx Mobile Java General 6 2007-05-24 11:33
VS.Net 2003 Carbide 2.01 and epoc32.exe ValentinK Carbide.c++ IDE and plug-ins 2 2007-01-12 13:31
how to avoid OutofMemory Exception lakshmanraob Mobile Java Networking & Messaging & Security 2 2005-10-28 15:53
can not successfully link any sample using .NET lobotomat Symbian Tools & SDKs 2 2002-08-20 01:29

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia