Gitlab Community Edition Instance
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
workshop-forests-in-hpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AG-Compute-public
workshop-forests-in-hpc
Commits
d7fd0e1c
Commit
d7fd0e1c
authored
2 years ago
by
Dorothea Sommer
Browse files
Options
Downloads
Patches
Plain Diff
refactor dataloader
parent
90901ae7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Pointnet_Example/train.py
+31
-25
31 additions, 25 deletions
Pointnet_Example/train.py
with
31 additions
and
25 deletions
Pointnet_Example/train.py
+
31
−
25
View file @
d7fd0e1c
...
...
@@ -24,6 +24,34 @@ def fix_random_seed(seed: int, device=None) -> None:
torch
.
cuda
.
manual_seed_all
(
seed
)
# For now, do not set torch.backends.cudnn.deterministic to True and cudnn.benchmark to False (it is faster without).
def
create_dataloader
(
data_folder
:
str
,
verbose
=
True
):
"""
Return two dataloaders, one for train and one for validation.
"""
transformations
=
transforms
.
Compose
(
[
SamplePoints
(
1024
,
sample_method
=
"
random
"
)])
# It would be also possible to sample the farthest points:
# transformations = transforms.Compose([SamplePoints(1024, sample_method = "farthest_points")])
data
=
PointCloudDataSet
(
data_folder
,
train
=
True
,
transform
=
transformations
)
validation_percentage
=
0.2
dataset_size
=
len
(
data
)
idx
=
list
(
range
(
dataset_size
))
split
=
int
(
np
.
floor
(
validation_percentage
*
dataset_size
))
np
.
random
.
shuffle
(
idx
)
train_idx
,
val_idx
=
idx
[
split
:],
idx
[:
split
]
if
verbose
:
print
(
f
"
Training is done with
{
len
(
train_idx
)
}
samples.
"
)
print
(
f
"
Validation is done with
{
len
(
val_idx
)
}
samples.
"
)
train_sampler
=
SubsetRandomSampler
(
train_idx
)
val_sampler
=
SubsetRandomSampler
(
val_idx
)
train_loader
=
DataLoader
(
data
,
batch_size
=
batch_size
,
sampler
=
train_sampler
)
val_loader
=
DataLoader
(
data
,
batch_size
=
batch_size
,
sampler
=
val_sampler
)
return
train_loader
,
val_loader
if
__name__
==
"
__main__
"
:
print
(
"
Start training
"
)
...
...
@@ -38,38 +66,16 @@ if __name__ == "__main__":
print
(
f
"
Created path for models in
{
saved_models_path
}
"
)
learning_rate
=
0.0005
batch_size
=
8
### FIX SEEDS ###
fix_random_seed
(
26
,
device
=
device
)
batch_size
=
8
### DATA ####
data_folder
=
"
/scratch/projects/forestcare/data/workshop/synthetic_trees_ten
"
transformations
=
transforms
.
Compose
(
[
SamplePoints
(
1024
,
sample_method
=
"
random
"
)])
# It would be also possible to sample the farthest points:
# transformations = transforms.Compose([SamplePoints(1024, sample_method = "farthest_points")])
data
=
PointCloudDataSet
(
data_folder
,
train
=
True
,
transform
=
transformations
)
validation_percentage
=
0.2
dataset_size
=
len
(
data
)
idx
=
list
(
range
(
dataset_size
))
split
=
int
(
np
.
floor
(
validation_percentage
*
dataset_size
))
np
.
random
.
shuffle
(
idx
)
train_idx
,
val_idx
=
idx
[
split
:],
idx
[:
split
]
print
(
f
"
Training is done with
{
len
(
train_idx
)
}
samples.
"
)
print
(
f
"
Validation is done with
{
len
(
val_idx
)
}
samples.
"
)
train_sampler
=
SubsetRandomSampler
(
train_idx
)
val_sampler
=
SubsetRandomSampler
(
val_idx
)
train_loader
=
DataLoader
(
data
,
batch_size
=
batch_size
,
sampler
=
train_sampler
)
val_loader
=
DataLoader
(
data
,
batch_size
=
batch_size
,
sampler
=
val_sampler
)
train_loader
,
val_loader
=
create_dataloader
(
data_folder
)
### MODEL ####
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment