Giter VIP home page Giter VIP logo

Comments (4)

AdeelH avatar AdeelH commented on June 11, 2024

I believe your model expects 256x256 inputs and you are passing in something larger. If you're using the code from this notebook, you might need to change 325 to 256.

P.S. please properly format your posts using GitHub markdown in the future.

from raster-vision.

skylning avatar skylning commented on June 11, 2024

TThanks you replay,i change 325 to 256,and rerun the code,and i get new error as following:


ValueError                                Traceback (most recent call last)
Cell In[35], [line 10](vscode-notebook-cell:?execution_count=35&line=10)
      [1](vscode-notebook-cell:?execution_count=35&line=1) from rastervision.core.data import SemanticSegmentationLabels
      [3](vscode-notebook-cell:?execution_count=35&line=3) predictions = learner.predict_dataset(
      [4](vscode-notebook-cell:?execution_count=35&line=4)     ds,
      [5](vscode-notebook-cell:?execution_count=35&line=5)     raw_out=True,
      [6](vscode-notebook-cell:?execution_count=35&line=6)     numpy_out=True,
      [7](vscode-notebook-cell:?execution_count=35&line=7)     predict_kw=dict(out_shape=(256, 256)),
      [8](vscode-notebook-cell:?execution_count=35&line=8)     progress_bar=True)
---> [10](vscode-notebook-cell:?execution_count=35&line=10) pred_labels = SemanticSegmentationLabels.from_predictions(
     [11](vscode-notebook-cell:?execution_count=35&line=11)     ds.windows,
     [12](vscode-notebook-cell:?execution_count=35&line=12)     predictions,
     [13](vscode-notebook-cell:?execution_count=35&line=13)     smooth=True,
     [14](vscode-notebook-cell:?execution_count=35&line=14)     extent=ds.scene.extent,
     [15](vscode-notebook-cell:?execution_count=35&line=15)     num_classes=len(class_config))

File [~/.local/lib/python3.10/site-packages/rastervision/core/data/label/semantic_segmentation_labels.py:210](https://file+.vscode-resource.vscode-cdn.net/media/lining/0BFD1A2A0BFD1A2A/mywork/rastervision/~/.local/lib/python3.10/site-packages/rastervision/core/data/label/semantic_segmentation_labels.py:210), in SemanticSegmentationLabels.from_predictions(cls, windows, predictions, extent, num_classes, smooth, crop_sz)
    [184](https://file+.vscode-resource.vscode-cdn.net/media/lining/0BFD1A2A0BFD1A2A/mywork/rastervision/~/.local/lib/python3.10/site-packages/rastervision/core/data/label/semantic_segmentation_labels.py:184) """Instantiate from windows and their corresponding predictions.
    [185](https://file+.vscode-resource.vscode-cdn.net/media/lining/0BFD1A2A0BFD1A2A/mywork/rastervision/~/.local/lib/python3.10/site-packages/rastervision/core/data/label/semantic_segmentation_labels.py:185) 
    [186](https://file+.vscode-resource.vscode-cdn.net/media/lining/0BFD1A2A0BFD1A2A/mywork/rastervision/~/.local/lib/python3.10/site-packages/rastervision/core/data/label/semantic_segmentation_labels.py:186) Args:
   (...)
    [207](https://file+.vscode-resource.vscode-cdn.net/media/lining/0BFD1A2A0BFD1A2A/mywork/rastervision/~/.local/lib/python3.10/site-packages/rastervision/core/data/label/semantic_segmentation_labels.py:207)     Otherwise, a SemanticSegmentationDiscreteLabels.
    [208](https://file+.vscode-resource.vscode-cdn.net/media/lining/0BFD1A2A0BFD1A2A/mywork/rastervision/~/.local/lib/python3.10/site-packages/rastervision/core/data/label/semantic_segmentation_labels.py:208) """
    [209](https://file+.vscode-resource.vscode-cdn.net/media/lining/0BFD1A2A0BFD1A2A/mywork/rastervision/~/.local/lib/python3.10/site-packages/rastervision/core/data/label/semantic_segmentation_labels.py:209) labels = cls.make_empty(extent, num_classes, smooth=smooth)
...
    [480](https://file+.vscode-resource.vscode-cdn.net/media/lining/0BFD1A2A0BFD1A2A/mywork/rastervision/~/.local/lib/python3.10/site-packages/rastervision/core/data/label/semantic_segmentation_labels.py:480) pixel_class_scores = pixel_class_scores[..., src_yslice, src_xslice]
--> [481](https://file+.vscode-resource.vscode-cdn.net/media/lining/0BFD1A2A0BFD1A2A/mywork/rastervision/~/.local/lib/python3.10/site-packages/rastervision/core/data/label/semantic_segmentation_labels.py:481) self.pixel_scores[..., dst_yslice, dst_xslice] += pixel_class_scores
    [482](https://file+.vscode-resource.vscode-cdn.net/media/lining/0BFD1A2A0BFD1A2A/mywork/rastervision/~/.local/lib/python3.10/site-packages/rastervision/core/data/label/semantic_segmentation_labels.py:482) self.pixel_hits[dst_yslice, dst_xslice] += 1


ValueError: operands could not be broadcast together with shapes (3,256,256) (2,256,256) (3,256,256)

and my complete code as follow:

from rastervision.pytorch_learner import SemanticSegmentationLearner

learner = SemanticSegmentationLearner.from_model_bundle(
    model_bundle_uri='./train-demo/model-bundle.zip',
    output_dir='./train/',
    model=model,
    training=False
)
image_uri = f'longjiangbouter.tif'
label_uri = f'longjiangbouter.geojson'
from rastervision.core.data import ClassConfig

class_config = ClassConfig(
    names=['building', 'background'],
    colors=['orange', 'black'])
class_config.ensure_null_class()
from rastervision.core.data import ClassConfig
from rastervision.pytorch_learner import SemanticSegmentationSlidingWindowGeoDataset

import albumentations as A

ds = SemanticSegmentationSlidingWindowGeoDataset.from_uris(
    class_config=class_config,
    image_uri=image_uri,
    size=256,
    stride=256,
    transform=A.Resize(256, 256))

from rastervision.core.data import SemanticSegmentationLabels

predictions = learner.predict_dataset(
    ds,
    raw_out=True,
    numpy_out=True,
    predict_kw=dict(out_shape=(256, 256)),
    progress_bar=True)

pred_labels = SemanticSegmentationLabels.from_predictions(
    ds.windows,
    predictions,
    smooth=True,
    extent=ds.scene.extent,
    num_classes=len(class_config))

from raster-vision.

AdeelH avatar AdeelH commented on June 11, 2024

The class config that you used to train the model and the class config you are using now are not identical. You might want to pass null_class='background' to ClassConfig.

from raster-vision.

skylning avatar skylning commented on June 11, 2024

thank your help,now i can run the code for prediction ,and now i retrain the model more epochs

from raster-vision.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.