nilmtk/nilmtk-contrib

WindowGRU training error

Closed this issue · 4 comments

Hi,
I tried to run the following code:

import warnings
warnings.filterwarnings("ignore")
from nilmtk.api import API
from nilmtk.disaggregate import Mean
from nilmtk_contrib.disaggregate import DAE,Seq2Point, Seq2Seq, RNN, WindowGRU

redd = {
  'power': {
    'mains': ['apparent','active'],
    'appliance': ['apparent','active']
  },
  'sample_rate': 60,

  'appliances': ['fridge'],
  'methods': {
    
      'WindowGRU':WindowGRU({'n_epochs':50,'batch_size':32}),
      'RNN':RNN({'n_epochs':50,'batch_size':32}),
      'DAE':DAE({'n_epochs':50,'batch_size':32}),
      'Seq2Point':Seq2Point({'n_epochs':50,'batch_size':32}),
      'Seq2Seq':Seq2Seq({'n_epochs':50,'batch_size':32}),

      'Mean': Mean({}),
          
  },
   'train': {    
    'datasets': {
            'REDD': {
                'path': 'C:/git/DNN-NILM/data/redd.hdf5',
				'buildings': {
				1: {
					'start_time': '2011-04-17',
                    'end_time': '2011-04-27'
				},
#                 56: {
#             'start_time': '2015-01-28',
#             'end_time': '2015-01-30'
#           },
				}
				                
			}
			}
	},
	'test': {
	'datasets': {
		'REDD': {
			'path': 'C:/git/DNN-NILM/data/redd.hdf5',
			'buildings': {
				1: {
					'start_time': '2013-01-05',
                    'end_time': '2013-01-08'
				},
			}
	}
},
        'metrics':['mae']
}
}

Then, I got the error after the training was done:

api_res = API(redd)

Started training for  WindowGRU
Joint training for  WindowGRU
............... Loading Data for training ...................
Loading data for  REDD  dataset
Loading building ...  1
Loading data for meter ElecMeterID(instance=2, building=1, dataset='REDD')     
Done loading data all meters for this chunk.
Dropping missing values
Training processing
First model training for  fridge
WARNING:tensorflow:From C:\Users\WuTeng\anaconda3\envs\nilm\lib\site-packages\keras\backend\tensorflow_backend.py:422: The name tf.global_variables is deprecated. Please use tf.compat.v1.global_variables instead.

Train on 10206 samples, validate on 1802 samples
Epoch 1/50
10206/10206 [==============================] - 70s 7ms/step - loss: 0.0104 - val_loss: 0.0071

Epoch 00001: val_loss improved from inf to 0.00709, saving model to windowgru-temp-weights-74894.h5
Epoch 2/50
10206/10206 [==============================] - 75s 7ms/step - loss: 0.0067 - val_loss: 0.0043

...

Epoch 00048: val_loss did not improve from 0.00116
Epoch 49/50
10206/10206 [==============================] - 67s 7ms/step - loss: 0.0020 - val_loss: 0.0018

Epoch 00049: val_loss did not improve from 0.00116
Epoch 50/50
10206/10206 [==============================] - 68s 7ms/step - loss: 0.0017 - val_loss: 0.0012

Epoch 00050: val_loss did not improve from 0.00116
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-15-6b963021b56a> in <module>
----> 1 api_res = API(redd)

~\anaconda3\envs\nilm\lib\site-packages\nilmtk\api.py in __init__(self, params)
     44         self.DROP_ALL_NANS = params.get("DROP_ALL_NANS", True)
     45         self.site_only = params.get('site_only',False)
---> 46         self.experiment()
     47 
     48 

~\anaconda3\envs\nilm\lib\site-packages\nilmtk\api.py in experiment(self)
     89             else:
     90                 print ("Joint training for ",clf.MODEL_NAME)
---> 91                 self.train_jointly(clf,d)
     92 
     93             print ("Finished training for ",clf.MODEL_NAME)

~\anaconda3\envs\nilm\lib\site-packages\nilmtk\api.py in train_jointly(self, clf, d)
    238         self.train_submeters = appliance_readings
    239 
--> 240         clf.partial_fit(self.train_mains,self.train_submeters)
    241 
    
...

~\anaconda3\envs\nilm\lib\site-packages\keras\engine\network.py in load_weights(self, filepath, by_name, skip_mismatch, reshape)
   1228             else:
   1229                 saving.load_weights_from_hdf5_group(
-> 1230                     f, self.layers, reshape=reshape)
   1231             if hasattr(f, 'close'):
   1232                 f.close()

