Comments (6)
@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.
@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.
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.
@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.
@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.
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)
- feat: add an option to store rclip DB alongside of the indexed images HOT 3
- FasterViT? HOT 2
- feat: enable outputting images to the terminal
- feat: make `rclip` explain indexing process to the user on the first usage (not everyone reads `README.md`) HOT 1
- ci: automate homebrew tap updates
- fix newlines in the auto-generated changelog
- rclip returns empty results on Windows
- feat: add support for Sixel and kitty graphics protocols for image preview HOT 1
- feat: improve indexing output
- feat: publish windows distributable to `winget`
- feat: make windows installer install mintty to make it easy to use `rclip -p` for the Windows users
- feat: add examples of how to preview the results in the external viewer on Windows (or make it easier)
- feat: option to do indexing without a query HOT 1
- bug: error on redirecting output on unicode file paths HOT 1
- Import error on fresh homebrew install HOT 4
- no results on fresh pip install
- feat: add support of indexing people by name HOT 3
- ERROR: Cannot install rclip using pip HOT 1
- feat: add option to rclip to save the topk images to a directory HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rclip.