Readme: Add more Installation details (#177)
* test functionality * add more steps for installation, so the CUDA_HOME can be set correctlypull/191/head
parent
b520c15790
commit
5bb6543346
48
README.md
48
README.md
|
@ -114,29 +114,67 @@ Marrying <a href="https://github.com/IDEA-Research/GroundingDINO">Grounding DINO
|
|||
|
||||
**Note:**
|
||||
|
||||
If you have a CUDA environment, please make sure the environment variable `CUDA_HOME` is set. It will be compiled under CPU-only mode if no CUDA available.
|
||||
0. If you have a CUDA environment, please make sure the environment variable `CUDA_HOME` is set. It will be compiled under CPU-only mode if no CUDA available.
|
||||
|
||||
Please make sure following the installation steps strictly, otherwise the program may produce:
|
||||
```bash
|
||||
NameError: name '_C' is not defined
|
||||
```
|
||||
|
||||
If this happened, please reinstalled the groundingDINO by reclone the git and do all the installation steps again.
|
||||
|
||||
#### how to check cuda:
|
||||
```bash
|
||||
echo $CUDA_HOME
|
||||
```
|
||||
If it print nothing, then it means you haven't set up the path/
|
||||
|
||||
Run this so the environment variable will be set under current shell.
|
||||
```bash
|
||||
export CUDA_HOME=/path/to/cuda-11.3
|
||||
```
|
||||
|
||||
Notice the version of cuda should be aligned with your CUDA runtime, for there might exists multiple cuda at the same time.
|
||||
|
||||
If you want to set the CUDA_HOME permanently, store it using:
|
||||
|
||||
```bash
|
||||
echo 'export CUDA_HOME=/path/to/cuda' >> ~/.bashrc
|
||||
```
|
||||
after that, source the bashrc file and check CUDA_HOME:
|
||||
```bash
|
||||
source ~/.bashrc
|
||||
echo $CUDA_HOME
|
||||
```
|
||||
|
||||
In this example, /path/to/cuda-11.3 should be replaced with the path where your CUDA toolkit is installed. You can find this by typing **which nvcc** in your terminal:
|
||||
|
||||
For instance,
|
||||
if the output is /usr/local/cuda/bin/nvcc, then:
|
||||
```bash
|
||||
export CUDA_HOME=/usr/local/cuda
|
||||
```
|
||||
**Installation:**
|
||||
|
||||
Clone the GroundingDINO repository from GitHub.
|
||||
1.Clone the GroundingDINO repository from GitHub.
|
||||
|
||||
```bash
|
||||
git clone https://github.com/IDEA-Research/GroundingDINO.git
|
||||
```
|
||||
|
||||
Change the current directory to the GroundingDINO folder.
|
||||
2. Change the current directory to the GroundingDINO folder.
|
||||
|
||||
```bash
|
||||
cd GroundingDINO/
|
||||
```
|
||||
|
||||
Install the required dependencies in the current directory.
|
||||
3. Install the required dependencies in the current directory.
|
||||
|
||||
```bash
|
||||
pip install -e .
|
||||
```
|
||||
|
||||
Download pre-trained model weights.
|
||||
4. Download pre-trained model weights.
|
||||
|
||||
```bash
|
||||
mkdir weights
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"final text_encoder_type: bert-base-uncased\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"application/json": {
|
||||
"ascii": false,
|
||||
"bar_format": null,
|
||||
"colour": null,
|
||||
"elapsed": 0.014210224151611328,
|
||||
"initial": 0,
|
||||
"n": 0,
|
||||
"ncols": null,
|
||||
"nrows": null,
|
||||
"postfix": null,
|
||||
"prefix": "Downloading model.safetensors",
|
||||
"rate": null,
|
||||
"total": 440449768,
|
||||
"unit": "B",
|
||||
"unit_divisor": 1000,
|
||||
"unit_scale": true
|
||||
},
|
||||
"application/vnd.jupyter.widget-view+json": {
|
||||
"model_id": "5922f34578364d36afa13de9f01254bd",
|
||||
"version_major": 2,
|
||||
"version_minor": 0
|
||||
},
|
||||
"text/plain": [
|
||||
"Downloading model.safetensors: 0%| | 0.00/440M [00:00<?, ?B/s]"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/root/miniconda3/lib/python3.8/site-packages/transformers/modeling_utils.py:881: FutureWarning: The `device` argument is deprecated and will be removed in v5 of Transformers.\n",
|
||||
" warnings.warn(\n",
|
||||
"/root/miniconda3/lib/python3.8/site-packages/torch/utils/checkpoint.py:31: UserWarning: None of the inputs have requires_grad=True. Gradients will be None\n",
|
||||
" warnings.warn(\"None of the inputs have requires_grad=True. Gradients will be None\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"True"
|
||||
]
|
||||
},
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from groundingdino.util.inference import load_model, load_image, predict, annotate\n",
|
||||
"import cv2\n",
|
||||
"\n",
|
||||
"model = load_model(\"groundingdino/config/GroundingDINO_SwinT_OGC.py\", \"../04-06-segment-anything/weights/groundingdino_swint_ogc.pth\")\n",
|
||||
"IMAGE_PATH = \".asset/cat_dog.jpeg\"\n",
|
||||
"TEXT_PROMPT = \"chair . person . dog .\"\n",
|
||||
"BOX_TRESHOLD = 0.35\n",
|
||||
"TEXT_TRESHOLD = 0.25\n",
|
||||
"\n",
|
||||
"image_source, image = load_image(IMAGE_PATH)\n",
|
||||
"\n",
|
||||
"boxes, logits, phrases = predict(\n",
|
||||
" model=model,\n",
|
||||
" image=image,\n",
|
||||
" caption=TEXT_PROMPT,\n",
|
||||
" box_threshold=BOX_TRESHOLD,\n",
|
||||
" text_threshold=TEXT_TRESHOLD\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"annotated_frame = annotate(image_source=image_source, boxes=boxes, logits=logits, phrases=phrases)\n",
|
||||
"cv2.imwrite(\"annotated_image.jpg\", annotated_frame)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "base",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.10"
|
||||
},
|
||||
"orig_nbformat": 4
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
Loading…
Reference in New Issue