~\anaconda3\envs\nilm\lib\site-packages\keras\engine\saving.py in load_weights_from_hdf5_group(f, layers, reshape)
   1181     """
   1182     if 'keras_version' in f.attrs:
-> 1183         original_keras_version = f.attrs['keras_version'].decode('utf8')
   1184     else:
   1185         original_keras_version = '1'

AttributeError: 'str' object has no attribute 'decode'

Any idea what's the issue? Keras version is wrong?

And here is my package list:

absl-py                   0.12.0             pyhd8ed1ab_0    conda-forge
anyio                     3.0.1            py37h03978a9_0    conda-forge
argon2-cffi               20.1.0           py37hcc03f2d_2    conda-forge
astor                     0.8.1              pyh9f0ad1d_0    conda-forge
async_generator           1.10                       py_0    conda-forge
attrs                     21.2.0             pyhd8ed1ab_0    conda-forge
babel                     2.9.1              pyh44b312d_0    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                        py_2    conda-forge
backports.functools_lru_cache 1.6.4              pyhd8ed1ab_0    conda-forge
bleach                    3.3.0              pyh44b312d_0    conda-forge
blosc                     1.21.0               h0e60522_0    conda-forge
brotlipy                  0.7.0           py37hcc03f2d_1001    conda-forge
bzip2                     1.0.8                h8ffe710_4    conda-forge
ca-certificates           2020.12.5            h5b45459_0    conda-forge
cached-property           1.5.2                hd8ed1ab_1    conda-forge
cached_property           1.5.2              pyha770c72_1    conda-forge
certifi                   2020.12.5        py37h03978a9_1    conda-forge
cffi                      1.14.5           py37hd8e9650_0    conda-forge
chardet                   4.0.0            py37h03978a9_1    conda-forge
colorama                  0.4.4              pyh9f0ad1d_0    conda-forge
cryptography              3.4.7            py37h20c650d_0    conda-forge
cvxpy                     1.1.12           py37h03978a9_0    conda-forge
cvxpy-base                1.1.12           py37h90003fb_0    conda-forge
cycler                    0.10.0                     py_2    conda-forge
dataclasses               0.8                pyhc8e2a94_1    conda-forge
decorator                 5.0.9              pyhd8ed1ab_0    conda-forge
defusedxml                0.7.1              pyhd8ed1ab_0    conda-forge
ecos                      2.0.8            py37hebb4d16_0    conda-forge
entrypoints               0.3             pyhd8ed1ab_1003    conda-forge
freetype                  2.10.4               h546665d_1    conda-forge
gast                      0.4.0              pyh9f0ad1d_0    conda-forge
google-pasta              0.2.0              pyh8c360ce_0    conda-forge
grpcio                    1.37.1           py37h04d2302_0    conda-forge
h5py                      3.2.1           nompi_py37he280515_100    conda-forge
hdf5                      1.10.6          nompi_h5268f04_1114    conda-forge
hmmlearn                  0.2.5            py37hda49f71_0    conda-forge
idna                      2.10               pyh9f0ad1d_0    conda-forge
importlib-metadata        4.0.1            py37h03978a9_0    conda-forge
intel-openmp              2021.2.0           h57928b3_616    conda-forge
ipykernel                 5.5.5            py37h7813e69_0    conda-forge
ipython                   7.23.1           py37h7813e69_0    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
jedi                      0.18.0           py37h03978a9_2    conda-forge
jinja2                    3.0.0              pyhd8ed1ab_0    conda-forge
joblib                    1.0.1              pyhd8ed1ab_0    conda-forge
json5                     0.9.5              pyh9f0ad1d_0    conda-forge
jsonschema                3.2.0              pyhd8ed1ab_3    conda-forge
jupyter_client            6.1.12             pyhd8ed1ab_0    conda-forge
jupyter_core              4.7.1            py37h03978a9_0    conda-forge
jupyter_server            1.7.0            py37h03978a9_1    conda-forge
jupyterlab                3.0.15             pyhd8ed1ab_0    conda-forge
jupyterlab_pygments       0.1.2              pyh9f0ad1d_0    conda-forge
jupyterlab_server         2.5.1              pyhd8ed1ab_0    conda-forge
keras                     2.3.1            py37h21ff451_0    conda-forge
keras-applications        1.0.8                      py_1    conda-forge
keras-preprocessing       1.1.2              pyhd8ed1ab_0    conda-forge
kiwisolver                1.3.1            py37h8c56517_1    conda-forge
krb5                      1.19.1               hbae68bd_0    conda-forge
libblas                   3.9.0                     9_mkl    conda-forge
libcblas                  3.9.0                     9_mkl    conda-forge
libcurl                   7.76.1               h789b8ee_2    conda-forge
libgpuarray               0.7.6             h8ffe710_1003    conda-forge
liblapack                 3.9.0                     9_mkl    conda-forge
libpng                    1.6.37               h1d00b33_2    conda-forge
libprotobuf               3.17.0               h7755175_0    conda-forge
libsodium                 1.0.18               h8d14728_1    conda-forge
libssh2                   1.9.0                h680486a_6    conda-forge
m2w64-gcc-libgfortran     5.3.0                         6    conda-forge
m2w64-gcc-libs            5.3.0                         7    conda-forge
m2w64-gcc-libs-core       5.3.0                         7    conda-forge
m2w64-gmp                 6.1.0                         2    conda-forge
m2w64-libwinpthread-git   5.0.0.4634.697f757               2    conda-forge
mako                      1.1.4              pyh44b312d_0    conda-forge
markdown                  3.3.4              pyhd8ed1ab_0    conda-forge
markupsafe                2.0.0            py37hcc03f2d_0    conda-forge
matplotlib-base           3.1.3            py37h2981e6d_0    conda-forge
matplotlib-inline         0.1.2              pyhd8ed1ab_2    conda-forge
mistune                   0.8.4           py37hcc03f2d_1003    conda-forge
mkl                       2021.2.0           hb70f87d_389    conda-forge
mock                      4.0.3            py37h03978a9_1    conda-forge
msys2-conda-epoch         20160418                      1    conda-forge
nbclassic                 0.2.8              pyhd8ed1ab_0    conda-forge
nbclient                  0.5.3              pyhd8ed1ab_0    conda-forge
nbconvert                 6.0.7            py37h03978a9_3    conda-forge
nbformat                  5.1.3              pyhd8ed1ab_0    conda-forge
nest-asyncio              1.5.1              pyhd8ed1ab_0    conda-forge
networkx                  2.1                        py_1    conda-forge
nilm_metadata             0.2.4                         0    nilmtk
nilmtk                    0.4.3                      py_0    nilmtk
nilmtk-contrib            0.1.1                      py_0    nilmtk
nose                      1.3.7                   py_1006    conda-forge
notebook                  6.3.0              pyha770c72_1    conda-forge
numexpr                   2.7.3            py37h08fd248_0    conda-forge
numpy                     1.19.5           py37hd20adf4_1    conda-forge
openssl                   1.1.1k               h8ffe710_0    conda-forge
osqp                      0.6.2            py37h08fd248_1    conda-forge
packaging                 20.9               pyh44b312d_0    conda-forge
pandas                    0.25.3           py37he350917_0    conda-forge
pandoc                    2.13                 h8ffe710_0    conda-forge
pandocfilters             1.4.2                      py_1    conda-forge
parso                     0.8.2              pyhd8ed1ab_0    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pip                       21.1.1             pyhd8ed1ab_0    conda-forge
prometheus_client         0.10.1             pyhd8ed1ab_0    conda-forge
prompt-toolkit            3.0.18             pyha770c72_0    conda-forge
protobuf                  3.17.0           py37hf2a7229_0    conda-forge
pycparser                 2.20               pyh9f0ad1d_2    conda-forge
pygments                  2.9.0              pyhd8ed1ab_0    conda-forge
pygpu                     0.7.6           py37hda49f71_1002    conda-forge
pyopenssl                 20.0.1             pyhd8ed1ab_0    conda-forge
pyparsing                 2.4.7              pyh9f0ad1d_0    conda-forge
pyreadline                2.1             py37h03978a9_1003    conda-forge
pyrsistent                0.17.3           py37hcc03f2d_2    conda-forge
pysocks                   1.7.1            py37h03978a9_3    conda-forge
pytables                  3.6.1            py37hdc91d43_3    conda-forge
python                    3.7.10          h7840368_100_cpython    conda-forge
python-dateutil           2.8.1                      py_0    conda-forge
python_abi                3.7                     1_cp37m    conda-forge
pytz                      2021.1             pyhd8ed1ab_0    conda-forge
pywin32                   300              py37hcc03f2d_0    conda-forge
pywinpty                  1.0.1            py37h7f67f24_0    conda-forge
pyyaml                    5.4.1            py37hcc03f2d_0    conda-forge
pyzmq                     22.0.3           py37hcce574b_1    conda-forge
qdldl-python              0.1.5            py37h08fd248_0    conda-forge
requests                  2.25.1             pyhd3deb0d_0    conda-forge
scikit-learn              0.24.2           py37h8ded0a9_0    conda-forge
scipy                     1.6.3            py37h924764e_0    conda-forge
scs                       2.1.3            py37he58051b_0    conda-forge
send2trash                1.5.0                      py_0    conda-forge
setuptools                49.6.0           py37h03978a9_3    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
sniffio                   1.2.0            py37h03978a9_1    conda-forge
sqlite                    3.35.5               h8ffe710_0    conda-forge
tbb                       2021.2.0             h2d74725_0    conda-forge
tensorboard               1.14.0                   py37_0    conda-forge
tensorflow                1.14.0               h1f41ff6_0    conda-forge
tensorflow-base           1.14.0           py37hc8dfbb8_0    conda-forge
tensorflow-estimator      1.14.0           py37h5ca1d4c_0    conda-forge
termcolor                 1.1.0                      py_2    conda-forge
terminado                 0.9.4            py37h03978a9_0    conda-forge
testpath                  0.4.4                      py_0    conda-forge
theano                    1.0.5            py37hf2a7229_1    conda-forge
threadpoolctl             2.1.0              pyh5ca1d4c_0    conda-forge
tk                        8.6.10               h8ffe710_1    conda-forge
tornado                   6.1              py37hcc03f2d_1    conda-forge
traitlets                 5.0.5                      py_0    conda-forge
typing_extensions         3.7.4.3                    py_0    conda-forge
urllib3                   1.26.4             pyhd8ed1ab_0    conda-forge
vc                        14.2                 hb210afc_4    conda-forge
vs2015_runtime            14.28.29325          h5e1d092_4    conda-forge
vs2017_win-64             19.16.27038          h2e3bad8_2    conda-forge
vswhere                   2.8.4                h57928b3_0    conda-forge
wcwidth                   0.2.5              pyh9f0ad1d_2    conda-forge
webencodings              0.5.1                      py_1    conda-forge
websocket-client          0.57.0           py37h03978a9_4    conda-forge
werkzeug                  2.0.0              pyhd8ed1ab_0    conda-forge
wheel                     0.36.2             pyhd3deb0d_0    conda-forge
win_inet_pton             1.1.0            py37h03978a9_2    conda-forge
wincertstore              0.2             py37h03978a9_1006    conda-forge
winpty                    0.4.3                         4    conda-forge
wrapt                     1.12.1           py37hcc03f2d_3    conda-forge
yaml                      0.2.5                he774522_0    conda-forge
zeromq                    4.3.4                h0e60522_0    conda-forge
zipp                      3.4.1              pyhd8ed1ab_0    conda-forge
zlib                      1.2.11            h62dcd97_1010    conda-forge

Just downgrade the h5py to version 2.10, it worked fine:
pip install h5py==2.10

I tried nilmtk-contrib with multiple homes in REDD dataset as following

redd = {
'power': {
'mains': ['apparent','active'],
'appliance': ['apparent','active']
},
'sample_rate': 60,

'appliances': ['fridge', 'light', 'dish washer', 'sockets', 'microwave'],
'methods': {

 'DAE':DAE({'n_epochs':10,'batch_size':128}),

},
'train': {
'datasets': {
'REDD': {
'path': '/content/drive/MyDrive/datasets/low_redd.h5',
'buildings': {
2: {
'start_time': '2011-04-18',
'end_time': '2011-04-30'
},
3: {
'start_time': '2011-04-18',
'end_time': '2011-04-30'
},
4: {
'start_time': '2011-04-18',
'end_time': '2011-04-30'
},

			}
			                
		}
		}
},
'test': {
'datasets': {
	'REDD': {
		'path': '/content/drive/MyDrive/datasets/low_redd.h5',
		'buildings': {
			1: {
				'start_time': '2011-04-30',
				'end_time': '2011-05-24'
			},
		}
}

},
'metrics':['mae']
}
}

I got the following error could any one help me

Started training for DAE
Joint training for DAE
............... Loading Data for training ...................
Loading data for REDD dataset
Loading building ... 2
Loading data for meter ElecMeterID(instance=2, building=2, dataset='REDD')
Done loading data all meters for this chunk.
Dropping missing values
Loading building ... 3
Loading data for meter ElecMeterID(instance=2, building=3, dataset='REDD')
Done loading data all meters for this chunk.
Dropping missing values
Loading building ... 4
Loading data for meter ElecMeterID(instance=2, building=4, dataset='REDD')
Done loading data all meters for this chunk.
Traceback (most recent call last):
File "/content/drive/MyDrive/NILM/redd-test.py", line 75, in
api_res = API(redd)
File "/usr/local/lib/python3.7/site-packages/nilmtk/api.py", line 46, in init
self.experiment()
File "/usr/local/lib/python3.7/site-packages/nilmtk/api.py", line 91, in experiment
self.train_jointly(clf,d)
File "/usr/local/lib/python3.7/site-packages/nilmtk/api.py", line 217, in train_jointly
appliance_df = next(train.buildings[building].elec[appliance_name].load(physical_quantity='power', ac_type=self.power['appliance'], sample_period=self.sample_period))
File "/usr/local/lib/python3.7/site-packages/nilmtk/metergroup.py", line 208, in getitem
return self[(key, 1)]
File "/usr/local/lib/python3.7/site-packages/nilmtk/metergroup.py", line 252, in getitem
return self[{'type': key[0], 'instance': key[1]}]
File "/usr/local/lib/python3.7/site-packages/nilmtk/metergroup.py", line 271, in getitem
raise KeyError(key)
KeyError: {'type': 'fridge', 'instance': 1}

I tried nilmtk-contrib with multiple homes in REDD dataset as following

redd = { 'power': { 'mains': ['apparent','active'], 'appliance': ['apparent','active'] }, 'sample_rate': 60,

'appliances': ['fridge', 'light', 'dish washer', 'sockets', 'microwave'], 'methods': {

 'DAE':DAE({'n_epochs':10,'batch_size':128}),

}, 'train': { 'datasets': { 'REDD': { 'path': '/content/drive/MyDrive/datasets/low_redd.h5', 'buildings': { 2: { 'start_time': '2011-04-18', 'end_time': '2011-04-30' }, 3: { 'start_time': '2011-04-18', 'end_time': '2011-04-30' }, 4: { 'start_time': '2011-04-18', 'end_time': '2011-04-30' },

			}
			                
		}
		}
},
'test': {
'datasets': {
	'REDD': {
		'path': '/content/drive/MyDrive/datasets/low_redd.h5',
		'buildings': {
			1: {
				'start_time': '2011-04-30',
				'end_time': '2011-05-24'
			},
		}
}

}, 'metrics':['mae'] } }

I got the following error could any one help me

Started training for DAE Joint training for DAE ............... Loading Data for training ................... Loading data for REDD dataset Loading building ... 2 Loading data for meter ElecMeterID(instance=2, building=2, dataset='REDD') Done loading data all meters for this chunk. Dropping missing values Loading building ... 3 Loading data for meter ElecMeterID(instance=2, building=3, dataset='REDD') Done loading data all meters for this chunk. Dropping missing values Loading building ... 4 Loading data for meter ElecMeterID(instance=2, building=4, dataset='REDD') Done loading data all meters for this chunk. Traceback (most recent call last): File "/content/drive/MyDrive/NILM/redd-test.py", line 75, in api_res = API(redd) File "/usr/local/lib/python3.7/site-packages/nilmtk/api.py", line 46, in init self.experiment() File "/usr/local/lib/python3.7/site-packages/nilmtk/api.py", line 91, in experiment self.train_jointly(clf,d) File "/usr/local/lib/python3.7/site-packages/nilmtk/api.py", line 217, in train_jointly appliance_df = next(train.buildings[building].elec[appliance_name].load(physical_quantity='power', ac_type=self.power['appliance'], sample_period=self.sample_period)) File "/usr/local/lib/python3.7/site-packages/nilmtk/metergroup.py", line 208, in getitem return self[(key, 1)] File "/usr/local/lib/python3.7/site-packages/nilmtk/metergroup.py", line 252, in getitem return self[{'type': key[0], 'instance': key[1]}] File "/usr/local/lib/python3.7/site-packages/nilmtk/metergroup.py", line 271, in getitem raise KeyError(key) KeyError: {'type': 'fridge', 'instance': 1}

Hello, I am getting the following key error did you encounter such an issue??

#78 (comment)