ok
Build-Deploy-Actions
Details
Build-Deploy-Actions
Details
This commit is contained in:
commit
17d6e87531
|
@ -0,0 +1,48 @@
|
|||
name: Build
|
||||
run-name: ${{ github.actor }} is upgrade release 🚀
|
||||
on: [push]
|
||||
env:
|
||||
REPOSITORY: ${{ github.repository }}
|
||||
COMMIT_ID: ${{ github.sha }}
|
||||
jobs:
|
||||
Build-Deploy-Actions:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
|
||||
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!"
|
||||
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v3
|
||||
-
|
||||
name: Setup Git LFS
|
||||
run: |
|
||||
git lfs install
|
||||
git lfs fetch
|
||||
git lfs checkout
|
||||
- name: List files in the repository
|
||||
run: |
|
||||
ls ${{ github.workspace }}
|
||||
-
|
||||
name: Docker Image Info
|
||||
id: image-info
|
||||
run: |
|
||||
echo "::set-output name=image_name::$(echo $REPOSITORY | tr '[:upper:]' '[:lower:]')"
|
||||
echo "::set-output name=image_tag::${COMMIT_ID:0:10}"
|
||||
-
|
||||
name: Login to Docker Hub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: artifacts.iflytek.com
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
-
|
||||
name: Build and push
|
||||
run: |
|
||||
docker version
|
||||
docker buildx build -t artifacts.iflytek.com/docker-private/atp/${{ steps.image-info.outputs.image_name }}:${{ steps.image-info.outputs.image_tag }} . --file ${{ github.workspace }}/Dockerfile --load
|
||||
docker push artifacts.iflytek.com/docker-private/atp/${{ steps.image-info.outputs.image_name }}:${{ steps.image-info.outputs.image_tag }}
|
||||
docker rmi artifacts.iflytek.com/docker-private/atp/${{ steps.image-info.outputs.image_name }}:${{ steps.image-info.outputs.image_tag }}
|
||||
- run: echo "🍏 This job's status is ${{ job.status }}."
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
FROM artifacts.iflytek.com/docker-private/atp/base_image_for_ailab:0.0.1
|
||||
|
||||
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
|
||||
RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 -y
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . /app
|
||||
|
||||
|
||||
RUN pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
CMD ["python", "app.py"]
|
|
@ -0,0 +1,93 @@
|
|||
import gradio as gr
|
||||
import numpy as np
|
||||
import torch
|
||||
import matplotlib.pyplot as plt
|
||||
import cv2
|
||||
import sys
|
||||
sys.path.append("..")
|
||||
from segment_anything import sam_model_registry, SamAutomaticMaskGenerator, SamPredictor
|
||||
from PIL import Image
|
||||
import io
|
||||
from gradio.themes.utils import sizes
|
||||
|
||||
|
||||
theme = gr.themes.Default(radius_size=sizes.radius_none).set(
|
||||
block_label_text_color = '#4D63FF',
|
||||
block_title_text_color = '#4D63FF',
|
||||
button_primary_text_color = '#4D63FF',
|
||||
button_primary_background_fill='#FFFFFF',
|
||||
button_primary_border_color='#4D63FF',
|
||||
button_primary_background_fill_hover='#EDEFFF',
|
||||
)
|
||||
|
||||
sam_checkpoint = "sam_vit_b_01ec64.pth"
|
||||
model_type = "vit_b"
|
||||
|
||||
device = "cuda"
|
||||
|
||||
sam = sam_model_registry[model_type](checkpoint=sam_checkpoint)
|
||||
sam.to(device=device)
|
||||
|
||||
mask_generator = SamAutomaticMaskGenerator(sam)
|
||||
|
||||
mask_generator_2 = SamAutomaticMaskGenerator(
|
||||
model=sam,
|
||||
points_per_side=32,
|
||||
pred_iou_thresh=0.86,
|
||||
stability_score_thresh=0.92,
|
||||
crop_n_layers=1,
|
||||
crop_n_points_downscale_factor=2,
|
||||
min_mask_region_area=100, # Requires open-cv to run post-processing
|
||||
)
|
||||
|
||||
|
||||
def fig2img(fig):
|
||||
buf = io.BytesIO()
|
||||
fig.savefig(buf)
|
||||
buf.seek(0)
|
||||
img = Image.open(buf)
|
||||
return img
|
||||
|
||||
def show_anns(anns):
|
||||
if len(anns) == 0:
|
||||
return
|
||||
sorted_anns = sorted(anns, key=(lambda x: x['area']), reverse=True)
|
||||
ax = plt.gca()
|
||||
ax.set_autoscale_on(False)
|
||||
polygons = []
|
||||
color = []
|
||||
for ann in sorted_anns:
|
||||
m = ann['segmentation']
|
||||
img = np.ones((m.shape[0], m.shape[1], 3))
|
||||
color_mask = np.random.random((1, 3)).tolist()[0]
|
||||
for i in range(3):
|
||||
img[:,:,i] = color_mask[i]
|
||||
ax.imshow(np.dstack((img, m*0.35)))
|
||||
|
||||
|
||||
def segment_image(image):
|
||||
image = image.astype('uint8')
|
||||
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
||||
#masks = mask_generator.generate(image)
|
||||
masks2 = mask_generator_2.generate(image)
|
||||
|
||||
plt.figure(figsize=(20,20))
|
||||
plt.imshow(image)
|
||||
#show_anns(masks)
|
||||
show_anns(masks2)
|
||||
plt.axis('off')
|
||||
|
||||
return fig2img(plt.gcf())
|
||||
|
||||
|
||||
demo = gr.Interface(fn=segment_image,
|
||||
inputs=gr.Image(),
|
||||
outputs=gr.Image(),
|
||||
title = "图像分割",
|
||||
theme = theme,
|
||||
examples = ['dog.jpg'])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
demo.queue(concurrency_count=10)
|
||||
demo.launch(server_name = "0.0.0.0")
|
|
@ -0,0 +1,7 @@
|
|||
numpy
|
||||
opencv-python
|
||||
matplotlib
|
||||
Pillow
|
||||
segment_anything
|
||||
torchvision
|
||||
|
Loading…
Reference in New Issue