--------------------------------------------------------------------------- AttributeError Traceback (most re…
- User
AttributeError Traceback (most recent call last) Cell In[6], line 2 1 # Compute image-hash ----> 2 model.compute_hash(method='phash', hash_size=hash_size) 4 # Find images with image-hash <= threshold 5 model.group(threshold=10)
Cell In[4], line 122, in Undouble.compute_hash(self, method, hash_size, return_dict) 118 self.results['img_hash_hex'] = self.bin2hex() 119 logger.info( 120 'Compute adjacency matrix [%gx%g] with absolute differences based on the image-hash of [%s].' % ( 121 self.results['img_hash_bin'].shape[0], self.results['img_hash_bin'].shape[0], self.params['method'])) --> 122 self.results['adjmat'] = (self.results['img_hash_bin'][:, None, :] != self.results['img_hash_bin']).sum(2) 123 self.results.pop('labels', None) 124 self.results.pop('xycoord', None)
AttributeError: 'bool' object has no attribute 'sum'
- Assistant
This error occurs because the 'sum' method is being applied to a boolean object instead of a numpy array or a pandas DataFrame.
To fix this error, you can check the variable 'self.results['img_hash_bin']' and make sure it is a numpy array or a pandas DataFrame before applying the 'sum' method.
- User
show me
- Assistant
To fix the 'AttributeError: 'bool' object has no attribute 'sum'' error, you can modify the code as follows:
# Compute image-hash model.compute_hash(method='phash', hash_size=hash_size) # Find images with image-hash <= threshold model.group(threshold=10) # Check if img_hash_bin is a boolean object if isinstance(self.results['img_hash_bin'], bool): self.results['img_hash_bin'] = np.array(self.results['img_hash_bin']) # Compute adjacency matrix self.results['adjmat'] = (self.results['img_hash_bin'][:, None, :] != self.results['img_hash_bin']).sum(2) # Remove unnecessary results self.results.pop('labels', None) self.results.pop('xycoord', None)In the modified code, we first check if 'self.results['img_hash_bin']' is a boolean object using the
isinstance()function. If it is, we convert it to a numpy array usingnp.array(). This ensures that we can apply the 'sum' method without any error.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.