Skip to content

Commit

Permalink
ENH: Reduce memory.
Browse files Browse the repository at this point in the history
  • Loading branch information
ntustison committed Sep 26, 2024
1 parent 991588c commit 94d1349
Showing 1 changed file with 23 additions and 31 deletions.
54 changes: 23 additions & 31 deletions R/deepAtropos.R
Original file line number Diff line number Diff line change
Expand Up @@ -333,44 +333,36 @@ deepAtropos <- function( t1, doPreprocessing = TRUE, useSpatialPriors = 1,
message( "Prediction.\n" )
}

batchX <- array( data = 0, dim = c( 8, patchSize, channelSize ) )
predictedData <- array( data = 0, dim = c( 8, patchSize, numberOfClassificationLabels ) )

batchX <- array( data = 0, dim = c( 1, patchSize, channelSize ) )

imagePatchesList <- list()
for( i in seq.int( length( preprocessedImages ) ) )
for( h in seq.int( 8 ) )
{
imagePatches <- extractImagePatches( preprocessedImages[[i]],
patchSize = patchSize,
maxNumberOfPatches = "all",
strideLength = strideLength,
returnAsArray = TRUE )
imagePatchesList[[i]] <- imagePatches
}
for( i in seq.int( length( preprocessedImages ) ) )
{
for( j in seq.int( 8 ) )
index <- 1
for( i in seq.int( length( preprocessedImages ) ) )
{
batchX[j,,,,i] <- imagePatchesList[[i]][j,,,]
patches <- extractImagePatches( preprocessedImages[[i]],
patchSize = patchSize,
maxNumberOfPatches = "all",
strideLength = strideLength,
returnAsArray = TRUE )
batchX[1,,,,index] <- patches[h,,,]
index <- index + 1
}
}

priorsPatchesList <- list()
for( i in seq.int( length( hcpTemplatePriors ) ) )
{
priorPatches <- extractImagePatches( hcpTemplatePriors[[i]],
patchSize = patchSize,
maxNumberOfPatches = "all",
strideLength = strideLength,
returnAsArray = TRUE )
priorsPatchesList[[i]] <- priorPatches
}
for( i in seq.int( length( hcpTemplatePriors ) ) )
{
for( j in seq.int( 8 ) )
for( i in seq.int( length( hcpTemplatePriors ) ) )
{
batchX[j,,,,length( preprocessedImages ) + i] <- priorsPatchesList[[i]][j,,,]
patches <- extractImagePatches( hcpTemplatePriors[[i]],
patchSize = patchSize,
maxNumberOfPatches = "all",
strideLength = strideLength,
returnAsArray = TRUE )
batchX[1,,,,index] <- patches[h,,,]
index <- index + 1
}

predictedData[h,,,,] <- unetModel %>% predict( batchX, verbose = verbose )
}
predictedData <- unetModel %>% predict( batchX, verbose = verbose )

probabilityImages <- list()
for( i in seq.int( dim( predictedData )[5] ) )
Expand Down

0 comments on commit 94d1349

Please sign in to comment.