简体   繁体   English

我从 Github 将 repo 导入到 Colab 当我运行它时没有响应

[英]I import repo from Github to Colab When I run it there is no response

I import this repo to Colab.将此存储库导入到 Colab。 The goal of this project is detect vehicles.该项目的目标是检测车辆。

import os
os.chdir("/content/drive/uygulama")
!git clone https://github.com/xuannianz/EfficientDet.git
!python3 /content/drive/uygulama/EfficientDet/inference.py

I see a long response.我看到一个很长的回应。 There is no any error.没有任何错误。 But also there is no any response.但也没有任何回应。 When I run it on Anaconda Prompt.当我在 Anaconda Prompt 上运行它时。 I can see video.我可以看视频。

2020-04-03 18:16:19.781211: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-04-03 18:16:21.705357: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2020-04-03 18:16:21.718914: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-04-03 18:16:21.719461: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:00:04.0 name: Tesla P100-PCIE-16GB computeCapability: 6.0
coreClock: 1.3285GHz coreCount: 56 deviceMemorySize: 15.90GiB deviceMemoryBandwidth: 681.88GiB/s
2020-04-03 18:16:21.719526: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-04-03 18:16:21.719593: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2020-04-03 18:16:21.719625: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2020-04-03 18:16:21.719657: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2020-04-03 18:16:21.719687: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2020-04-03 18:16:21.720621: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2020-04-03 18:16:21.720704: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2020-04-03 18:16:21.720808: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-04-03 18:16:21.721346: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-04-03 18:16:21.721859: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-04-03 18:16:21.727125: I tensorflow/core/platform/profile_utils/cpu_utils.cc:102] CPU Frequency: 2200000000 Hz
2020-04-03 18:16:21.727305: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x1d65100 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-04-03 18:16:21.727352: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-04-03 18:16:21.816983: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-04-03 18:16:21.817861: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x1d652c0 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2020-04-03 18:16:21.817893: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Tesla P100-PCIE-16GB, Compute Capability 6.0
2020-04-03 18:16:21.818109: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-04-03 18:16:21.818693: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:00:04.0 name: Tesla P100-PCIE-16GB computeCapability: 6.0
coreClock: 1.3285GHz coreCount: 56 deviceMemorySize: 15.90GiB deviceMemoryBandwidth: 681.88GiB/s
2020-04-03 18:16:21.818752: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-04-03 18:16:21.818776: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2020-04-03 18:16:21.818804: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2020-04-03 18:16:21.818827: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2020-04-03 18:16:21.818846: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2020-04-03 18:16:21.818891: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2020-04-03 18:16:21.818909: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2020-04-03 18:16:21.819005: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-04-03 18:16:21.819632: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-04-03 18:16:21.820138: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-04-03 18:16:21.820201: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-04-03 18:16:22.362078: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-04-03 18:16:22.362140: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0 
2020-04-03 18:16:22.362153: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N 
2020-04-03 18:16:22.362389: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-04-03 18:16:22.363088: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-04-03 18:16:22.363704: W tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:39] Overriding allow_growth setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0.
2020-04-03 18:16:22.363748: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 14974 MB memory) -> physical GPU (device: 0, name: Tesla P100-PCIE-16GB, pci bus id: 0000:00:04.0, compute capability: 6.0)

Then, nothing happens.然后,什么也没有发生。 I expect to see a video frame by frame.我希望逐帧看到视频。 Why there is no any response?为什么没有任何回应?

This is inference.py这是 inference.py

import cv2
import json
import numpy as np
import os
import time
import glob

from model import efficientdet
from utils import preprocess_image, postprocess_boxes
from utils.draw_boxes import draw_boxes


