Code Monkey home page Code Monkey logo

u2netdemo's Introduction

U-2-Net-Demo

Demonstration using Google Colab to show how U-2-NET can be used for Background Removal, Changing Backgrounds, Bounding Box Creation, Salient Feature Highlighting and Salient Object Cropping

Please let me know if you would like to collaborate on building a website/web demo for this repo or any other contributions

Check out these articles making use of this repository:

Medium: Large Scale Background Removal Using AI

I REMOVED THE BACKGROUNDS FROM 11,782 JPGS FOR FREE! USING AI!

UPDATES: upcoming update - notebook for inferencing a large number of images

  • [Jan 11, 2021] - Salient Object Cropping notebook is now available following this PR, thanks to the contribution from Norod!
  • [Jan 05, 2021] - Keras .h5 saved models available in new repository following this issue Note: if there are any new requests for a TensorFlow saved model, I will upload
  • [Dec 24, 2020] - change background in step by step file: commit
  • [Oct 29, 2020] - implemented quick fix for ipynb.checkpoints error: commit

Click this link for step-by-step instructions: Open Google Colab Notebook {Use this to save your results too} {update: now with code to change background}

Click this link for Salient Object Cropping: U_2_Netp_Cropper_Colab

Example Results

Cat:

Formula 1 Car:

Rick Astley:

Background Changed:

Bacground Removed and Image Cropped (Mask and Resulting Image):

Useful material

U-2-NET Paper: U2-Net: Going Deeper with Nested U-Structure for Salient Object Detection

Original Repo: U-2-Net Github repo

Modified repo for that this colab uses: Modified fork

References: X. Qin, Z. Zhang, C. Huang, M. Dehghan, O. R. Zaiane, and M. Jagersand, “U2-net: Going deeper with nested u-structure for salient object detection,” Pattern Recognition, vol. 106, p. 107404, 2020

Other Results

Details about U-2-Net

The following is an excerpt from the paper: 'In this paper, we design a simple yet powerful deep network architecture, U2-Net, for salient object detection (SOD). The architecture of our U2-Net is a two-level nested U-structure. The design has the following advantages: (1) it is able to capture more contextual information from different scales thanks to the mixture of receptive fields of different sizes in our proposed ReSidual U-blocks (RSU), (2) it increases the depth of the whole architecture without significantly increasing the computational cost because of the pooling operations used in these RSU blocks. This architecture enables us to train a deep network from scratch without using backbones from image classification tasks. We instantiate two models of the proposed architecture, U2-Net (176.3 MB, 30 FPS on GTX 1080Ti GPU) and U2-Net† (4.7 MB, 40 FPS), to facilitate the usage in different environments. Both models achieve competitive performance on six SOD datasets.'

U2NET Model

TODO:

  • remove dependancy to secondary repo
  • algorithmic post processing
  • flask demo
  • multiproc cpu code
  • benchmarks
  • video background removal
  • change backgrounds for main notebook
  • support .jpeg images
  • upload python code for webcam support
  • add demo for portrait feature of U-2-Net
  • add license to nbs
  • maybe make a webpage for bounding box creation over large datasets

Please feel free to suggest changes to improve this repository

u2netdemo's People

Contributors

shreyas-bk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

u2netdemo's Issues

ValueError: Could not find a format to read the specified file in single-image mode

Hey, thank you for your effort in sharing this.
I've tried all the collab notebooks and all are failling

# run the test script, and outputs are saved to results folder
!python -W ignore u2net_test.py
['/content/U-2-Net/images/2000388537240_2.png', '/content/U-2-Net/images/2000388299407_2.png']
Traceback (most recent call last):
  File "u2net_test.py", line 117, in <module>
    main()
  File "u2net_test.py", line 91, in main
    for i_test, data_test in enumerate(test_salobj_dataloader):
  File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py", line 681, in __next__
    data = self._next_data()
  File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py", line 1376, in _next_data
    return self._process_data(data)
  File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py", line 1402, in _process_data
    data.reraise()
  File "/usr/local/lib/python3.7/dist-packages/torch/_utils.py", line 461, in reraise
    raise exception
ValueError: Caught ValueError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/worker.py", line 302, in _worker_loop
    data = fetcher.fetch(index)
  File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py", line 49, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py", line 49, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/content/U-2-Net/data_loader.py", line 242, in __getitem__
    image = io.imread(self.image_name_list[idx])
  File "/usr/local/lib/python3.7/dist-packages/skimage/io/_io.py", line 48, in imread
    img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
  File "/usr/local/lib/python3.7/dist-packages/skimage/io/manage_plugins.py", line 207, in call_plugin
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/skimage/io/_plugins/imageio_plugin.py", line 10, in imread
    return np.asarray(imageio_imread(*args, **kwargs))
  File "/usr/local/lib/python3.7/dist-packages/imageio/core/functions.py", line 265, in imread
    reader = read(uri, format, "i", **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/imageio/core/functions.py", line 182, in get_reader
    "Could not find a format to read the specified file in %s mode" % modename
ValueError: Could not find a format to read the specified file in single-image mode

Then, the next cells fail as expected

Load model with keras

Hi.

Is there anyway i can load this model using keras.models.load_model?

Pls i will really appreciate it

Any pre-trained Model For Fashion-Wear ?

Hi, thank you so much for making this code.

Now i have web-scraped some shoe images, but get mixed results (Below Pic)

https://i.postimg.cc/YCTBpyTc/Screenshot-from-2021-11-03-11-07-53.png

Is there a per-trained Fashion model ?, i can use to get the Crop correctly

Thanks :)

because res-net and u-net does detect objects correctly, but i think has somewhat a hard time doing fashion images or i may be Wrong.

I have also been using this project as well, similar to yours.

https://github.com/OPHoperHPO/image-background-remove-tool

An issue on deploying to Tensorflow savedmodel

Hello
How are you?
Thanks for contributing this project.
I tried to deploy this pre-trained model to Tensorflow savedmodel but failed.
Could u provide tensorflow savedmodel too?
Thanks

train own dataset

Is there a way to train on my custom dataset on the already trained model?

error while running the result cell

I get the following error when i run the results cell in colab.

/usr/local/lib/python3.6/dist-packages/keras_preprocessing/image/utils.py in load_img(path, grayscale, color_mode, target_size, interpolation)
111 raise ImportError('Could not import PIL.Image. '
112 'The use of load_img requires PIL.')
--> 113 with open(path, 'rb') as f:
114 img = pil_image.open(io.BytesIO(f.read()))
115 if color_mode == 'grayscale':

FileNotFoundError: [Errno 2] No such file or directory: '/content/U-2-Net/results/.ipynb_checkpo.png'

Error in results cell

I get the following error when i run the results cell in colab.

/usr/local/lib/python3.6/dist-packages/keras_preprocessing/image/utils.py in load_img(path, grayscale, color_mode, target_size, interpolation)
111 raise ImportError('Could not import PIL.Image. '
112 'The use of load_img requires PIL.')
--> 113 with open(path, 'rb') as f:
114 img = pil_image.open(io.BytesIO(f.read()))
115 if color_mode == 'grayscale':

FileNotFoundError: [Errno 2] No such file or directory: '/content/U-2-Net/results/.ipynb_checkpo.png'

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.