Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify some code to run on windows system. #139

Open
wants to merge 5 commits into
base: OpenSTL-Lightning
Choose a base branch
from
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
6 changes: 3 additions & 3 deletions openstl/api/exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ def _get_data(self, dataloaders=None):
return BaseDataModule(train_loader, vali_loader, test_loader)

def train(self):
self.trainer.fit(self.method, self.data)
self.trainer.fit(self.method, self.data.train_loader)

def test(self):
if self.args.test == True:
ckpt = torch.load(osp.join(self.save_dir, 'checkpoints', 'best.ckpt'))
self.method.load_state_dict(ckpt['state_dict'])
self.trainer.test(self.method, self.data)
self.trainer.test(self.method, self.data.test_loader)

def display_method_info(self, args):
"""Plot the basic infomation of supported methods"""
Expand Down Expand Up @@ -142,4 +142,4 @@ def display_method_info(self, args):
fps = 'Throughputs of {}: {:.3f}\n'.format(args.method, fps)
else:
fps = ''
return info, flops, fps, dash_line
return info, flops, fps, dash_line
10 changes: 7 additions & 3 deletions openstl/utils/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
import ast
from importlib import import_module
import os

'''
Thanks the code from https://github.com/open-mmlab/mmcv/blob/master/mmcv/utils/config.py wrote by Open-MMLab.
Expand Down Expand Up @@ -58,8 +59,10 @@ def _substitute_predefined_vars(filename, temp_config_name):
regexp = r'\{\{\s*' + str(key) + r'\s*\}\}'
value = value.replace('\\', '/')
config_file = re.sub(regexp, value, config_file)
with open(temp_config_name, 'w') as tmp_config_file:
tmp_config_file.write(config_file)
# with open(temp_config_name, 'w') as tmp_config_file:
# tmp_config_file.write(config_file)
temp_config_file = open(temp_config_name, 'w')
temp_config_file.write(config_file)

@staticmethod
def _file2dict(filename, use_predefined_variables=True):
Expand All @@ -71,7 +74,7 @@ def _file2dict(filename, use_predefined_variables=True):

with tempfile.TemporaryDirectory() as temp_config_dir:
temp_config_file = tempfile.NamedTemporaryFile(
dir=temp_config_dir, suffix=fileExtname)
dir=temp_config_dir, suffix=fileExtname, delete=False)
temp_config_name = osp.basename(temp_config_file.name)

# Substitute predefined variables
Expand All @@ -96,6 +99,7 @@ def _file2dict(filename, use_predefined_variables=True):
del sys.modules[temp_module_name]
# close temp file
temp_config_file.close()
os.remove(temp_config_file.name)
return cfg_dict

@staticmethod
Expand Down
12 changes: 7 additions & 5 deletions openstl/utils/main_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,15 @@ def get_batch_size(H, W):

def load_config(filename:str = None):
"""load and print config"""
print('loading config from ' + filename + ' ...')
print('loading config from ' + filename)
try:
configfile = Config(filename=filename)
config = configfile._cfg_dict
except (FileNotFoundError, IOError):
config = dict()
print('warning: fail to load the config!')
except Exception as e:
raise Exception('error in load the config:{}'.format(e))
# except (FileNotFoundError, IOError):
# config = dict()
# print('warning: fail to load the config!')
return config


Expand Down Expand Up @@ -177,4 +179,4 @@ def get_dist_info() -> Tuple[int, int]:
else:
rank = 0
world_size = 1
return rank, world_size
return rank, world_size
4 changes: 2 additions & 2 deletions tools/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
config[attribute] = default_values[attribute]

print('>'*35 + ' training ' + '<'*35)
exp = BaseExperiment(args)
exp = BaseExperiment(args, strategy='auto')
rank, _ = get_dist_info()
exp.train()

if rank == 0:
print('>'*35 + ' testing ' + '<'*35)
mse = exp.test()
mse = exp.test()