Giter VIP home page Giter VIP logo

Comments (6)

yurijmikhalevich avatar yurijmikhalevich commented on June 13, 2024

@sugizo, are you running this in the notebook?

rclip doesn't support notebooks yet; I'll keep this issue open to track progress on adding notebooks support.

from rclip.

yurijmikhalevich avatar yurijmikhalevich commented on June 13, 2024

@sugizo, as a workaround, you may import rclip directly into the notebook, example:

from rclip.main import init_rclip

_, model, rclipDB = init_rclip(DATA_DIR, BATCH_SIZE, DEVICE)  # this will also index `DATA_DIR`
tag_features = model.compute_text_features([f'photo of {tag}' for tag in tags])
for image in tqdm(rclipDB.get_image_vectors_by_dir_path(current_directory), unit='images'):
  image_features = np.frombuffer(image['vector'], np.float32)
  # do whatever you need with `image_features` and `tag_features`; compute similarity, etc

from rclip.

sugizo avatar sugizo commented on June 13, 2024

yes, running in notebook
here's the detail

info

  • env : google colab
  • os : ubuntu jammy x86_64
  • python : 3.10.12

code

import os
from rclip.main import init_rclip
DATASET_DIR = os.getenv('DATASET_DIR', os.path.join(os.path.dirname(__file__), 'datasets', 'objectnet-1.0') )
BATCH_SIZE = int(os.getenv('BATCH_SIZE', 256) )
DEVICE = os.getenv('DEVICE', 'cpu')
_, model, rclipDB = init_rclip(DATA_DIR, BATCH_SIZE, DEVICE)  # this will also index `DATA_DIR`
tag_features = model.compute_text_features([f'photo of {tag}' for tag in tags] )
for image in tqdm(rclipDB.get_image_vectors_by_dir_path(current_directory), unit = 'images'):
    image_features = np.frombuffer(image['vector'], np.float32)

result

NameError                                 Traceback (most recent call last)
[<ipython-input-6-51821106f897>](https://localhost:8080/#) in <cell line: 4>()
      2 from rclip.main import init_rclip
      3 
----> 4 DATASET_DIR = os.getenv('DATASET_DIR', os.path.join(os.path.dirname(__file__), 'datasets', 'objectnet-1.0'))
      5 BATCH_SIZE = int(os.getenv('BATCH_SIZE', 256))
      6 DEVICE = os.getenv('DEVICE', 'cpu')

NameError: name '__file__' is not defined

best regards

from rclip.

yurijmikhalevich avatar yurijmikhalevich commented on June 13, 2024

@sugizo, __file__ is a special variable, which is not defined in Python code running in notebooks. When calling init_rclip like that, you have to construct and pass the path to the directory with the images you want to process as the first argument.

from rclip.

yurijmikhalevich avatar yurijmikhalevich commented on June 13, 2024

@sugizo, version 1.8.6 got published with the fix for the issue you encountered. Can you please confirm that the issue is solved for you, too?

Still, it's better to use rclip in the terminal; some features, like image preview, won't work in notebooks. Alternatively, you can use rclip as a library in notebooks, as I showed before, but this "library" API isn't public and may change between versions.

What are you trying to solve with rclip? If I better understand your use-case, I may have more ideas.

from rclip.

sugizo avatar sugizo commented on June 13, 2024

steps

pip install --extra-index-url https://download.pytorch.org/whl/cpu rclip
!wget -c 'https://i.ytimg.com/vi/vEYsdh6uiS4/maxresdefault.jpg'
import os
from rclip.main import init_rclip
DATASET_DIR = os.getenv('DATASET_DIR', os.path.join(os.path.dirname('./') ) )
BATCH_SIZE = int(os.getenv('BATCH_SIZE', 256) )
DEVICE = os.getenv('DEVICE', 'cpu')
_, model, rclipDB = init_rclip(DATASET_DIR, BATCH_SIZE, DEVICE)  # this will also index `DATASET_DIR`
tag_features = model.compute_text_features([f'photo of {tag}' for tag in tags] )
for image in tqdm(rclipDB.get_image_vectors_by_dir_path(current_directory), unit = 'images'):
    image_features = np.frombuffer(image['vector'], np.float32)

result

checking images in the current directory for changes; use "--no-indexing" to skip this if no images were added, changed, or removed
100%|██████████| 1/1 [00:00<00:00, 94.34images/s] 

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
[<ipython-input-5-1fcf6811c109>](https://localhost:8080/#) in <cell line: 7>()
      5 DEVICE = os.getenv('DEVICE', 'cpu')
      6 _, model, rclipDB = init_rclip(DATASET_DIR, BATCH_SIZE, DEVICE)  # this will also index `DATASET_DIR`
----> 7 tag_features = model.compute_text_features([f'photo of {tag}' for tag in tags] )
      8 for image in tqdm(rclipDB.get_image_vectors_by_dir_path(current_directory), unit = 'images'):
      9     image_features = np.frombuffer(image['vector'], np.float32)

NameError: name 'tags' is not defined

from rclip.

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.