Spaces:
Paused
Paused
Experimenting with something....
Browse files28 unmodified lines29303132333443 unmodified lines7879808182838485868788899091929394959697989910010110210310410510610710810911011128 unmodified linesREAD_DISTRO = FalseGATED_IMAGENET = os.environ.get("GATED_IMAGENET")def main(percentage=10):global randomize_subset43 unmodified linesprint("That took %d seconds" % (end - start))def get_label_fractions(dataset):print("Getting label proportions.")if READ_DISTRO:with open("label_distro.json", "r+") as f:label_counts = json.loads(f.read())else:label_counts = Counter([example['label'] for example in dataset])# Don't overrwrite the distribution when devving.if not DEV:with open("label_distro.json", "w+") as f:f.write(json.dumps(label_counts))label_list = list(label_counts.keys())denom = sum(label_counts.values())label_fractions = [label_counts[key]/denom for key in label_counts]return label_list, label_fractionsdef randomize_labels(examples, indices):# What set of examples should be randomized in this batch?# This is the intersection of the batch indices and the indices we randomly selected to change the labels of.batch_subset = list(set(indices) & randomize_subset)# If this batch has indices that we're changing the label of....if batch_subset != []:# Change the label to a random integer between 0 and 9for n in range(len(indices)):index = indices[n]examples["label"][n] = new_random_labels.pop() if index in batch_subset else examples["label"][n]return examplesdemo = gr.Interface(fn=main, inputs="text", outputs="text")demo.launch()28 unmodified lines2930313233343536373839404142434445464748495051525354555657585960616243 unmodified lines10610710810911028 unmodified linesREAD_DISTRO = FalseGATED_IMAGENET = os.environ.get("GATED_IMAGENET")def get_label_fractions(dataset):print("Getting label proportions.")if READ_DISTRO:with open("label_distro.json", "r+") as f:label_counts = json.loads(f.read())else:label_counts = Counter([example['label'] for example in dataset])# Don't overrwrite the distribution when devving.if not DEV:with open("label_distro.json", "w+") as f:f.write(json.dumps(label_counts))label_list = list(label_counts.keys())denom = sum(label_counts.values())label_fractions = [label_counts[key]/denom for key in label_counts]return label_list, label_fractionsdef randomize_labels(examples, indices):# What set of examples should be randomized in this batch?# This is the intersection of the batch indices and the indices we randomly selected to change the labels of.batch_subset = list(set(indices) & randomize_subset)# If this batch has indices that we're changing the label of....if batch_subset != []:# Change the label to a random integer between 0 and 9for n in range(len(indices)):index = indices[n]examples["label"][n] = new_random_labels.pop() if index in batch_subset else examples["label"][n]return examplesdef main(percentage=10):global randomize_subset43 unmodified linesprint("That took %d seconds" % (end - start))demo = gr.Interface(fn=main, inputs="text", outputs="text")demo.launch()
app.py+28-29