def main():
    os.environ['CUDA_VISIBLE_DEVICES'] = '0' #ekran kartı olsaydı 0 -> 1 olacaktı.

    phi = 0 # çözünürlük indisi. phi ne ile eğittiyseniz ona göre ayarlayacaksınız.
    weighted_bifpn = True
    model_path = '/content/drive/uygulama/EfficientDet/efficientdet-d0.h5' #modelin pathi ve kendisi. 
    #çözünürlük olarak 512 yi mi seçtik indisi 0 yaparak: evet.
    image_sizes = (512, 640, 768, 896, 1024, 1280, 1408)
    image_size = image_sizes[phi]
    # coco classes
    classes = {value['id'] - 1: value['name'] for value in json.load(open('/content/drive/uygulama/EfficientDet/coco_90.json', 'r')).values()} # bu datasetler 90 farklı nesneye göre 
    #oluşturulmuş datasetler siz eğer sadece araba, kamyon gibi şeyleri almak istiyorsanız. coco_90.json bu dosyaya gidip aradığınız nesnenin labelına bakacaksınız.
    # örneğin car 3 bisiklet 2 bunu bir if else yapısı ile aşağıda ayrıştıracaksınız.
    num_classes = 90
    score_threshold = 0.3 # modelin verdiği score'un eşiklenmesi. Örneğin bir nesneye 0.2 dediyse onu almayacak.
    #anladım bunun bir formülü var mı deneme yanılma mı? : Modelin başarısına göre siz ayarlayacaksınız. Deneme yanılma biraz.
    colors = [np.random.randint(0, 256, 3).tolist() for _ in range(num_classes)]
    _, model = efficientdet(phi=phi,
                            weighted_bifpn=weighted_bifpn, #false yapıp dene
                            num_classes=num_classes,
                            score_threshold=score_threshold)
    model.load_weights(model_path, by_name=True)

    cap = cv2.VideoCapture('t.mp4')

    while cap.isOpened():
        ret,image = cap.read()
        src_image = image.copy()
        # BGR -> RGB
        image = image[:, :, ::-1]
        h, w = image.shape[:2]

        image, scale = preprocess_image(image, image_size=image_size)
        # run network
        start = time.time()
        boxes, scores, labels = model.predict_on_batch([np.expand_dims(image, axis=0)]) # modelin çalıştığı yer
        boxes, scores, labels = np.squeeze(boxes), np.squeeze(scores), np.squeeze(labels)
        print(time.time() - start)
        boxes = postprocess_boxes(boxes=boxes, scale=scale, height=h, width=w)

        # select indices which have a score above the threshold
        indices = np.where(scores[:] > score_threshold)[0] # eşiklemenin yapıldığı yer.

        # select those detections
        boxes = boxes[indices]
        labels = labels[indices]
        #buradaki labels hangi cisme ait olduğunu gösterir. Bu değer 3 ise o arabadır. Umarım anlatabilmişimdir.
        #şöyle mi olacak? if label == 3 ise alt kısmı gerçkleştir?: Aynen öyle. Tabi bu sizin kodlama becerinize bağlı olarak uğraştırabilir. :)
        # 0.93 yazan confidence değeri.
        # kodlama becerisi derken? basit bir if else yapısı gibi duruyor. o yüzden sordum? : Tabi basit. Ama indisleri iyi seçmek lazım. Gözünüz korkmasın.

        if labels[0]==2 or labels[0]==3:
            draw_boxes(src_image, boxes, scores, labels, colors, classes)

            cv2.namedWindow('image', cv2.WINDOW_NORMAL)
            cv2.imshow('image', src_image)
            cv2.waitKey(0)
    cap.release()
    cv2.destroyAllWindows()  

if __name__ == '__main__':
    main()

The problem is here问题在这里

cv2.namedWindow('image', cv2.WINDOW_NORMAL)
cv2.imshow('image', src_image)
cv2.waitKey(0)

It tries to open a new window, then wait for your keyboard.它试图打开一个新的 window,然后等待你的键盘。 But Colab is run in the cloud.但是 Colab 是在云中运行的。 It cannot access your window or keyboard.它无法访问您的 window 或键盘。 You can modify the code to save the image and display it in another way.您可以修改代码以保存图像并以另一种方式显示。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何直接将文件从 colab 复制到 github 存储库? (可以将笔记本保存在 Github 存储库中) - How can I copy a file from colab to github repo directly? (It is possible to save the notebook in the Github repo) 如何在 Google Colab 中运行 Github 项目的笔记本? - How can I run notebooks of a Github project in Google Colab? 从github repo安装时,模块无法导入为pip中的egg - Module fails to import when installing from github repo as egg in pip 我如何简单地从 github 回购中运行 python 脚本并执行操作 - How do I simply run a python script from github repo with actions 在Github中,我可以从存储库之外的其他仓库运行python脚本吗? - In Github, can I run a python script from a different repo than where it's stored? 将单个文件夹或目录从 GitHub 存储库下载到 Colab - Download a single folder or directory from a GitHub repo to Colab 从 github repo 下载并从 repo 中导入 .py 文件以供使用 - Download from github repo and import .py file from the repo for usage 我如何查看Heroku的github仓库? - How can I check out a github repo from Heroku? 如何从他们的 GitHub 存储库中获取 Helm 的二进制文件? - How can I get Helm's binary from their GitHub repo? 当我运行来自 google colab w3school 的以下 python 代码时,我得到了“AttributeError: 'OutStream' object has no attribute 'buffer'” - I got the "AttributeError: 'OutStream' object has no attribute 'buffer'" when i run the below python code that are from w3school in the google colab
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM