textgenrnn
textgenrnn copied to clipboard
Something is wrong in importing a saved model
textgen_2.generate(3, temperature=1.0)
ValueError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/textgenrnn/textgenrnn.py in init(self, weights_path, vocab_path, config_path, name, allow_growth) 74 self.model = textgenrnn_model(self.num_classes, 75 cfg=self.config, ---> 76 weights_path=weights_path) 77 self.indices_char = dict((self.vocab[c], c) for c in self.vocab) 78
/usr/local/lib/python3.6/dist-packages/textgenrnn/model.py in textgenrnn_model(num_classes, cfg, context_size, weights_path, dropout, optimizer) 37 model = Model(inputs=[input], outputs=[output]) 38 if weights_path is not None: ---> 39 model.load_weights(weights_path, by_name=True) 40 model.compile(loss='categorical_crossentropy', optimizer=optimizer) 41
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/engine/training.py in load_weights(self, filepath, by_name, skip_mismatch) 232 raise ValueError('Load weights is not yet supported with TPUStrategy ' 233 'with steps_per_run greater than 1.') --> 234 return super(Model, self).load_weights(filepath, by_name, skip_mismatch) 235 236 @trackable.no_automatic_dependency_tracking
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/engine/network.py in load_weights(self, filepath, by_name, skip_mismatch) 1218 if by_name: 1219 hdf5_format.load_weights_from_hdf5_group_by_name( -> 1220 f, self.layers, skip_mismatch=skip_mismatch) 1221 else: 1222 hdf5_format.load_weights_from_hdf5_group(f, self.layers)
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/saving/hdf5_format.py in load_weights_from_hdf5_group_by_name(f, layers, skip_mismatch) 775 symbolic_weights[i])) + 776 ', but the saved weight has shape ' + --> 777 str(weight_values[i].shape) + '.') 778 779 else:
ValueError: Layer #1 (named "embedding"), weight <tf.Variable 'embedding_9/embeddings:0' shape=(465, 100) dtype=float32, numpy= array([[-0.03741096, -0.04658312, 0.01201523, ..., -0.02237569, 0.00691094, -0.00432412], [-0.01291311, -0.02439495, 0.04050244, ..., -0.01166402, -0.03546994, 0.02613578], [-0.02922498, 0.02382291, -0.04644821, ..., 0.0323942 , 0.0452521 , -0.02743921], ..., [-0.01573447, 0.04208423, 0.02321548, ..., 0.04489509, -0.02404162, -0.01873245], [ 0.02387646, -0.00570326, 0.02345118, ..., -0.01930389, -0.01780029, 0.00130523], [-0.02276372, 0.00365648, -0.04388548, ..., -0.01877537, -0.00214895, -0.02720003]], dtype=float32)> has shape (465, 100), but the saved weight has shape (51, 100).
You probably need to specify the locations of the model's other auxiliary files too:
e.g.
textgen2 = textgenrnn(
weights_path='colaboratory_weights.hdf5',
vocab_path='colaboratory_vocab.json',
config_path='colaboratory_config.json'
)
its always been like that in my code and suddenly stopped working but everything is correct