Swift - Parse检查PFFile是否被缓存

时间:2016-11-19 23:28:29

标签: ios swift caching parse-platform pfimageview

考虑到我正在使用PFImageViews,启用了缓存,我想知道是否有办法确定图像是否已经下载。

总而言之,我想说:

if imageAlreadyDownloaded {
    ...
}
else {
    ...
}

有可能吗?

2 个答案:

答案 0 :(得分:1)

所以,我终于找到了解决我自己问题的方法!每个PFFile都有一个名为" isDataAvailable"的布尔属性。

通过一些代码我们可以得到以下解决方案:

let imageFile = file as? PFFile

if imageFile.isDataAvailable {
    ...
}
else {
    ...
}

完成了! ; - )

答案 1 :(得分:0)

我认为你必须使用PFImageView和具有完成处理程序的loadInBackground方法来推出自己的解决方案。

类似的东西:

import tensorflow as tf
import numpy as np
from preprocess import create_feature_sets_and_labels
from tensorflow.python.ops import rnn, rnn_cell

train_x,train_y,test_x,test_y = create_feature_sets_and_labels()

hm_epochs = 10
n_classes = 1
batch_size = 128
chunk_size = 5
n_chunks = 1
rnn_size = 128

x = tf.placeholder('float', [None, n_chunks, chunk_size])
y = tf.placeholder('float')


def recurrent_neural_network(x):

    layer = {'weights':tf.Variable(tf.random_normal([rnn_size, n_classes])),
             'biases':tf.Variable(tf.random_normal([n_classes]))}

    x = tf.transpose(x, [1,0,2])
    x = tf.reshape(x, [-1, chunk_size])
    x = tf.split(0, n_chunks, x)


    lstm_cell = rnn_cell.BasicLSTMCell(rnn_size)
    outputs, states = rnn.rnn(lstm_cell, x, dtype = tf.float32)

    output = tf.add(tf.matmul(outputs[-1], layer['weights']), layer['biases'])
    return output



def train_neural_network(x):
    prediction = recurrent_neural_network(x)
    cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(prediction, y))
    optimizer = tf.train.AdamOptimizer().minimize(cost)

    with tf.Session() as sess:
        sess.run(tf.initialize_all_variables())

        for epoch in range(hm_epochs):
            epoch_loss = 0
            i = 0
            while i < len(train_x):
                start = i
                end = i+batch_size
                batch_x = np.array(train_x[start:end])
                batch_y = np.array(train_y[start:end])
                batch_x = batch_x.reshape((batch_size, n_chunks, chunk_size))


                _, c = sess.run([optimizer, cost], feed_dict={x: batch_x,
                                                              y: batch_y})
                epoch_loss += c
            print('Epoch', epoch, 'completed out of', hm_epochs, 'loss:', epoch_loss)

        correct = tf.equal(tf.argmax(prediction, 1), tf.argmax(y, 1))

        accuracy = tf.reduce_mean(tf.cast(correct, 'float'))

        print('Accuracy:', accuracy.eval({x: test_x, y: test_y}))

train_neural_network(x)
相关问题