-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Corey Adams
committed
Dec 11, 2020
1 parent
547f35a
commit 89d591a
Showing
21 changed files
with
619 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import larcv | ||
|
||
|
||
# This script is an example of what a larcv dataloader should look like. | ||
|
||
|
||
dl = larcv.dataloader() | ||
|
||
# Add several input streams. | ||
# Each input stream is from a file (or, maybe, set of files if distributed?) | ||
dl.add_input_stream(key="train", file="example_train_file.h5") | ||
dl.add_input_stream(key="test", file="example_test_file.h5") | ||
|
||
|
||
# Set target outputs for each stream. | ||
dl.add_output_stream( | ||
keys="all", # This is default, but can be configured | ||
input_format="image2d", # This needs to be a larcv3 dataformat | ||
input_label="sbndwire", # This is the larcv key under which this is stored. | ||
output_format="dense", # This can be "dense" for dense images, "sparse" for SCN, "graph" for torch_geometric | ||
framework = "numpy", # This can be "numpy", "torch", "tf"/"tensorflow" | ||
preload = True # If set, it will preload data to the GPU/accelerator | ||
) | ||
|
||
|
||
dl.configure() # Calling this will configure the C++ code and begin loading data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import sys,time,os,signal | ||
import numpy | ||
import larcv | ||
import random | ||
|
||
class dataloader(object) | ||
|
||
'''Dataloader for larcv3 | ||
This class manages the data loading from larcv, including preprocessing | ||
To configure this, you create the dataloader with a configuration dictionary like so: | ||
{ | ||
'train': { | ||
'data' : { | ||
'input_data' : 'sparse2d' | ||
'preprocess' : { | ||
'Downsample' : .... | ||
} | ||
} | ||
} | ||
} | ||
''' | ||
|
||
def __init__(self, verbose=False, random_access_mode="random_blocks", seed=None): | ||
'''init function | ||
Not much to store here, just a dict of dataloaders and the keys to access their data. | ||
Queue loaders are manually triggered IO, not always running, so | ||
''' | ||
object.__init__(self) | ||
|
||
# Hold a config for each process stream (for example, "train" or "test") | ||
self.config = {} | ||
self._queue_processor = {} | ||
self._batch_holder = {} | ||
|
||
|
||
def add_data_stream(self, configure): | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
add_subdirectory(filter) | ||
add_subdirectory(queueio) | ||
add_subdirectory(imagemod) | ||
# add_subdirectory(imagemod) | ||
# add_subdirectory(sbnd_imagemod) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#ifndef __LARCV3THREADIO_BATCHFILLERPARTICLE_CXX__ | ||
#define __LARCV3THREADIO_BATCHFILLERPARTICLE_CXX__ | ||
|
||
#include "BatchFillerParticle.h" | ||
#include <random> | ||
|
||
namespace larcv3 { | ||
|
||
static BatchFillerParticleProcessFactory __global_BatchFillerParticleProcessFactory__; | ||
|
||
BatchFillerParticle::BatchFillerParticle(const std::string name) | ||
: BatchFillerTemplate<larcv3::Particle>(name) | ||
{} | ||
|
||
void BatchFillerParticle::configure(const json& cfg){ | ||
config = this -> default_config(); | ||
config = augment_default_config(config, cfg); | ||
} | ||
|
||
void BatchFillerParticle::initialize(){} | ||
|
||
bool BatchFillerParticle::process(IOManager& mgr){ | ||
|
||
std::string producer = config["ParticleProducer"].get<std::string>(); | ||
// Fetch the particles: | ||
auto const& event_part = mgr.get_data<larcv3::EventParticle>(producer); | ||
|
||
// Refresh the dimension: | ||
std::vector<int> dim(2); | ||
dim[0] = batch_size(); | ||
dim[1] = event_part.size(); | ||
set_dim(dim); | ||
|
||
|
||
// labels | ||
auto const& part_v = event_part.as_vector(); | ||
if (part_v.size() != 1) { | ||
LARCV_CRITICAL() << "Only support single particle label now: EventParticle size != 1" << std::endl; | ||
throw larbys(); | ||
} | ||
// class | ||
size_t label = kINVALID_SIZE; | ||
int pdg = 0; | ||
|
||
_entry_data.resize(1); | ||
_entry_data.at(0) = part_v.front(); | ||
|
||
|
||
set_entry_data(_entry_data); | ||
|
||
return true; | ||
|
||
|
||
} | ||
|
||
void BatchFillerParticle::_batch_begin_(){ | ||
if (!batch_data().dim().empty() && (int)(batch_size()) != batch_data().dim().front()) { | ||
auto dim = batch_data().dim(); | ||
dim[0] = batch_size(); | ||
this->set_dim(dim); | ||
} | ||
|
||
} | ||
|
||
void BatchFillerParticle::_batch_end_(){} | ||
|
||
void BatchFillerParticle::finalize(){} | ||
|
||
} | ||
|
||
#endif |
Oops, something went wrong.