Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Update NeuralNet.py #19

Merged
merged 4 commits into from
Nov 30, 2020
Merged
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
16 changes: 8 additions & 8 deletions graphprot/NeuralNet.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, database, Net,

else:
self.load_params(pretrained_model)

self.outdir = outdir
# dataset
dataset = HDF5DataSet(root='./', database=database, index=self.index,
node_feature=self.node_feature, edge_feature=self.edge_feature,
Expand Down Expand Up @@ -218,10 +218,10 @@ def train(self, nepoch=1, validate=False, plot=False, save_model='last', hdf5='t

# If file exists, change its name with a number
count = 0
hdf5_name = hdf5.split('.')[0]
while os.path.exists(fname) :
count += 1
hdf5 = hdf5.split('.')[0]
hdf5 = '{}_{:03d}.hdf5'.format(hdf5, count)
hdf5 = '{}_{:03d}.hdf5'.format(hdf5_name, count)
fname = os.path.join(self.outdir, hdf5)

# Open output file for writting
Expand Down Expand Up @@ -346,10 +346,10 @@ def test(self, database_test, threshold=4, hdf5='test_data.hdf5'):

# If file exists, change its name with a number
count = 0
hdf5_name = hdf5.split('.')[0]
while os.path.exists(fname) :
count += 1
hdf5 = hdf5.split('.')[0]
hdf5 = '{}_{:03d}.hdf5'.format(hdf5, count)
hdf5 = '{}_{:03d}.hdf5'.format(hdf5_name, count)
fname = os.path.join(self.outdir, hdf5)
Comment on lines 348 to 353
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could consider putting that in a staticmethod or external function as it appears at several places :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general code duplication should be avoided as it makes the code difficult to maintain. In this case it's not a big deal of course :)


# Open output file for writting
Expand All @@ -376,8 +376,7 @@ def test(self, database_test, threshold=4, hdf5='test_data.hdf5'):
self.test_acc = _test_acc
self.test_loss = _test_loss

if save_prediction :
self._export_epoch_hdf5(0, self.data)
self._export_epoch_hdf5(0, self.data)

self.f5.close()

Expand Down Expand Up @@ -594,6 +593,7 @@ def _export_epoch_hdf5(self, epoch, data):
# mol name is a bit different
# since there are strings
if data_name == 'mol':
data_value = np.string_(data_value)
string_dt = h5py.special_dtype(vlen=str)
sg.create_dataset(
data_name, data=data_value, dtype=string_dt)
Expand All @@ -603,4 +603,4 @@ def _export_epoch_hdf5(self, epoch, data):
sg.create_dataset(data_name, data=data_value)

except TypeError:
logger.exception("Error in export epoch to hdf5")
raise ValueError("Error in export epoch to hdf5")