Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
350 changes: 289 additions & 61 deletions DLInterface_module.cc

Large diffs are not rendered by default.

40 changes: 36 additions & 4 deletions PyNet_SparseInfill.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ namespace ubdlintegration {

int PyNetSparseInfill::run_sparse_cropped_infill( const std::vector< std::vector<larcv::SparseImage> >& cropped_vv,
const int run, const int subrun, const int event,
const std::vector< std::vector<int> >& use_vv,
std::vector<std::vector<larcv::SparseImage> >& results_vv,
bool debug ) {

results_vv.clear();

bool runall = (use_vv.size()==0 ) ? true : false;

// for each plane:
// make a vector of bsons
Expand All @@ -77,24 +80,50 @@ namespace ubdlintegration {

auto const& cropped_v = cropped_vv.at(planeid);

// first
int nimages = 0;
if ( runall ) {
nimages = (int)cropped_v.size();
}
else {
for ( auto const& use : use_vv[planeid] ) {
if ( use==1 )
nimages++;
}
}

// create list to fill
PyObject* pList = PyList_New( (Py_ssize_t)cropped_v.size() );
PyObject* pList = PyList_New( (Py_ssize_t)nimages );

// fill list with bson objects
int nsent = 0;
for ( size_t idx=0; idx<cropped_v.size(); idx++ ) {

if ( !runall && use_vv.at(planeid).at(idx)==0 ) {
// do not use
continue;
}

const larcv::SparseImage& spimg = cropped_v.at(idx);
PyObject* bson = larcv::json::as_bson_pybytes( spimg, run, subrun, event, idx );
std::cout << " [" << idx << "] add cropped image into python list" << std::endl;

// set item for previously unitialized list
PyList_SET_ITEM(pList, (Py_ssize_t)idx, bson );
PyList_SET_ITEM(pList, (Py_ssize_t)nsent, bson );
nsent++;
// if ( status==-1 ) {
// throw std::runtime_error("[PyNetSparseInfill] trouble setting item for input bson list");
// }
}
std::cout << "[PyNetSparseInfill] filled bson list plane[" << planeid << "] size=" << PyList_Size(pList) << std::endl;

std::cout << "[PyNetSparseInfill] filled bson list plane[" << planeid << "] "
<< "size=" << PyList_Size(pList)
<< " of " << cropped_v.size() << " total"
<< " and " << nimages << " to send"
<< std::endl;
if ( nsent!=nimages ) {
throw std::runtime_error( "number of images sent is not the number expected" );
}

PyObject *pWeightpath = PyString_FromString( _weight_file_v.at( planeid ).c_str() );

std::cout << "[PyNetSparseInfill] call function: " << pFunc << " weight=" << PyString_AsString( pWeightpath ) << std::endl;
Expand All @@ -108,6 +137,9 @@ namespace ubdlintegration {
auto nout = PyList_Size(pReturn);

std::cout << "Number of masks returned from python: " << nout << std::endl;
if ( (int)nout!=nsent ) {
throw std::runtime_error("Number returned not the same as sent!");
}
std::vector<larcv::SparseImage> out_v;
for (int iout=0; iout<(int)nout; iout++ ) {
PyObject* sparseimg_bson = PyList_GetItem(pReturn,(Py_ssize_t)iout);
Expand Down
1 change: 1 addition & 0 deletions PyNet_SparseInfill.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace ubdlintegration {

int run_sparse_cropped_infill( const std::vector< std::vector<larcv::SparseImage> >& cropped_vv,
const int run, const int subrun, const int event,
const std::vector< std::vector<int> >& use_vv,
std::vector<std::vector<larcv::SparseImage> >& results_vv,
bool debug );

Expand Down
20 changes: 14 additions & 6 deletions PyNet_SparseSSNet.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ namespace ubdlintegration {
larcv::SetPyUtil();

std::cout << "[PyNetSparseSSNet] import script" << std::endl;
PyObject *pName = PyUnicode_FromString("Infill_ForwardPass");
PyObject *pName = PyUnicode_FromString("inference_sparse_ssnet");
pModule = PyImport_Import(pName);
if ( !pModule ) {
throw std::runtime_error("failed to import import module 'Infill_ForwardPass'");
throw std::runtime_error("failed to import import module 'inference_sparse_ssnet'");
}
else {
std::cout << "[PyNetSparseSSNet] loaded Infill_ForwardPass module" << std::endl;
std::cout << "[PyNetSparseSSNet] loaded inference_sparse_ssnet module" << std::endl;
}

pFunc = PyObject_GetAttrString(pModule,"forwardpass");
Expand Down Expand Up @@ -62,6 +62,7 @@ namespace ubdlintegration {

int PyNetSparseSSNet::run_sparse_ssnet( const std::vector< std::vector<larcv::SparseImage> >& cropped_vv,
const int run, const int subrun, const int event,
const int nrows, const int ncols,
std::vector<std::vector<larcv::SparseImage> >& results_vv,
bool debug ) {

Expand Down Expand Up @@ -97,13 +98,17 @@ namespace ubdlintegration {

PyObject *pWeightpath = PyString_FromString( _weight_file_v.at( planeid ).c_str() );
PyObject* pPlaneID = PyInt_FromLong( (long)planeid );
PyObject* pNROWS = PyInt_FromLong( (long)nrows );
PyObject* pNCOLS = PyInt_FromLong( (long)ncols );

std::cout << "[PyNetSparseSSNet] call function: " << pFunc << " weight=" << PyString_AsString( pWeightpath ) << std::endl;
PyObject *pReturn = PyObject_CallFunctionObjArgs(pFunc,pPlaneID,pList,pWeightpath,NULL);
std::cout << "[PyNetSparseSSNet] call function: " << pFunc
<< " weight=" << PyString_AsString( pWeightpath )
<< std::endl;
PyObject *pReturn = PyObject_CallFunctionObjArgs(pFunc,pPlaneID,pNROWS,pNCOLS,pList,pWeightpath,NULL);
std::cout << "python returned: " << pReturn << std::endl;

if (!PyList_Check(pReturn)) {
throw std::runtime_error("Return from pynet_deploy.inference_mrcnn.forwardpass was no a list");
throw std::runtime_error("Return from pynet_deploy.inference_sparse_ssnet.forwardpass was no a list");
}

auto nout = PyList_Size(pReturn);
Expand All @@ -125,6 +130,9 @@ namespace ubdlintegration {
std::cout << "dereference string arguments/paths" << std::endl;
Py_DECREF(pWeightpath);
Py_DECREF(pPlaneID);
Py_DECREF(pNROWS);
Py_DECREF(pNCOLS);
Py_DECREF(pPlaneID);
Py_DECREF(pReturn);
Py_DECREF(pList);

Expand Down
1 change: 1 addition & 0 deletions PyNet_SparseSSNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace ubdlintegration {

int run_sparse_ssnet( const std::vector< std::vector<larcv::SparseImage> >& cropped_vv,
const int run, const int subrun, const int event,
const int nrows, const int ncols,
std::vector<std::vector<larcv::SparseImage> >& results_vv,
bool debug );

Expand Down
84 changes: 63 additions & 21 deletions dl_driver.fcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,65 @@ BEGIN_PROLOG

DLInterface: {
module_type: "DLInterface"
Verbosity: 0
WireProducerName: "butcher"
OutputProducerName: "ssnet"
PixelThresholdsForSavedScoresPerPlane: [5.0,5.0,5.0]
#NetInterface: "DummyServer"
#NetInterface: "PyTorchCPU"
NetInterface: "Server"
larliteOutputFile: "larlite_larflow.root"

SuperaConfigFile: "supera_ssnetinterface.fcl"
PyTorchNetScript: ["/uboone/app/users/tmw/dl_model_files/ubssnet/mcc8_caffe_ubssnet_plane0.pytorchscript",
"/uboone/app/users/tmw/dl_model_files/ubssnet/mcc8_caffe_ubssnet_plane1.pytorchscript",
"/uboone/app/users/tmw/dl_model_files/ubssnet/mcc8_caffe_ubssnet_plane2.pytorchscript"]
CroppingMethod: "FlashCROI"
PixelThresholdsForSavedScoresPerPlane: [10.0,10.0,10.0]
DoWholeImageCrop: true
DoFlashROICrop: true
OpFlashProducerName: "simpleFlashBeam"
SSNetCropMethod: "FlashCROI"
UBCropConfig: "ubcrop.fcl"
SaveDetsplitImagesInput: false
SaveNetOutSplitImagesOutput: false

SSNetMode: "DoNotRun"
LArFlowMode: "DoNotRun"
InfillMode: "PyTorchCPU"
CosmicMRCNNMode: "PyTorchCPU"
SparseSSNetMode: "PyTorchCPU"

ServerConfiguration: {
UseSSHtunnel: false
SSHAddress: ""
SSHUsername: "twongj01"
BrokerAddress: "tcp://nudot.lns.mit.edu"
BrokerPort: "6000"
BrokerAddress: "tcp://nudot.lns.mit.edu"
BrokerPort: "6000"
RequestTimeoutSecs: 300
RequestMaxTries: 3
MaxBrokerReconnects: 3
}

MCC8SSNetScript: ["mcc8_caffe_ubssnet_plane0.pytorchscript",
"mcc8_caffe_ubssnet_plane1.pytorchscript",
"mcc8_caffe_ubssnet_plane2.pytorchscript"]

CosmicMRCNN_WeightFiles: ["mcc8_mrcnn_plane0_weightsonly.pt",
"mcc8_mrcnn_plane1_weightsonly.pt",
"mcc8_mrcnn_plane2_weightsonly.pt"]

CosmicMRCNN_ConfigFiles: ["mills_config_0.yaml",
"mills_config_1.yaml",
"mills_config_2.yaml"]

SparseInfill_WeightFiles: ["sparseinfill_uplane_test.tar",
"sparseinfill_vplane_test.tar",
"sparseinfill_yplane_test.tar"]
SparseInfillOnlyCROI: true
InfillCropConfig: "infill_split.fcl"

SparseSSNet_WeightFiles: ["sparse_uresnet_plane0_16filter_6layers_22999.ckpt",
"sparse_uresnet_plane1_16filter_6layers_31999.ckpt",
"sparse_uresnet_plane2_16filter_6layers_36999.ckpt"]


}

UBDLIntegration: @local::DLInterface

END_PROLOG

process_name: SSNet
process_name: DLDeploy

services:
{
Expand All @@ -42,7 +73,8 @@ services:
MemoryTracker: @local::microboone_memory_tracker
#message: @local::microboone_message_services_prod_debug
#FileCatalogMetadata: @local::art_file_catalog_mc
@table::microboone_services
#@table::microboone_services
@table::microboone_services_reco
TFileService: { fileName: "mc_hist.root" }
}

Expand All @@ -56,6 +88,8 @@ services.DetectorClocksService.InheritClockConfig: false
services.DetectorClocksService.TriggerOffsetTPC: -0.400e3
services.SpaceCharge.EnableSimSpatialSCE: true
services.SpaceCharge.EnableSimEfieldSCE: true
services.LLMetaMaker: {Enable: false}
services.LArCVMetaMaker: {Enable: false}

#services.FileCatalogMetadata.applicationVersion: "develop"
#services.FileCatalogMetadata.fileType: "mc"
Expand Down Expand Up @@ -88,26 +122,34 @@ physics:
{
producers: {
@table::dlprod_producers
ssnet: @local::UBDLIntegration
ubdl: @local::UBDLIntegration
}

filters: {}

analyzers: {}
analyzers: {
@table::dlprod_analyzers
}

ssnetpath: [ssnet]
stream: [out1]
dlnetpath: [ubdl]
stream: [opreco, reco2d, out1]
end_paths: [stream]
trigger_paths: [ ssnetpath ]
trigger_paths: [ dlnetpath ]
}

# configure larlite
# DATA
#physics.analyzers.opreco.trigger: ["daq"]
# MC
physics.analyzers.opreco.trigger: ["triggersim"]

outputs:
{
out1:
{
module_type: RootOutput
fileName: "out_larsoft.root" #default file name, can override from command line with -o or --output
dataTier: "larlite"
dataTier: "larcv"
compressionLevel: 1
}
}
Expand Down
Loading