Skip to content

Commit

Permalink
Merge branch 'master' of lorenz.ecn.purdue.edu:PhenoSorg/object-locator
Browse files Browse the repository at this point in the history
Former-commit-id: 142c29d3a44b7b444bf0d799d4c76f7e69780d3c
  • Loading branch information
Javi Ribera committed Sep 21, 2018
2 parents c375d38 + 788a995 commit 78b1461
Show file tree
Hide file tree
Showing 12 changed files with 742 additions and 248 deletions.
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies:
- xmltodict=0.11.0
- pytorch=0.4.0
- pip:
- ballpark==1.4.0
- visdom==0.1.7
- peterpy
- torchvision==0.2.1
Expand Down
45 changes: 37 additions & 8 deletions object-locator/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,16 @@ def parse_command_args(training_or_testing):
metavar='F',
help='run validation after F epochs. '
'If 0, no validation will be done')
parser.add_argument('--env-name',
default='Pure U-Net',
parser.add_argument('--visdom-env',
default='default_environment',
type=str,
metavar='NAME',
help='name of the environment in Visdom')
parser.add_argument('--visdom-server',
default='http://localhost',
type=str,
metavar='SRV',
help='Hostname of the Visdom server')
parser.add_argument('--optimizer', '--optim',
default='sgd',
type=str.lower,
Expand Down Expand Up @@ -186,11 +191,19 @@ def parse_command_args(training_or_testing):
default='256x256',
metavar='HxW',
help='Size of the input images (heightxwidth).')
optional_args.add_argument('--radius',
type=int,
default=5,
metavar='R',
help='Detections at dist <= R to a GT pt are True Positives.')
optional_args.add_argument('--radii',
type=str,
default=range(0, 15 + 1),
metavar='Rs',
help='Detections at dist <= R to a GT pt are True Positives.'
'If not selected, R=0, ..., 15 will be tested.')
optional_args.add_argument('--taus',
type=str,
default=np.linspace(0, 1, 100).tolist() + [-1],
metavar='Ts',
help='Detection threshold. '
'If not selected, 100 thresholds in [0, 1] will be tested. '
'tau=-1 means dynamic Otsu thresholding.')
optional_args.add_argument('--n-points',
type=int,
default=None,
Expand All @@ -203,7 +216,7 @@ def parse_command_args(training_or_testing):
help='Don\'t paint a red circle at each estimated location.')
optional_args.add_argument('--seed',
type=int,
default=1,
default=0,
metavar='S',
help='Random seed.')
optional_args.add_argument('--max-testset-size',
Expand All @@ -226,6 +239,22 @@ def parse_command_args(training_or_testing):

args.paint = not args.no_paint

# String/Int -> List
if isinstance(args.taus, list):
pass
elif isinstance(args.taus, str) and ',' in args.taus:
args.taus = [float(tau) for tau in args.taus.split(',')]
else:
args.taus = [int(args.taus)]

if isinstance(args.radii, list):
pass
elif isinstance(args.radii, str) and ',' in args.radii:
args.radii = [int(r) for r in args.radii.split(',')]
else:
args.radii = [int(args.radii)]


else:
raise ValueError('Only \'training\' or \'testing\' allowed, got %s'
% training_or_testing)
Expand Down
10 changes: 6 additions & 4 deletions object-locator/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __getitem__(self, idx):
"""

if self.there_is_gt:
img_abspath = os.path.join(self.root_dir, self.csv_df.ix[idx, 0])
img_abspath = os.path.join(self.root_dir, self.csv_df.ix[idx].filename)
dictionary = dict(self.csv_df.ix[idx])
else:
img_abspath = os.path.join(self.root_dir, self.listfiles[idx])
Expand Down Expand Up @@ -138,7 +138,8 @@ def __getitem__(self, idx):
# Prevents crash when making a batch out of an empty tensor
if dictionary['count'][0] == 0:
with torch.no_grad():
dictionary['locations'] = torch.tensor([-1, -1])
dictionary['locations'] = torch.tensor([-1, -1],
dtype=torch.get_default_dtype())

return (img_transformed, transformed_dictionary)

Expand Down Expand Up @@ -236,7 +237,7 @@ def __call__(self, img, dictionary):
img = super(ScaleImageAndLabel, self).__call__(img)

# Scale GT
if 'locations' in dictionary:
if 'locations' in dictionary and len(dictionary['locations']) > 0:
# print(dictionary['locations'].type())
# print(torch.tensor([scale_h, scale_w]).type())
with torch.no_grad():
Expand Down Expand Up @@ -473,6 +474,7 @@ def __getitem__(self, idx):
# Prevents crash when making a batch out of an empty tensor
if self.there_is_gt and dictionary['count'].item() == 0:
with torch.no_grad():
dictionary['locations'] = torch.tensor([-1, -1])
dictionary['locations'] = torch.tensor([-1, -1],
dtype=torch.get_default_dtype())

return (img_transformed, transformed_dictionary)
Loading

0 comments on commit 78b1461

Please sign in to comment.