![](/img/trans.png)
[英]How can I copy a file from colab to github repo directly? (It is possible to save the notebook in the Github repo)
[英]I import repo from Github to Colab When I run it there is no response
我将此存储库导入到 Colab。 该项目的目标是检测车辆。
import os
os.chdir("/content/drive/uygulama")
!git clone https://github.com/xuannianz/EfficientDet.git
!python3 /content/drive/uygulama/EfficientDet/inference.py
我看到一个很长的回应。 没有任何错误。 但也没有任何回应。 当我在 Anaconda Prompt 上运行它时。 我可以看视频。
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)
然后,什么也没有发生。 我希望逐帧看到视频。 为什么没有任何回应?
这是 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()
问题在这里
cv2.namedWindow('image', cv2.WINDOW_NORMAL)
cv2.imshow('image', src_image)
cv2.waitKey(0)
它试图打开一个新的 window,然后等待你的键盘。 但是 Colab 是在云中运行的。 它无法访问您的 window 或键盘。 您可以修改代码以保存图像并以另一种方式显示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.