Got it

Error message \'raise ValueError(f"For \'{prim_name}\', the x_shape {x_shape} and y_shape {y_shape} can not broadcast.") ValueError: For \'A

Created: Sep 22, 2021 09:45:05Latest reply: Oct 11, 2021 10:32:10 407 6 0 0 0
  HiCoins as reward: 0 (problem unresolved)

I am trying to implement FastRCNN using Mindspore, I am using the code from the offciel gitee as a reference: 'https://gitee.com/mindspore/mindspore/tree/r1.0/model_zoo/official/cv/faster_rcnn', everything in the code is working well but when I start training it gives me the follwing error: 

raise ValueError(f"For '{prim_name}', the x_shape {x_shape} and y_shape {y_shape} can not broadcast.")
ValueError: For 'Add', the x_shape [2, 256, 24, 32] and y_shape [2, 256, 48, 80] can not broadcast.


Knowing that I am using VOC dataset and MindSpore 1.3.0 

This a snapshot of the code: 


## The shape of the mindrecord:
fasterrcnn_json = {
    "image": {"type": "bytes"},
    "annotation": {"type": "int32", "shape": [-1, 6]},
    
##### annotation=[x1,y1,x2,y2,label(int),iscrowd(int)]


}
writer.add_schema(fasterrcnn_json, "fasterrcnn_json")

###############the function of creating the dataset: 

def create_fasterrcnn_dataset(mindrecord_file, batch_size=2, repeat_num=12, device_num=1, rank_id=0,
                              is_training=True, num_parallel_workers=4):
    """Creatr FasterRcnn dataset with MindDataset."""
    ds = de.MindDataset(mindrecord_file, columns_list=["image", "annotation"], num_shards=device_num, shard_id=rank_id,
                        num_parallel_workers=1, shuffle=is_training)
    decode = C.Decode()
    ds = ds.map(operations=decode, input_columns=["image"], num_parallel_workers=1)
    compose_map_func = (lambda image, annotation: preprocess_fn(image, annotation, is_training))

    hwc_to_chw = C.HWC2CHW()
    normalize_op = C.Normalize((123.675, 116.28, 103.53), (58.395, 57.12, 57.375))
    horizontally_op = C.RandomHorizontalFlip(1)
    type_cast0 = CC.TypeCast(mstype.float32)
    type_cast1 = CC.TypeCast(mstype.float16)
    type_cast2 = CC.TypeCast(mstype.int32)
    type_cast3 = CC.TypeCast(mstype.bool_)

    if is_training:
        ds = ds.map(operations=compose_map_func, input_columns=["image", "annotation"],
                    output_columns=["image", "image_shape", "box", "label", "valid_num"],
                    column_order=["image", "image_shape", "box", "label", "valid_num"],
                    num_parallel_workers=num_parallel_workers)

        flip = (np.random.rand() < config.flip_ratio)
        if flip:
            ds = ds.map(operations=[normalize_op, type_cast0, horizontally_op], input_columns=["image"],
                        num_parallel_workers=1)
            ds = ds.map(operations=flipped_generation,
                        input_columns=["image", "image_shape", "box", "label", "valid_num"],
                        num_parallel_workers=num_parallel_workers)
        else:
            ds = ds.map(operations=[normalize_op, type_cast0], input_columns=["image"],
                        num_parallel_workers=1)
        ds = ds.map(operations=[hwc_to_chw, type_cast1], input_columns=["image"],
                    num_parallel_workers=1)

    else:
        ds = ds.map(operations=compose_map_func,
                    input_columns=["image", "annotation"],
                    output_columns=["image", "image_shape", "box", "label", "valid_num"],  ###what is valid-num
                    column_order=["image", "image_shape", "box", "label", "valid_num"],
                    num_parallel_workers=num_parallel_workers)

        ds = ds.map(operations=[normalize_op, hwc_to_chw, type_cast1], input_columns=["image"],
                    num_parallel_workers=1)

    # transpose_column from python to c
    ds = ds.map(operations=[type_cast1], input_columns=["image_shape"])
    ds = ds.map(operations=[type_cast1], input_columns=["box"])
    ds = ds.map(operations=[type_cast2], input_columns=["label"])
    ds = ds.map(operations=[type_cast3], input_columns=["valid_num"])
    ds = ds.batch(batch_size, drop_remainder=True)
    ds = ds.repeat(repeat_num)
    ds

    return ds

######Dataset creation:
dataset = create_fasterrcnn_dataset(mindrecord_file, repeat_num=1,
                                    batch_size=config.batch_size, device_num=device_num, rank_id=rank)
                                    
##### Start trainign the model: 
model.train(config.epoch_size, dataset, callbacks=cb)

-How do you think I can solve the error?

-The question also is, How the model suppose to split the data into X and Y and what is why in this case? 


Thank you in Advance!


I attached the full error traceback as doc file. 

Attachment: You need to log in to download or view. No account? Register

Featured Answers

Recommended answer

cle
Created Sep 22, 2021 10:57:01

The MindSpore version must match the script version. You are advised to refer to the following:https://gitee.com/mindspore/mindspore/tree/r1.3/model_zoo/official/cv/faster_rcnn
View more
  • x
  • convention:

All Answers
Y_T_Z
Y_T_Z Admin Created Sep 22, 2021 09:45:40

Hello, dear.
It's nice to meet you in the community.
We're working on getting the right answer for you. Please rest assured that we'll be back with an answer shortly.
View more
  • x
  • convention:

Posted by Y_T_Z at 2021-09-22 09:45 Hello, dear.It's nice to meet you in the community.We're working on getting the right answer for you ...
Thank you dear, nice to meet you too.

Ok sure, looking forward to have a working code ^^.
View more
  • x
  • convention:

Hello, what version of MindSpore is used? Please provide the version information.
View more
  • x
  • convention:

Posted by cle at 2021-09-22 09:59 Hello, what version of MindSpore is used? Please provide the version information.
I am using MindSpore 1.3
View more
  • x
  • convention:

The MindSpore version must match the script version. You are advised to refer to the following:https://gitee.com/mindspore/mindspore/tree/r1.3/model_zoo/official/cv/faster_rcnn
View more
  • x
  • convention:

Good answer
View more
  • x
  • convention:

Comment

You need to log in to comment to the post Login | Register
Comment

Notice: To protect the legitimate rights and interests of you, the community, and third parties, do not release content that may bring legal risks to all parties, including but are not limited to the following:
  • Politically sensitive content
  • Content concerning pornography, gambling, and drug abuse
  • Content that may disclose or infringe upon others ' commercial secrets, intellectual properties, including trade marks, copyrights, and patents, and personal privacy
Do not share your account and password with others. All operations performed using your account will be regarded as your own actions and all consequences arising therefrom will be borne by you. For details, see " User Agreement."

My Followers

Login and enjoy all the member benefits

Login

Block
Are you sure to block this user?
Users on your blacklist cannot comment on your post,cannot mention you, cannot send you private messages.
Reminder
Please bind your phone number to obtain invitation bonus.