You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by JJZOU via Apache TVM Discuss <no...@discuss.tvm.ai> on 2021/10/19 13:57:10 UTC

[Apache TVM Discuss] [Questions] Check failed: (reporter->AssertEQ(data->shape[data->shape.size() - 1], weight->shape[1])) is false: DenseRel: input dimension doesn't match, data shape=[1, 512], weight shape=[512, 1000]


 ![TVMerror_1|690x397](upload://wldDPxg9rjHK2p6ro1Rvm9fM7JY.png) 
It runs on an Intel CPU and Windows 10.
There seems to be an error in transitioning from PyTorch Graph to Relay Graph.
I am a new entry rookie, thank you for your answer





---
[Visit Topic](https://discuss.tvm.apache.org/t/check-failed-reporter-asserteq-data-shape-data-shape-size-1-weight-shape-1-is-false-denserel-input-dimension-doesnt-match-data-shape-1-512-weight-shape-512-1000/11274/1) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/7aa914970cf94d067fed5cb66c7af1ff3208d4fdcb11e796f04ea50ada312d39).

[Apache TVM Discuss] [Questions] Check failed: (reporter->AssertEQ(data->shape[data->shape.size() - 1], weight->shape[1])) is false: DenseRel: input dimension doesn't match, data shape=[1, 512], weight shape=[512, 1000]

Posted by JJZOU via Apache TVM Discuss <no...@discuss.tvm.ai>.

 I got an error running on torch1.9.0





---
[Visit Topic](https://discuss.tvm.apache.org/t/check-failed-reporter-asserteq-data-shape-data-shape-size-1-weight-shape-1-is-false-denserel-input-dimension-doesnt-match-data-shape-1-512-weight-shape-512-1000/11274/14) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/4c8595e9784c5a58bc002a64c6ab12a0f9ba099bc615ba577f46e4d8d56e77b8).

[Apache TVM Discuss] [Questions] Check failed: (reporter->AssertEQ(data->shape[data->shape.size() - 1], weight->shape[1])) is false: DenseRel: input dimension doesn't match, data shape=[1, 512], weight shape=[512, 1000]

Posted by JJZOU via Apache TVM Discuss <no...@discuss.tvm.ai>.

Yeah,I think maybe I should quit the road of windows now





---
[Visit Topic](https://discuss.tvm.apache.org/t/check-failed-reporter-asserteq-data-shape-data-shape-size-1-weight-shape-1-is-false-denserel-input-dimension-doesnt-match-data-shape-1-512-weight-shape-512-1000/11274/17) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/3596f7385469e033fee5bf7f0dc3937e143fdfee48a7fe7261cbc641f370ac81).

[Apache TVM Discuss] [Questions] Check failed: (reporter->AssertEQ(data->shape[data->shape.size() - 1], weight->shape[1])) is false: DenseRel: input dimension doesn't match, data shape=[1, 512], weight shape=[512, 1000]

Posted by Andrew Zhao Luo via Apache TVM Discuss <no...@discuss.tvm.ai>.

Oh you were using windows this whole time??? 

Yeah I think it might be a little tricky, it has the least amount of testing and use I believe.





---
[Visit Topic](https://discuss.tvm.apache.org/t/check-failed-reporter-asserteq-data-shape-data-shape-size-1-weight-shape-1-is-false-denserel-input-dimension-doesnt-match-data-shape-1-512-weight-shape-512-1000/11274/16) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/daeae7008319eff635593bb2f6a2a4850133b48d60c60bad2e3a24140c3610f0).

[Apache TVM Discuss] [Questions] Check failed: (reporter->AssertEQ(data->shape[data->shape.size() - 1], weight->shape[1])) is false: DenseRel: input dimension doesn't match, data shape=[1, 512], weight shape=[512, 1000]

Posted by JJZOU via Apache TVM Discuss <no...@discuss.tvm.ai>.

I was able to run successfully on torch1.8.0, but reported a new error "RuntimeError: LLVM version is not available, please check if you build with LLVM ", maybe there is a problem with TVM and LLVM on Windows, I am ready to give up and use Ubuntu in the future. There are too many bugs running TVM on Windows





---
[Visit Topic](https://discuss.tvm.apache.org/t/check-failed-reporter-asserteq-data-shape-data-shape-size-1-weight-shape-1-is-false-denserel-input-dimension-doesnt-match-data-shape-1-512-weight-shape-512-1000/11274/15) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/9a7ec9d19c53ef353c142ab1829687f47ff29302baab17e9e38f513038b6f528).

[Apache TVM Discuss] [Questions] Check failed: (reporter->AssertEQ(data->shape[data->shape.size() - 1], weight->shape[1])) is false: DenseRel: input dimension doesn't match, data shape=[1, 512], weight shape=[512, 1000]

Posted by Andrew Zhao Luo via Apache TVM Discuss <no...@discuss.tvm.ai>.

I was not able to reproduce the error. I am using torch `1.9.0.post2`. Do you still have an issue?





---
[Visit Topic](https://discuss.tvm.apache.org/t/check-failed-reporter-asserteq-data-shape-data-shape-size-1-weight-shape-1-is-false-denserel-input-dimension-doesnt-match-data-shape-1-512-weight-shape-512-1000/11274/13) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/07fdd411462367d7d9f319d572cf76e6079bdb67ccd7c74af16db7df86cbc788).

[Apache TVM Discuss] [Questions] Check failed: (reporter->AssertEQ(data->shape[data->shape.size() - 1], weight->shape[1])) is false: DenseRel: input dimension doesn't match, data shape=[1, 512], weight shape=[512, 1000]

Posted by Andrew Zhao Luo via Apache TVM Discuss <no...@discuss.tvm.ai>.

If you share the python file you ran I can try to recreate it.





---
[Visit Topic](https://discuss.tvm.apache.org/t/check-failed-reporter-asserteq-data-shape-data-shape-size-1-weight-shape-1-is-false-denserel-input-dimension-doesnt-match-data-shape-1-512-weight-shape-512-1000/11274/6) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/f25b902d97283b4fada9efcf5e26efcf2f77f79fd33798fffaeb8b2cbeff8b0d).

[Apache TVM Discuss] [Questions] Check failed: (reporter->AssertEQ(data->shape[data->shape.size() - 1], weight->shape[1])) is false: DenseRel: input dimension doesn't match, data shape=[1, 512], weight shape=[512, 1000]

Posted by JJZOU via Apache TVM Discuss <no...@discuss.tvm.ai>.

Sorry, I'm a novice, I can't quite understand what you mean





---
[Visit Topic](https://discuss.tvm.apache.org/t/check-failed-reporter-asserteq-data-shape-data-shape-size-1-weight-shape-1-is-false-denserel-input-dimension-doesnt-match-data-shape-1-512-weight-shape-512-1000/11274/4) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/e6020d10162487e4af33b71eb58fb258d811f19f0c2ef214d4bc72b1d572091b).

[Apache TVM Discuss] [Questions] Check failed: (reporter->AssertEQ(data->shape[data->shape.size() - 1], weight->shape[1])) is false: DenseRel: input dimension doesn't match, data shape=[1, 512], weight shape=[512, 1000]

Posted by Andrew Zhao Luo via Apache TVM Discuss <no...@discuss.tvm.ai>.

Do you have a script to recreate?





---
[Visit Topic](https://discuss.tvm.apache.org/t/check-failed-reporter-asserteq-data-shape-data-shape-size-1-weight-shape-1-is-false-denserel-input-dimension-doesnt-match-data-shape-1-512-weight-shape-512-1000/11274/2) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/5e52fd858a7e04fa3dcb6de6b8bfea0fccc060a2f4adbabdac271a1be27388bb).

[Apache TVM Discuss] [Questions] Check failed: (reporter->AssertEQ(data->shape[data->shape.size() - 1], weight->shape[1])) is false: DenseRel: input dimension doesn't match, data shape=[1, 512], weight shape=[512, 1000]

Posted by JJZOU via Apache TVM Discuss <no...@discuss.tvm.ai>.

Thank you very much,I'll give it a try。





---
[Visit Topic](https://discuss.tvm.apache.org/t/check-failed-reporter-asserteq-data-shape-data-shape-size-1-weight-shape-1-is-false-denserel-input-dimension-doesnt-match-data-shape-1-512-weight-shape-512-1000/11274/5) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/f914dc47c4f63c492c0ae474c58f059f114befe303e14e6ce97dbc522da0c0ad).

[Apache TVM Discuss] [Questions] Check failed: (reporter->AssertEQ(data->shape[data->shape.size() - 1], weight->shape[1])) is false: DenseRel: input dimension doesn't match, data shape=[1, 512], weight shape=[512, 1000]

Posted by know via Apache TVM Discuss <no...@discuss.tvm.ai>.

I got the same error with torch v1.9.1. 
I downgraded it to v1.8.0 and it works.





---
[Visit Topic](https://discuss.tvm.apache.org/t/check-failed-reporter-asserteq-data-shape-data-shape-size-1-weight-shape-1-is-false-denserel-input-dimension-doesnt-match-data-shape-1-512-weight-shape-512-1000/11274/3) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/c37aeaea9f52d97ccf91f7a8fd236ba5ea7ff7e870caf13aa972ccbf3b77291d).

[Apache TVM Discuss] [Questions] Check failed: (reporter->AssertEQ(data->shape[data->shape.size() - 1], weight->shape[1])) is false: DenseRel: input dimension doesn't match, data shape=[1, 512], weight shape=[512, 1000]

Posted by JJZOU via Apache TVM Discuss <no...@discuss.tvm.ai>.

  Not yet, but it worked in Ubuntu16.04





---
[Visit Topic](https://discuss.tvm.apache.org/t/check-failed-reporter-asserteq-data-shape-data-shape-size-1-weight-shape-1-is-false-denserel-input-dimension-doesnt-match-data-shape-1-512-weight-shape-512-1000/11274/12) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/5d1d4573aa883988630b36eddbcd06eba7b6815fbd9848bdc5b7fde151342aa9).

[Apache TVM Discuss] [Questions] Check failed: (reporter->AssertEQ(data->shape[data->shape.size() - 1], weight->shape[1])) is false: DenseRel: input dimension doesn't match, data shape=[1, 512], weight shape=[512, 1000]

Posted by JJZOU via Apache TVM Discuss <no...@discuss.tvm.ai>.

Not yet, but I run the same code successfully in Ubuntu





---
[Visit Topic](https://discuss.tvm.apache.org/t/check-failed-reporter-asserteq-data-shape-data-shape-size-1-weight-shape-1-is-false-denserel-input-dimension-doesnt-match-data-shape-1-512-weight-shape-512-1000/11274/11) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/24ac91a9fb6f34887daf66fcae0533cba2ada3ed288d793bfd8515e49078b4f6).

[Apache TVM Discuss] [Questions] Check failed: (reporter->AssertEQ(data->shape[data->shape.size() - 1], weight->shape[1])) is false: DenseRel: input dimension doesn't match, data shape=[1, 512], weight shape=[512, 1000]

Posted by JJZOU via Apache TVM Discuss <no...@discuss.tvm.ai>.

I'm sorry that I didn't reply you in time because there are too many courses recently
Here's the code:
import tvm

from tvm import relay

import numpy as np

from tvm.contrib.download import download_testdata

# PyTorch imports

import torch

import torchvision

######################################################################

# Load a pretrained PyTorch model

# -------------------------------

model_name = "resnet18"

model = getattr(torchvision.models, model_name)(pretrained=True)

model = model.eval()

# We grab the TorchScripted model via tracing

input_shape = [1, 3, 224, 224]

input_data = torch.randn(input_shape)

scripted_model = torch.jit.trace(model, input_data).eval()

######################################################################

# Load a test image

# -----------------

# Classic cat example!

from PIL import Image

import PIL

img_url = "https://github.com/dmlc/mxnet.js/blob/main/data/cat.png?raw=true"

img_path = "C:\\Users\\Batman\\Desktop\\Ⅲ\\CV\\cat.png" #download_testdata(img_url, "cat.png", module="data")

img = Image.open(img_path).resize((224, 224))

# Preprocess the image and convert to tensor

from torchvision import transforms

my_preprocess = transforms.Compose(

    [

        transforms.Resize(256),

        transforms.CenterCrop(224),

        transforms.ToTensor(),

        transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),

    ]

)

img = np.array(img)

print(np.array(img[:,:,0:3]).shape)

img = Image.fromarray(img[:,:,0:3])

img = my_preprocess(img)

img = np.expand_dims(img, 0)

######################################################################

# Import the graph to Relay

# -------------------------

# Convert PyTorch graph to Relay graph. The input name can be arbitrary.

input_name = "input0"

shape_list = [(input_name, img.shape)]

mod, params = relay.frontend.from_pytorch(scripted_model, shape_list)

######################################################################

# Relay Build

# -----------

# Compile the graph to llvm target with given input specification.

target = tvm.target.Target("llvm", host="llvm")

dev = tvm.cpu(0)

with tvm.transform.PassContext(opt_level=3):

    lib = relay.build(mod, target=target, params=params)

######################################################################

# Execute the portable graph on TVM

# ---------------------------------

# Now we can try deploying the compiled model on target.

from tvm.contrib import graph_executor

dtype = "float32"

m = graph_executor.GraphModule(lib["default"](dev))

# Set inputs

m.set_input(input_name, tvm.nd.array(img.astype(dtype)))

# Execute

m.run()

# Get outputs

tvm_output = m.get_output(0)

print(tvm_output.shape)

#####################################################################

# Look up synset name

# -------------------

# Look up prediction top 1 index in 1000 class synset.

synset_url = "".join(

    [

        "https://raw.githubusercontent.com/Cadene/",

        "pretrained-models.pytorch/master/data/",

        "imagenet_synsets.txt",

    ]

)

synset_name = "imagenet_synsets.txt"

synset_path = download_testdata(synset_url, synset_name, module="data")

with open(synset_path) as f:

    synsets = f.readlines()

synsets = [x.strip() for x in synsets]

splits = [line.split(" ") for line in synsets]

key_to_classname = {spl[0]: " ".join(spl[1:]) for spl in splits}

class_url = "".join(

    [

        "https://raw.githubusercontent.com/Cadene/",

        "pretrained-models.pytorch/master/data/",

        "imagenet_classes.txt",

    ]

)

class_name = "imagenet_classes.txt"

class_path = download_testdata(class_url, class_name, module="data")

with open(class_path) as f:

    class_id_to_key = f.readlines()

class_id_to_key = [x.strip() for x in class_id_to_key]

# Get top-1 result for TVM

top1_tvm = np.argmax(np.array(tvm_output))

tvm_class_key = class_id_to_key[top1_tvm]

# Convert input to PyTorch variable and get PyTorch result for comparison

with torch.no_grad():

    torch_img = torch.from_numpy(img)

    output = model(torch_img)

    # Get top-1 result for PyTorch

    top1_torch = np.argmax(output.numpy())

    torch_class_key = class_id_to_key[top1_torch]

print("Relay top-1 id: {}, class name: {}".format(top1_tvm, key_to_classname[tvm_class_key]))

print("Torch top-1 id: {}, class name: {}".format(top1_torch, key_to_classname[torch_class_key]))





---
[Visit Topic](https://discuss.tvm.apache.org/t/check-failed-reporter-asserteq-data-shape-data-shape-size-1-weight-shape-1-is-false-denserel-input-dimension-doesnt-match-data-shape-1-512-weight-shape-512-1000/11274/10) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/34cb9de455d982359b916f8144f0d91faac8ecb41a24c977cf6c579111a2eac1).

[Apache TVM Discuss] [Questions] Check failed: (reporter->AssertEQ(data->shape[data->shape.size() - 1], weight->shape[1])) is false: DenseRel: input dimension doesn't match, data shape=[1, 512], weight shape=[512, 1000]

Posted by Andrew Zhao Luo via Apache TVM Discuss <no...@discuss.tvm.ai>.

If people are suffering from this problem, please send a script/code to recreate it. It should be easy to solve.





---
[Visit Topic](https://discuss.tvm.apache.org/t/check-failed-reporter-asserteq-data-shape-data-shape-size-1-weight-shape-1-is-false-denserel-input-dimension-doesnt-match-data-shape-1-512-weight-shape-512-1000/11274/9) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/df0eee5693753f80755a629fa28aa91aef387f694ffe98f2e043e2097d448770).