carpedm20 / DCGAN-tensorflow

A tensorflow implementation of "Deep Convolutional Generative Adversarial Networks"
http://carpedm20.github.io/faces/
MIT License
7.14k stars 2.63k forks source link

ValueError: could not broadcast input array from shape (1,2048) into shape (98,1024) #395

Open Hemanth-Gloify opened 2 years ago

Hemanth-Gloify commented 2 years ago

I'm trying to build a Attention mechanism for Medical report Generation using Chest X-rays.

train, test = train_test_split(data, test_size = 0.2, random_state = 1, shuffle = True) print(train.shape) - (3056, 4) print(test.shape) - (764, 4)

Function for Extracting the Images:

def image_feature_extraction(image1,image2):

  image_1 = Image.open(image1).convert('RGB')
  image_1 = np.asarray(image_1)

  image_2 = Image.open(image2).convert('RGB')
  image_2 = np.asarray(image_2)

    #normalize the values of the image
  image_1 = image_1/255
  image_2 = image_2/255

    #resize all image into (224,224)
  image_1 = cv2.resize(image_1,(224,224))
  image_2 = cv2.resize(image_2,(224,224))

  image_1 = np.expand_dims(image_1, axis=0)
  image_2 = np.expand_dims(image_2, axis=0)

    #now we have read two image per patient. this is goven to the chexnet model for feature extraction

  image_1_out = final_chexnet_model(image_1)
  image_2_out = final_chexnet_model(image_2)

  #conactenate along the width
  conc = np.concatenate((image_1_out,image_2_out),axis = -1)

  #reshape into(no.of images passed, length*breadth, depth)
  image_feature=tf.reshape(conc,(conc.shape[0], -1, conc.shape[-1]))
  #image_feature = feature_extraction_model([image_1,image_2])

  return image_feature

print(image_2_out)

KerasTensor(type_spec=TensorSpec(shape=(None, 1024), dtype=tf.float32, name=None), name='Chexnet_model/avg_pool/Mean:0', description="created by layer 'Chexnet_model'")

train_features = np.zeros((3056,98,1024))

for row in tqdm(range(train.shape[0])): image_1=train.iloc[row]["image1"] image_2=train.iloc[row]["image2"] train_features[row] = (image_feature_extraction(image_1,image_2))

0%| | 0/3056 [00:00<?, ?it/s]

ValueError Traceback (most recent call last)

in 2 image_1=train.iloc[row]["image1"] 3 image_2=train.iloc[row]["image2"] ----> 4 train_features[row] = (image_feature_extraction(image_1,image_2)) **ValueError: could not broadcast input array from shape (1,2048) into shape (98,1024)**
lihh1023 commented 2 years ago

您好:       来信我已收到,我会尽快回复的。

GraceYYJ commented 2 years ago
收到。