Commit 21b4452c authored by ac_22's avatar ac_22

updated gofulleval

parent 5ceba91f
function res=ctcEval(wrangleFolder,dsName)
path(path,'C:\Users\ac\Documents\git\leverApps\ctc\importExport');
outfolder='f:\ctcEval';
gtPath='R:\Images\ctc2018\training\2d\';
gtPath='X:\gRaw\ctc2020\';
evalFolder='f:\ctcEval';
targetFolder='F:\autowrangler\awHeLa_01';
flist=dir(fullfile(targetFolder,'*.LEVER'));
thisFile=mfilename('fullpath');
[thisFolder,~,~]=fileparts(thisFile);
path(path,fullfile(thisFolder,'..','ctc\importExport'));
outfolder=fullfile(wrangleFolder,'eval');
flist=dir(fullfile(wrangleFolder,dsName,'*.LEVER'));
% results file
strResults=fullfile(evalFolder,[dsName '_res.txt']);
if exist(strResults,'file')
res=readtable(strResults,'delimiter',',');
else
res=[];
end
res=[];
for ff=1:length(flist)
fname=flist(ff).name;
fname=strrep(fname,'_training','');
tokens=regexp(flist(ff).name,'(.+)_(\d+)_(\d+).LEVER','tokens');
tokens=regexp(fname,'(.*)_(\d\d)_','tokens');
dsName=tokens{1}{1};
dsID=tokens{1}{2};
paramID=tokens{1}{3};
[~,targetName,~]=fileparts(flist(ff).name);
importExport(fullfile(flist(ff).folder,flist(ff).name),outfolder, [])
% copy over the ground truth
copyfile(fullfile(gtPath,dsName,[dsID '_GT\']),fullfile(outfolder,targetName,[dsID '_GT']));
gtSource=fullfile(gtPath,['2d_' dsName '_training'],dsName,[dsID '_GT\']);
if ~exist(gtSource,'dir')
gtSource=fullfile(gtPath,['3d_' dsName '_training'],dsName,[dsID '_GT\']);
end
if ~exist(gtSource,'dir')
fprintf(2,'ground truth not found, skipping : %s\n',gtSource);
continue;
end
copyfile(gtSource,fullfile(outfolder,targetName,[dsID '_GT']),'f');
exePath=fullfile(outfolder,'EvaluationSoftware/Win');
exePath=fullfile(evalFolder,'EvaluationSoftware/Win');
system([fullfile(exePath,'TRAMeasure.exe') ' ' ...
fullfile(outfolder,targetName) ' ' dsID ' > score.txt']);
......@@ -37,8 +57,20 @@ for ff=1:length(flist)
sx=cellfun(@str2double,sx);
if length(sx)<3 , sx(3)=0; end
fprintf(1,'TRAmeasure:%f, SEGmeasure:%f, DETmeasure:%f\n',sx(1),sx(2),sx(3));
pid=str2double(paramID)
res=[res;pid,sx];
end
pid=ff; %str2double(paramID)
% get the algorithm settings
[conn,CONSTANTS]=openDB(fullfile(flist(ff).folder,flist(ff).name));
segParams=Read.getSegmentationParams(conn);
if isempty(res)
res=table(sx,{jsonencode(segParams)},'VariableNames',{'TRA_SEG_DET','segParams'});
else
res=[res;sx,{jsonencode(segParams)}];
end
close(conn);
end
writetable(res,strResults);
ROOT='g:\leverjs\ctc2020\2d';
DS='Fluo-N2DL-HeLa_training_01';
EXT='_param_1';
DEST='f:\autowrangler';
if ~exist(DEST,'dir')
mkdir(DEST);
DEST='f:\autowrangler2';
strDB='g:\leverjs\ctc2020\2d\Fluo-N2DL-HeLa_training_01.LEVER';
[~,dsName,~]=fileparts(strDB);
outfolder=fullfile(DEST,dsName);
if exist(outfolder,'dir')
rmdir(outfolder,'s');
end
strDB=fullfile(ROOT,[DS '.LEVER']);
strTarget=fullfile(DEST,[DS EXT '.LEVER']);
if exist(strTarget,'file')
delete(strTarget);
if ~exist(outfolder,'dir')
mkdir(outfolder);
end
copyfile(strDB,strTarget);
eraseAll=getLeverjsPath('eraseAll.js');
system(['node ' eraseAll ' ' strTarget]);
conn=database(strTarget, '','', 'org.sqlite.JDBC', 'jdbc:sqlite:');
conn=database(strDB, '','', 'org.sqlite.JDBC', 'jdbc:sqlite:');
segParams=Read.getSegmentationParams(conn);
segParams.alpha=[0.9,0.1];
Write.setSegParams(conn,segParams);
close(conn);
hTarget=[0.001,0.005,0.01,0.05,0.1];
spWrangle=[];
for h=1:length(hTarget)
sp=segParams;
sp.alpha(1)=0.6;
sp.NLM(1)=hTarget(h);
spWrangle=[spWrangle,sp];
buildWrangleFile(strDB,outfolder,[dsName '_param_' num2str(length(spWrangle))],sp);
end
% run it
Batch.batchSegment(strTarget,[],true);
Batch.batchSegmentFolder(outfolder,true);
% score it...
ctcEval(DEST,dsName)
\ No newline at end of file
ROOT='F:\leverjs\ctc2019_training\';
DS='Fluo-N2DL-HeLa_01';
strDB=fullfile(ROOT,[DS '.LEVER']);
%conn = database(strDB, '','', 'org.sqlite.JDBC', 'jdbc:sqlite:');
%CONSTANTS=Read.getConstants(conn);
segParams=Segment.getDefaultSegParams();
segParams.useCuda=true;
segParams.minimumRadius_um=[3.5,0.2,5];
segParams.denoise=true;
segParams.NLM=[0.065,6,5,false];
segParams.alpha=0.1;
strTarget=fullfile(ROOT,[DS '_param_X.LEVER']);
if exist(strTarget,'file')
delete(strTarget);
end
copyfile(strDB,strTarget);
conn=database(strTarget, '','', 'org.sqlite.JDBC', 'jdbc:sqlite:');
algorithm=[];
algorithm.name='optimization search';
algorithm.type='segment';
algorithm.params=segParams;
algorithm.function='+Segment.FrameSegment_texture.m';
algorithm.commandHost='matlab';
strAlg=jsonencode(algorithm);
exec(conn,'delete from tblAlgorithms where type="segment"');
cmd=['insert into tblAlgorithms (fqn,type,jsAlgorithmInfo) '...
' values("optimization search","segment", '' ' strAlg ' '')'];
exec(conn,cmd);
close(conn);
% run it
system(['node.exe C:\Users\ac\Documents\git\leverjs\leverjs\resegAndTrackDataset.js "' ...
strTarget '" resegAll 1 "{}" ' ]);
% score it
......@@ -6,7 +6,7 @@ if 0==rROI
return
end
q=fetch(conn,['select centroid from tblCells where trackID=' num2str(trackID)]);
q=ljsFetch(conn,['select centroid from tblCells where trackID=' num2str(trackID)]);
if isempty(q)
return;
end
......
% segEval
ROOT='F:\leverjs\ctc2019_training\';
DS='Fluo-N2DL-HeLa_01';
ROI=50;
strDB=fullfile(ROOT,[DS '.LEVER']);
conn = database(strDB, '','', 'org.sqlite.JDBC', 'jdbc:sqlite:');
CONSTANTS=Read.getConstants(conn);
aw_conn=AutoWrangler.awInit('f:\autowrangler',strDB);
errorList=[];
gtPath='R:\Images\ctc2018\training\2d\Fluo-N2DL-HeLa\01_GT\';
% get the segmentation ground truth
flist=dir(fullfile([gtPath 'SEG'],'*.tif'));
if ~exist('nProcessors','var') || isempty(nProcessors)
nProcessors=feature('numcores');
end
segParams=Segment.getDefaultSegParams();
segParams.useCuda=true;
segParams.denoise=true;
segParams.bCircular=true;
%
gtCells=[]; %Read.getCellsTime(conn,1);
% rcX=1.0e+03 * [1.3435 1.7491];
% rcY=1.0e+03 *[1.2487 1.7613];
%
% set up parameters
commandList=AutoWrangler.getParameters(aw_conn);
p=gcp('nocreate');
if isempty(p) || p.NumWorkers~=nProcessors
delete(p);
p=[];
end
if isempty(p)
p=parpool(nProcessors);
end
idxCommandList=0;
idxNext=1;
completedCells=cell(size(commandList(:,1)));
t=90
LGTtra=imread(fullfile(gtPath,['TRA/man_track' num2str(t,'%03d') '.tif']));
% idp is the number of steps
for idp=0:ceil(size(commandList,1)/p.NumWorkers)-1
nc=Composite();
spmd
if labindex+idxCommandList <size(commandList,1)
sp=segParams;
sp.minimumRadius_um=commandList{labindex+idxCommandList,'r'};
sp.NLM(1)=commandList{labindex+idxCommandList,'h'};
wr=commandList{labindex+idxCommandList,'nlm_wr'};
sp.NLM(2)=wr(1);
sp.NLM(3)=wr(2);
sp.NLM(4)=commandList{labindex+idxCommandList,'hpf'};
sp.alpha=commandList{labindex+idxCommandList,'alpha'};
sp.ensemble_minimumRadius_um=true;
nc=Segment.FrameSegment_texture('',t,CONSTANTS,sp);
else
nc=[];
end
end
for i=1:length(nc)
completedCells(idp*p.NumWorkers+i)=nc(i);
end
idxCommandList=idxCommandList+p.NumWorkers;
% once we complete a time slot, insert those segmentations and delete
% them from the table so we don't hog all the
idxCommandList=min(idxCommandList,size(commandList,1));
idxComplete=commandList{idxCommandList,'paramID'};
while idxNext<idxComplete
idxCommands=find(commandList{:,'paramID'}==idxNext);
if isempty(idxCommands)
idxNext=idxNext+1;
continue;
end
bEnsemble=length(idxCommands)>1;
% find all the segmentations at idxNext
rgRadius=commandList{idxCommands,'r'};
if bEnsemble
ensembleCells=completedCells(idxCommands);
[Cells,nestedCells]=Ensemble.processEnsemble(conn,1,CONSTANTS,ensembleCells,rgRadius,segParams);
else
Cells=[completedCells{idxCommands}];
end
imX=0*LGTtra;
for i=1:length(Cells)
if roiClip(Cells(i),ROI,size(imX))
continue
end
idx=sub2ind(size(imX),Cells(i).pts(:,2),Cells(i).pts(:,1));
imX(idx)=i;
end
sx=detectionScore(LGTtra,imX);
% put segmentation into DB
AutoWrangler.awAddSegmention(aw_conn,Cells,commandList(idxCommands(1),:),rgRadius,sx);
%remove cells from table (so we don't run out of memory...
for idel=1:length(idxCommands)
completedCells{idxCommands(idel)}=[];
end
idxNext=idxNext+1;
end
end
close(conn);
close(aw_conn);
\ No newline at end of file
function er=segScore(LGT,imX)
er=NaN;
[L]=bwlabeln(imX);
num=max(LGT(:));
erX=0;
nCells=0;
for n=1:num
idx=find(LGT==n);
if isempty(idx)
continue
end
idxLabels=unique(L(idx));
idxLabels(idxLabels==0)=[];
if isempty(idxLabels)
continue
end
if length(idxLabels)>1
nx=[];
for il=1:length(idxLabels)
nx(il)=length(find(L(idx)==idxLabels(il)));
end
[~,mmidx]=max(nx);
idxLabels=idxLabels(mmidx);
idx=find(L==idxLabels);
end
idxSeg=find(L==idxLabels);
er = 1-length(intersect(idxSeg,idx))/length(union(idxSeg,idx));
nCells=nCells+1;
erX=erX+er;
end
er=er/nCells;
% track the top X from aw file
strDB='F:\leverjs\ctc2019_training\Fluo-N2DL-HeLa_01.LEVER';
strAutoWrangleFolder='f:\autowrangler';
strCloneFolder='f:\autowrangler\awHeLa_01';
% strDB='f:\leverjs\Olivier\mcf10a_3D\20190301_7d_S00_wt.LEVER';
% strAutoWrangleFolder='f:\autowrangler';
% strCloneFolder='F:\autowrangler\awHeLa_01';
nFramesToTrack=[];
aw_conn = AutoWrangler.awInit(strAutoWrangleFolder,strDB);
% here we track a short section of each param list.
% set a command list
% commandList=AutoWrangler.getTrackEvalParameters();
% paramIDs=unique(commandList{:,'paramID'});
% for i=1:length(paramIDs)
% idx=find(commandList{:,'paramID'}==i);
% rgRadius=commandList{idx,'r'};
% AutoWrangler.awAddSegmention(aw_conn,[],commandList(idx(1),:),rgRadius,0);
% end
nClones=1;
cmd=['select paramID from awParamList order by score ASC limit ' num2str(nClones)];
q=fetch(aw_conn,cmd);
paramIDs=cell2mat(q);
for i=1:length(paramIDs)
AutoWrangler.makeTrackableClone(strDB,paramIDs(i),strAutoWrangleFolder, ...
strCloneFolder);
end
[imFolder,~,~]=fileparts(strDB)
strFolder=strrep(imFolder,'\','/');
cmd=['echo {"ROOT":"' strFolder '"} > ' fullfile(strCloneFolder,'lever.json')];
system(cmd);
% truncate constants
if ~isempty(nFramesToTrack)
flist=dir(fullfile(strCloneFolder,'*.LEVER'));
for ff=1:length(flist)
sx=fullfile(flist(ff).folder,flist(ff).name);
cx=database(sx, '','', 'org.sqlite.JDBC', 'jdbc:sqlite:');
CONSTANTS=Read.getConstants(cx);
CONSTANTS.imageData.NumberOfFrames=nFramesToTrack;
Write.updateConstants(cx,CONSTANTS);
close(cx);
end
end
Batch.batchSegmentFolder(strCloneFolder,false);
flist=dir(fullfile(strCloneFolder,'*.LEVER'));
for ff=1:length(flist)
applyROI(fullfile(flist(ff).folder,flist(ff).name),25);
end
Batch.batchSegmentFolder(strCloneFolder,true);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment