小编Tob*_*ob 的帖子

如何下载并保存音频文件然后快速播放?

我正在尝试从互联网下载音频文件并将其保存到手机上。这是下载功能:

func download() {
    if let audioUrl = downloadUrl {

        // then lets create your document folder url
        let documentsDirectoryURL =  FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!

        // lets create your destination file url
        let destinationUrl = documentsDirectoryURL.appendingPathComponent(audioUrl.lastPathComponent)
        print(destinationUrl)

        // to check if it exists before downloading it
        if FileManager.default.fileExists(atPath: destinationUrl.path) {
            print("The file already exists at path")

            // if the file doesn't exist
        } else {

            // you can use NSURLSession.sharedSession to download the data asynchronously
            URLSession.shared.downloadTask(with: audioUrl, completionHandler: { (location, …
Run Code Online (Sandbox Code Playgroud)

xcode ios avplayer swift

9
推荐指数
1
解决办法
9615
查看次数

如何使用JSQMessageViewController显示发件人显示名称?

我有以下函数被调用添加消息:

    func addMessage(text: String, displayName: String) {
        let message = JSQMessage(senderId: "tester", displayName: displayName, text: text)
        messages.append(message)

        finishReceivingMessage()

}
Run Code Online (Sandbox Code Playgroud)

然后在这个功能

    override func collectionView(collectionView: JSQMessagesCollectionView!,
    messageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageData! {
        return messages[indexPath.item]
}
Run Code Online (Sandbox Code Playgroud)

我返回该indexPath的消息日期.消息显示正确,但没有显示名称.

ios swift jsqmessagesviewcontroller

7
推荐指数
2
解决办法
3360
查看次数

SCNNodes中的颜色

我试图将SCNNode的颜色设置为自定义RGBA颜色,但是当我尝试该框时将结束白色:

let box = SCNBox(width: 4, height: 1, length: 4, chamferRadius: 0)
    let boxNode = SCNNode(geometry: box)
    myScene.rootNode.addChildNode(boxNode)

    boxNode.castsShadow = true


    box.firstMaterial?.diffuse.contents  = UIColor(red: 30, green: 150, blue: 30, alpha: 1)
Run Code Online (Sandbox Code Playgroud)

这使得盒子变白了但是做这样的事情有效:

box.firstMaterial?.diffuse.contents  = UIColor.greenColor()
Run Code Online (Sandbox Code Playgroud)

如何使盒子具有自定义RGBA颜色?

-谢谢

ios scenekit swift

6
推荐指数
1
解决办法
4393
查看次数

如何处理运行时错误:CUDA错误:PyTorch中遇到非法内存访问?

我正在启用 GPU 的机器上使用 pytorch 1.7 和 cuda 11.0 运行一些代码。我有一些类包含一些不同神经网络的代码。我的第一堂课运行顺利,以下打印语句有效:

A类:

print("Device resnet", torch.cuda.current_device()) # Prints 0
print("Boxes resnet", boxes) # Prints the array of bounding boxes
Run Code Online (Sandbox Code Playgroud)

类 A 创建类 b 的实例,并将框传递给构造函数。但是当我在 b 类中执行类似的 print 语句时,它崩溃了:

print("Device fastrcnn", torch.cuda.current_device()) # Prints 0
print("BOXES in fastrcnn", boxes) # crashes and prints the following error
Run Code Online (Sandbox Code Playgroud)

这会崩溃并打印:

RuntimeError: CUDA error: an illegal memory access was encountered
Run Code Online (Sandbox Code Playgroud)

我该如何调试这个,我已经尝试添加.cpu().cuda()到框以将它们传输到相应的设备,但我遇到了完全相同的崩溃。

python pytorch

5
推荐指数
0
解决办法
1582
查看次数

如何将darknet yolo模型转换为keras?

我正在使用 yad2k 将暗网 YOLO 模型转换为 keras .h5 格式。我的 yolov3-voc.cfg、yolov3.weights 和 yolov3.cfg 都在包含 yad2k 脚本的目录上方。当我运行以下命令时:

python3 yad2k.py -p ../yolov3-voc.cfg ../yolov3.weights model_data/yolov3.h5
Run Code Online (Sandbox Code Playgroud)

或者:

python3 yad2k.py -p ../yolov3.cfg ../yolov3.weights model_data/yolov3.h5
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

    Traceback (most recent call last):
  File "yad2k.py", line 271, in <module>
    _main(parser.parse_args())
  File "yad2k.py", line 90, in _main
    cfg_parser.read_file(unique_config_file)
  File "/Users/tobykrieman/anaconda/lib/python3.6/configparser.py", line 718, in read_file
    self._read(f, source)
  File "/Users/tobykrieman/anaconda/lib/python3.6/configparser.py", line 1080, in _read
    raise MissingSectionHeaderError(fpname, lineno, line)
configparser.MissingSectionHeaderError: File contains no section headers.
file: '<???>', line: 7
'<!DOCTYPE html>\n'
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

python keras darknet yolo

4
推荐指数
1
解决办法
1万
查看次数

如何通过代码选择/突出显示图表的一部分?(图表- PieChartView)

我正在使用这些类来制作图表:https : //github.com/danielgindi/Charts 。我目前有一个饼图显示两个选项,我想知道如何以编程方式突出显示其中一个选项。

charts ios swift

1
推荐指数
1
解决办法
6901
查看次数

您将如何快速绘制饼图视图?

我目前正在做一个需要绘制饼图的项目。我试图使用核心图形来绘制它,而不是使用第三方库。这是绘制饼图的代码。

let circlePath = UIBezierPath(arcCenter: CGPoint(x: self.frame.width/2 + r/8, y: self.frame.height/2 + r/8), radius: r, startAngle: CGFloat(0), endAngle: CGFloat(M_PI * 2 * Double(percent1 / 100)), clockwise: true)
let circlePath2 = UIBezierPath(arcCenter: CGPoint(x: self.frame.width/2 + r/8, y: self.frame.height/2 + r/8), radius: r, startAngle: CGFloat(M_PI * 2 * Double(percent1 / 100)), endAngle: CGFloat(0), clockwise: true)

let shapeLayer = CAShapeLayer()
shapeLayer.path = circlePath.cgPath

let shapeLayer2 = CAShapeLayer()
shapeLayer2.path = circlePath2.cgPath
//change the fill color
shapeLayer.fillColor = UIColor.red.cgColor
shapeLayer2.fillColor = UIColor.blue.cgColor
//you can change …
Run Code Online (Sandbox Code Playgroud)

charts geometry ios swift

1
推荐指数
1
解决办法
878
查看次数

在张量流中对二维数组进行二次采样?

假设我有一个n[[1,2,3], [0.7, 1. 2.6], [9, 2, 1.4], ...]. 我将如何使用tf.gather_nd返回数组的所有第一个和第三个元素。即返回一个长度数组,n如:[[1, 3], [0.7, 2.6], [9, 1.4], ...]

python tensorflow

0
推荐指数
1
解决办法
782
查看次数