I was using the SAM-LSTM-RESNET package and i had a this shape problem.
It is also happenning with the examples pics that come with the package, so it’s very wierd that it does not work as it should. Someone knoes how to fix this without modifying the package’s code?
from sam_lstm import SalMap
import os
if not os.path.exists("\samples"):
os.makedirs("\samples")
SalMap.auto()
and this was the traceback
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [5], in <cell line: 9>()
6 if not os.path.exists("\samples"):
7 os.makedirs("\samples")
----> 9 SalMap.auto()
File ~anaconda3libsite-packagessam_lstm__init__.py:48, in SalMap.auto(cls)
45 @classmethod
46 def auto(cls):
47 salmap = cls()
---> 48 salmap.compile()
49 salmap.load_weights()
50 salmap.predict_maps()
File ~anaconda3libsite-packagessam_lstm__init__.py:59, in SalMap.compile(self)
57 def compile(self):
58 self.model = Model(
---> 59 inputs=[self.x, self.x_maps], outputs=sam_resnet([self.x, self.x_maps])
60 )
61 self.model.compile(
62 RMSprop(learning_rate=1e-4),
63 loss=[kl_divergence, correlation_coefficient, nss],
64 loss_weights=[10, -2, -1],
65 )
File ~anaconda3libsite-packagessam_lstmmodels.py:192, in sam_resnet(x)
190 def sam_resnet(x):
191 # Dilated Convolutional Network
--> 192 dcn = dcn_resnet(input_tensor=x[0])
193 conv_feat = Conv2D(512, (3, 3), padding="same", activation="relu")(dcn.output)
194 # Attentive Convolutional LSTM
File ~anaconda3libsite-packagessam_lstmdcn_resnet.py:259, in dcn_resnet(input_tensor)
252 # Load weights
253 weights_path = get_file(
254 "resnet50_weights_th_dim_ordering_th_kernels_notop.h5",
255 TH_WEIGHTS_PATH_NO_TOP,
256 cache_subdir="weights",
257 file_hash="f64f049c92468c9affcd44b0976cdafe",
258 )
--> 259 model.load_weights(weights_path)
261 return model
File ~anaconda3libsite-packageskerassrcutilstraceback_utils.py:122, in filter_traceback.<locals>.error_handler(*args, **kwargs)
119 filtered_tb = _process_traceback_frames(e.__traceback__)
120 # To get the full stack trace, call:
121 # `keras.config.disable_traceback_filtering()`
--> 122 raise e.with_traceback(filtered_tb) from None
123 finally:
124 del filtered_tb
File ~anaconda3libsite-packageskerassrcbackendcommonvariables.py:226, in KerasVariable.assign(self, value)
224 value = self._convert_to_tensor(value, dtype=self.dtype)
225 if not shape_equal(value.shape, self.shape):
--> 226 raise ValueError(
227 "The shape of the target variable and "
228 "the shape of the target value in "
229 "`variable.assign(value)` must match. "
230 f"variable.shape={self.value.shape}, "
231 f"Received: value.shape={value.shape}. "
232 f"Target variable: {self}"
233 )
234 if in_stateless_scope():
235 scope = get_stateless_scope()
ValueError: The shape of the target variable and the shape of the target value in `variable.assign(value)` must match. variable.shape=(7, 7, 3, 64), Received: value.shape=(64, 3, 7, 7). Target variable: <KerasVariable shape=(7, 7, 3, 64), dtype=float32, path=conv1/kernel>
ass you can see the error is basicaly the shape that is transposed somehow but i don’t know how to fix it?
New contributor
damian antonio gonzo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.